Page({ data: { cartItems: [ { id: '1', image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500', title: '幼儿启蒙绘本 10册套装', description: '适合3-6岁儿童,培养创造力', price: 134.00, quantity: 1, checked: true }, { id: '2', image: 'https://img1.baidu.com/it/u=2052658756,3021621759&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=500', title: '幼儿启蒙绘本 10册套装', description: '适合3-6岁儿童,培养创造力', price: 134.00, quantity: 1, checked: true } ], souimg: '', }, onLoad() { this.updateTotalPrice(); const fileIDs = [ 'cloud://cloud1-6g98iw7i28b01747.636c-cloud1-6g98iw7i28b01747-1367995226/images/icon/sou.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({ souimg: tempFilePaths[0], }); }).catch(err => { console.error('有文件下载失败:', err); }); }, handleCheckboxChange(e) { const { value } = e.detail; const cartItems = this.data.cartItems.map(item => ({ ...item, checked: value.includes(item.id) })); this.setData({ cartItems }); this.updateTotalPrice(); }, handleAllCheckboxChange(e) { const { value } = e.detail; const allChecked = value.includes('all'); const cartItems = this.data.cartItems.map(item => ({ ...item, checked: allChecked })); this.setData({ cartItems, allChecked }); this.updateTotalPrice(); }, updateTotalPrice() { const totalPrice = this.data.cartItems.reduce((total, item) => { if (item.checked) { return total + item.price * item.quantity; } return total; }, 0); this.setData({ totalPrice }); }, handleCheckout() { // 处理结算逻辑 console.log('结算'); }, onChange(e) { const { id } = e.currentTarget.dataset; const { detail } = e; const cartItems = this.data.cartItems.map(item => { if (item.id === id) { return { ...item, quantity: detail }; } return item; }); this.setData({ cartItems }, () => { this.updateTotalPrice(); }); } });