yiming
2024-03-25 ecabd20b3dfbd956dad14ffb6ba3dc2efcfdd7c1
pages/cart/paymentPage/index.js
@@ -16,6 +16,8 @@
    productList: [],
    payPrice: '',
    orderGoods: '',
    isPaySuccess: false,
    isPayComplete: false,
  },
  /**
@@ -123,6 +125,7 @@
    })
  },
  confirmOrderGet() {
    var that = this;
    let query = {
      orderNum: this.data.orderGoods
    }
@@ -132,15 +135,50 @@
        const resOrderNum = {
          orderNum: res.orderNumber,
        };
        // 用户未绑定微信 报500
        app.MG.store.makeWeChatPay(resOrderNum).then(payRes => {
          const payVal = JSON.parse(payRes);
          console.log(payVal);
          wx.requestPayment({
            "appId": payVal.appId,
            "timeStamp": payVal.timeStamp,
            "nonceStr": payVal.nonceStr,
            "package": payVal.package,
            "signType": payVal.signType,
            "paySign": payVal.paySign,
            success: function (res) {
              console.log('支付成功');
              if (res.errMsg == 'requestPayment:ok') {
                that.setData({
                  isPaySuccess: true
                })
              }
            },
            fail: function (res) {
              console.log('支付失败');
            },
            // 无论支付成功失败都会调用
            "complete": function (res) {
              if (res.errMsg == 'requestPayment:ok') {
                that.setData({
                  isPayComplete: true
                })
              }
              if (that.data.isPaySuccess && that.data.isPayComplete) {
                that.navToBack()
              }
            }
          });
        })
      }
      // this.makeWeChatQrPayGet()
    })
    // 调取微信二维码支付
  },
  // 页面返回
  navToBack() {
    // 返回
    wx.navigateBack()
  },
})