123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- Page({
- data: {
- products: [
- {
- id: 1,
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- name: '幼儿启蒙绘本10册套装',
- desc: '适合3-6岁儿童,培养创造力',
- price: 134.00,
- quantity: 1
- },
- {
- id: 1,
- image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500',
- name: '幼儿启蒙绘本10册套装',
- desc: '适合3-6岁儿童,培养创造力',
- price: 134.00,
- quantity: 1
- }
- ],
- totalAmount: 134.00,
- dingweiimg: '',
- youjiantouimg: '',
- },
- onLoad(options) {
- // const title = options.title ? decodeURIComponent(options.title) : '商品列表';
- // this.setData({ title });
- // wx.setNavigationBarTitle({ title });
- const fileIDs = [
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/dingwei.png',
- 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/youjiantou.png',
- ];
-
- // 并发下载多个 fileID
- Promise.all(
- fileIDs.map(fileID => wx.cloud.downloadFile({ fileID }))
- ).then(results => {
- // 每个 result 对应一个下载结果
- const tempFilePaths = results.map(r => r.tempFilePath);
- console.log('全部下载成功:', tempFilePaths);
- this.setData({
- dingweiimg: tempFilePaths[0],
- youjiantouimg: tempFilePaths[1],
- });
- }).catch(err => {
- console.error('有文件下载失败:', err);
- });
- },
- decreaseQuantity(e) {
- const index = e.currentTarget.dataset.index;
- let products = this.data.products;
- if (products[index].quantity > 1) {
- products[index].quantity--;
- this.setData({ products });
- this.calculateTotal();
- }
- },
- increaseQuantity(e) {
- const index = e.currentTarget.dataset.index;
- let products = this.data.products;
- products[index].quantity++;
- this.setData({ products });
- this.calculateTotal();
- },
- calculateTotal() {
- let totalAmount = 0;
- this.data.products.forEach(item => {
- totalAmount += item.price * item.quantity;
- });
- this.setData({ totalAmount });
- },
- handlePay() {
- // 处理支付逻辑
- },
- setGridView() {
- wx.navigateTo({
- url: '/subpackages/addresslist/addresslist'
- });
- }
- });
|