闫增涛
2024-11-28 dce885689d308043450f199981722b5c80360fe7
pages/cart/paymentPage/index.js
@@ -21,13 +21,19 @@
    selectedIds: '',
    purchasedIds: [],
    productList: [],
    price: '',
    payPrice: '',
    orderGoods: '',
    isPaySuccess: false,
    isPayComplete: false,
    type: '',
    onNorderSaleMethod: '',
    ImmediatelyReceive: ''
    integral: 0,
    defaultVal: false,
    deductioRate: 0,
    currentBalance: 0,
    showIntegral: false
  },
  /**
@@ -47,11 +53,22 @@
      selectedIds: options.selectedIds,
      onNorderSaleMethod: options.onNorderSaleMethod
    })
    console.log(this.data.onNorderSaleMethod, 'options');
    this.getIntegral()
    this.getOrderByOrderNumData()
    this.getDataList()
  },
  getIntegral() {
    app.MG.store
      .getUserWallet({
        type: 'integral'
      })
      .then((res) => {
        this.setData({
          integral: res.balance,
          deductioRate: res.exchangeRate
        });
      })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
@@ -125,7 +142,6 @@
    return intPartFormat + floatPart;
  },
  getOrderByOrderNumData() {
    console.log(this.data.orderNumber, 'this.data.orderNumber');
    let query = {
      orderNum: this.data.orderNumber,
      fields: {
@@ -135,26 +151,43 @@
    }
    app.MG.store.getOrderByOrderNum(query).then(res => {
      this.setData({
        orderGoods: res.orderNumber
      })
      this.setData({
        orderGoods: res.orderNumber,
        price: res.totalPrice.toFixed(2),
        payPrice: res.payPrice.toFixed(2),
        ImmediatelyReceive: res.payPrice
      })
      console.log(this.data.ImmediatelyReceive);
      if (Number(this.data.payPrice) < Number(this.data.price)) {
        this.handleChange()
      }
      console.log(res, "res")
      res.saleMethodLinks.forEach(item => {
        const type = item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product';
        item.type = type; // 将type设置为item对象的属性,而不是使用setData
        item.paymentIcon = getPublicImage(item.orderSaleMethod.product.icon)
        item.payPrice = this.numFormat(item.payPrice)
        console.log(item, 'item');
        item.price = item.orderSaleMethod.price.toFixed(2)
        if (item.orderSaleMethod.product.cmsTypeRefCode == 'jsek_digitalTextbooks') {
          item.typeTxt = '数字教材'
          item.productType = "数字教材"
        } else if (item.orderSaleMethod.product.cmsTypeRefCode == 'jsek_digitalCourses') {
          item.typeTxt = '数字课程'
          item.productType = "数字课程"
        } else {
          item.typeTxt = '电子书'
          item.productType = "图书服务-电子书"
          if (item.orderSaleMethod.type == 'createProductItemSaleMethod') {
            item.typeTxt = '云学习'
            item.productType = "图书服务-云学习"
          }
          if (item.orderSaleMethod.cmsItemList.length && item.orderSaleMethod.cmsItemList[0].type == "questionBankFolder") {
            item.typeTxt = '题库'
            item.productType = "图书服务-云测试"
          }
        }
      })
      this.setData({
        productList: res.saleMethodLinks,
        loading: false,
        hidden: false,
      })
    })
  },
  getDataList() {
@@ -171,13 +204,69 @@
      }
    }
    app.MG.store.getUserOrderList(data).then((res) => {
      res.datas.forEach((item) => {
        this.data.myOrderOrderNumber.push(item.saleMethodLinks[0].orderSaleMethod.id)
        console.log(this.data.myOrderOrderNumber);
      })
    })
  },
  handleChange(e) {
    if (e) {
      this.setData({
        defaultVal: e.detail.value,
      });
    } else {
      this.setData({
        defaultVal: true,
      });
    }
    if (this.data.defaultVal) {
      let useBalance = Math.round(Number(this.data.payPrice) * Number(this.data.deductioRate));
      if (useBalance >= this.data.integral) {
        this.setData({
          currentBalance: this.data.integral,
        });
      } else {
        this.setData({
          currentBalance: useBalance,
        });
      }
      const data = {
        orderNumber: this.data.orderNumber,
        payMethod: "Wallet",
        type: "integral",
        payValue: this.data.currentBalance
      }
      app.MG.store.newOrderPay(data).then(res => {
        if (res) {
          this.setData({
            payId: res.payList[0].id,
            payPrice: res.payPrice.toFixed(2),
            deduct: (this.data.currentBalance / 100).toFixed(2),
            integral: this.data.integral - this.data.currentBalance,
            showIntegral: true
          });
        }
      })
    } else {
      const data = {
        orderNumber: this.data.orderNumber,
        payId: this.data.payId,
      }
      app.MG.store.delOrderPay(data).then(res => {
        if (res) {
          this.setData({
            payPrice: res.payPrice.toFixed(2),
            showIntegral: false
          });
          this.getIntegral()
        }
      })
    }
  },
  confirmOrderGet() {
    if (this.data.myOrderOrderNumber.includes(parseInt(this.data.onNorderSaleMethod))) {
      Toast({
@@ -193,19 +282,15 @@
        orderNum: this.data.orderGoods
      }
      app.MG.store.confirmOrder(query).then(res => {
        console.log(res.orderNumber, 'res');
        if (res.orderNumber) {
          let resOrderNum = {
            orderNum: res.orderNumber,
            platform: "WeChatAppCustom"
          };
          console.log(resOrderNum, 'resOrderNum');
          // 用户未绑定微信 报500
          app.MG.store.makeWeChatPay(resOrderNum).then(payRes => {
            console.log(payRes, 'payRes');
            if (payRes) {
              const payVal = JSON.parse(payRes);
              console.log(payVal);
              wx.requestPayment({
                "appId": payVal.appId,
                "timeStamp": payVal.timeStamp,
@@ -214,7 +299,6 @@
                "signType": payVal.signType,
                "paySign": payVal.paySign,
                success: function (res) {
                  console.log('支付成功');
                  if (res.errMsg == 'requestPayment:ok') {
                    that.setData({
                      isPaySuccess: true
@@ -263,14 +347,16 @@
      orderNum: this.data.orderGoods
    }
    app.MG.store.confirmOrder(query).then(res => {
      Toast({
        context: this,
        selector: '#t-toast',
        message: '领取成功',
        theme: 'success',
        direction: 'column',
      wx.showToast({
        title: '领取成功',
        icon: 'success',
        complete: res => {
          setTimeout(() => {
            wx.navigateBack()
          }, 1000);
        }
      });
      wx.navigateBack()
    })
  }
})