litian
2024-08-27 366de5b4636679392a1e3d2984fc23bd5eaa5ac3
pages/cart/index.js
@@ -1,5 +1,4 @@
const app = getApp();
// import { getPublicImage } from '@/assets/js/middleGround/tool.js'
import {
  loginInfo
} from '../../assets/js/login';
@@ -11,6 +10,7 @@
Page({
  data: {
    price: '',
    loading: true,
    hidden: true,
    swipeOpened: false,
@@ -34,7 +34,6 @@
      title: '购物车'
    });
    this.shoppingCartGet();
    this.setData({
      swipeOpened: true
    })
@@ -56,7 +55,26 @@
    })
  },
  // 金额显示.00格式
  numFormat(value) {
    if (!value) return "0.00";
    value = Number(value).toFixed(2);
    var intPart = Math.trunc(value); // 获取整数部分
    var intPartFormat = intPart
      .toString()
      .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,"); // 将整数部分逢三一断
    var floatPart = ".00"; // 预定义小数部分
    var value2Array = value.split(".");
    // =2表示数据有小数位
    if (value2Array.length === 2) {
      floatPart = value2Array[1].toString(); // 拿到小数部分
      if (floatPart.length === 1) {
        return `${intPartFormat}.${floatPart}0`;
      }
      return `${intPartFormat}.${floatPart}`;
    }
    return intPartFormat + floatPart;
  },
  onDelete(e) {
    const item = e.currentTarget.dataset.item;
    app.MG.store.delShoppingCart({
@@ -83,14 +101,15 @@
      searchList: []
    };
    app.MG.store.getShoppingCartProductList(query).then(res => {
      console.log(res);
      this.setData({
        totalSize: res.totalSize
      })
      res.datas.forEach(item => {
        this.setData({
          bookId: res.id,
          bookName: res.name
          bookName: res.name,
          price: item.saleMethod.price.toFixed(2),
        })
        item.imgUrl = getPublicImage(item.productMonWithLinkDto.product.icon, '', '160');
        // this.setData({
@@ -98,8 +117,8 @@
        // })
        const type = item.saleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product';
        item.type = type; // 将type设置为item对象的属性,而不是使用setData
        item.name = item.linkCmsItems[0].name ? item.productMonWithLinkDto.product.name + ':' + item.linkCmsItems[0].name : item.productMonWithLinkDto.product.name
        item.saleMethod.price = this.numFormat(item.saleMethod.price)
      });
      this.setData({