1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- Page({
- data: {
- products: [],
- totalAmount: 0,
- dingweiimg: '',
- youjiantouimg: '',
- },
- onLoad() {
- const selectedItems = wx.getStorageSync('checkoutItems') || [];
- // 标准化 quantity 字段
- const products = selectedItems.map(item => ({
- ...item,
- quantity: item.num
- }));
- console.log(123123);
- this.setData({ products }, () => {
- this.calculateTotal();
- });
- 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();
- },
- onChange(e) {
- const { id } = e.currentTarget.dataset;
- const { detail } = e;
-
- const products = this.data.products.map(item => {
- if (item._id === id) {
- return { ...item, quantity: detail };
- }
- return item;
- });
-
- 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'
- });
- }
- });
|