yiming
2024-03-13 c0c9335c4e404beb94890fe2ef402380b8e3b151
pages/personalCenter/myOrder/index.js
@@ -9,26 +9,21 @@
   */
  data: {
    active: 0,
    activeName: "FavoriteBookCity",
    tabList: [
      {
        label: '全部',
        key: 0,
        value: 'all',
      },
      {
        label: '待支付',
        key: 1,
        value: 'WaitPay',
      },
      {
        label: '已完成',
        key: 1,
        value: 'Success',
      },
      {
        label: '已取消',
        key: 1,
        value: 'Cancel',
      }
    ],
@@ -67,7 +62,6 @@
    that.setData({
      skeletonLoding: true,
      active: item.detail.value,
      activeName: info.value,
      queryFilter: info.value == 'all' ? [] : [{ field: 'State', value: info.value }],
      list: [],
      page: 1,
@@ -138,7 +132,7 @@
          }
          this.setData({
            list: dataList,
            pageTotalCount: res.total,
            pageTotalCount: res.totalSize,
            bottomLoading: false,
            isMoreData: dataList.length > 0 ? false : true,
            skeletonLoding: false,
@@ -165,7 +159,7 @@
    this.setData({
      // list: [],
      page: 1,
      limit: 18,
      limit: 12,
      pageTotalCount: 0,
      bottomLoading: false,
      isMoreData: false
@@ -204,6 +198,138 @@
    this.getDataList(bool);
  },
  onCancel(e) {
    let { orderNum } = e.currentTarget.dataset
    console.log(orderNum, 12)
    wx.showModal({
      title: '提示', //提示的标题
      content: '确定要取消订单?', //提示的内容
      success: function (res) {
        if (res.confirm) {
          app.MG.store.cancelOrder({ orderNum: orderNum }).then(() => {
            wx.showToast({
              title: "订单已取消",
              icon: 'success',
              duration: 1000
            })
            this.getDataList(false)
          })
        } else if (res.cancel) {
          console.log('用户点击了取消')
        }
      }
    })
  },
  //立即支付、再次购买
  onPayment(e) {
    var that = this;
    const {
      orderNum
    } = e.currentTarget.dataset
    const data = {
      orderNum: orderNum,
    };
    app.MG.store.getOrderByOrderNum(data).then(res => {
      if (res && res.state != "WaitPay") {
        app.MG.store.confirmOrder(data).then(conRes => {
          if (conRes.orderNumber) {
            const resOrderNum = {
              orderNum: conRes.orderNumber,
            };
            if (conRes.payPrice != 0) {
              app.MG.store.makeWeChatPay(resOrderNum).then(payRes => {
                const payVal = JSON.parse(payRes);
                wx.requestPayment({
                  "appId": payVal.appId,
                  "timeStamp": payVal.timeStamp,
                  "nonceStr": payVal.nonceStr,
                  "package": payVal.package,
                  "signType": payVal.signType,
                  "paySign": payVal.paySign,
                  "success": function (res) {
                    if (res.errMsg == 'requestPayment:ok') {
                      that.setData({
                        isPaySuccess: true
                      })
                    }
                    console.log(res, "成功")
                  },
                  "fail": function (res) {
                    console.log(res, "失败")
                  },
                  "complete": function (res) {
                    if (res.errMsg == 'requestPayment:ok') {
                      that.setData({
                        isPayComplete: true
                      })
                    }
                    if (that.data.isPaySuccess && that.data.isPayComplete) {
                      that.navToBack()
                    }
                  }
                })
              });
            } else {
              wx.showToast({
                title: '领取成功',
              })
              // 可添加返回上级
              setTimeout(() => {
                that.navToBack()
              }, 2000);
            }
          }
        });
      } else {
        app.MG.store
          .makeWeChatPay({
            orderNum: orderNum
          })
          .then(payRes => {
            const payVal = JSON.parse(payRes);
            wx.requestPayment({
              "appId": payVal.appId,
              "timeStamp": payVal.timeStamp,
              "nonceStr": payVal.nonceStr,
              "package": payVal.package,
              "signType": payVal.signType,
              "paySign": payVal.paySign,
              "success": function (res) {
                if (res.errMsg == 'requestPayment:ok') {
                  that.setData({
                    isPaySuccess: true
                  })
                }
              },
              "fail": function (res) {
                console.log(res, "失败")
              },
              "complete": function (res) {
                if (res.errMsg == 'requestPayment:ok') {
                  that.setData({
                    isPayComplete: true
                  })
                }
                if (that.data.isPaySuccess && that.data.isPayComplete) {
                  that.navToBack()
                }
              }
            })
          });
      }
    });
  },
  //删除订单
  onDel(e) {
    const {
      orderNum
    } = e.currentTarget.dataset
  },
  /**
   * 用户点击右上角分享
   */