litian
2024-03-15 3f1ea0a8e4bb02bf7544df8660b15cfa69d6b84a
pages/cart/index.js
@@ -1,6 +1,7 @@
const app = getApp();
// import { getPublicImage } from '@/assets/js/middleGround/tool.js'
import { getPublicImage } from '../../assets/js/middleGround/tool';
import Toast from 'tdesign-miniprogram/toast/index';
Page({
  data: {
@@ -9,7 +10,8 @@
    checkAll: false,
    checkedList: [],
    selectedCount: 0,
    totalPrice: 0.00
    totalPrice: 0.00,
    type: ''
  },
  onLoad(options) {
@@ -39,6 +41,12 @@
    app.MG.store.getShoppingCartProductList(query).then(res => {
      res.datas.forEach(item => {
        item.imgUrl = getPublicImage(item.productMonWithLinkDto.product.icon, '', '160');
        console.log(item);
        console.log(item.saleMethod.type, 'item.saleMethod.type')
        this.setData({
          type: item.saleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'
        })
      });
      this.setData({
@@ -98,22 +106,29 @@
    });
  },
  goPaymentPage() {
    const selectedItems = this.data.shoppingCartData.filter(item => item.checked);
    console.log(selectedItems, 789);
    // console.log(selectedItems, 789);
    const selectedIds = selectedItems.map(item => item.id);
    console.log('选中的商品 id:', selectedIds);
    if (selectedIds.length) {
      app.MG.store.shoppingCartCreateOrder({ linkIds: selectedIds }).then(res => {
        console.log(res, 456);
        const url = '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber
        wx.navigateTo({
          url
        });
      })
    } else {
    app.MG.store.shoppingCartCreateOrder({ linkIds: selectedIds }).then(res => {
      console.log(res.orderNumber, 456);
      const url = '/pages/cart/paymentPage/index?orderNumber=' + res.orderNumber
      wx.navigateTo({
        url
      Toast({
        context: this,
        selector: '#t-toast',
        message: '请选择商品',
        theme: 'warning',
        direction: 'column',
      });
    }
    })
  }