confirmOrder.js 7.6 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    confirmOrder: '',
    id: '',
    order_no: '',
    type: 0, // 1 = 抵扣; 0 = 不抵扣
    msg: '',
    all_pay: '',
    timeStamp: '',
    nonceStr: '',
    package: '',
    signType: 'MD5',
    paySign: '',
    stay: '',
    shifu: {
      red_name: ''
    },
    list_id: '',
  },

  onLoad: function (options) {
    console.log(options);
    this.setData({
      order_no: options.order_no,
      stay: options.stay || ''
    })
    if (this.data.stay == 1) {
      this.getendmoney()
    } else {
      this.getConfirmOrder()
    }
    console.log(this.data.order_no);
  },


  onReady: function () {

  },


  onShow: function () {

  },
  async getConfirmOrder() { // 获取订单
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/index/baoOrder',
        data: {
          order_no: that.data.order_no,
        }
      })
      that.setData({
        confirmOrder: data,
        confirmOrderBao: data.bao,
        all_pay: data.all_pay
      })
      console.log(data, "促销", that.data.confirmOrder);

    } catch (err) {
      console.log(err);
    }
  },
  async getendmoney() { // 获取尾款订单
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/my/weiOrder',
        data: {
          order_no: that.data.order_no,
        }
      })
      that.setData({
        confirmOrder: data,
        confirmOrderBao: data.bao,
        all_pay: data.shi_pay
      })
      console.log(data, "尾款");

    } catch (err) {
      console.log(err);
    }
  },
  goRedPacketd() {
    let order_no = this.data.order_no
    wx.navigateTo({
      url: '/pages/usePacket/usePacket?order_no=' + order_no
    })
  },
  usejf() { // 使用积分
    let that = this;
    if (that.data.type == 1) {
      that.setData({
        type: 0,
        msg: '您已取消积分抵扣'
      })
      that.popTest()
      that.actualPacket()
    } else {
      that.setData({
        type: 1,
      })
      that.actualPacket()
    }

  },
  async actualPacket() {
    let that = this
    let obj = {}
    obj.list_id = that.data.list_id
    obj.order_no = that.data.order_no
    obj.type = that.data.type
    if (that.data.stay == 1) {
      try {
        const {
          data
        } = await
        request({
          url: 'api/red/shiPay2',
          data: obj
        })
        that.setData({
          shifu: data.data,
          all_pay: data.data.shi
        })
      } catch (err) {
        console.log(err);
      }
    } else {
      try {
        const {
          data
        } = await
        request({
          url: 'api/red/shiPay2',
          data: obj
        })
        console.log(data);
        that.setData({
          shifu: data.data,
          all_pay: data.data.shi
        })
      } catch (err) {
        console.log(err);
      }
    }
  },
  async payConfirmOrder() { // 确认支付
    let that = this;
    if (that.data.all_pay != 0) {
      try {
        const {
          data: {
            data
          }
        } = await
        request({
          url: 'api/index/baoPay2',
          data: {
            order_no: that.data.order_no,
            type: that.data.type,
            list_id: that.data.list_id
          }
        })
        wx.requestPayment({
          timeStamp: data.timeStamp,
          nonceStr: data.nonceStr,
          package: data.package,
          signType: 'MD5',
          paySign: data.paySign,
          success(res) {
            wx.redirectTo({
              url: '/pages/MaintenanceService/MaintenanceService?order_no=' + that.data.order_no,
            })
          },
          fail(res) {
            console.log(res)
          }
        })
      } catch (err) {
        that.setData({
          msg: err.msg
        })
        that.popTest()
      }
    } else {
      wx.showModal({
        title: '提示',
        content: '您的积分可以完全抵扣! 纯积分支付商品不支持退款',
        success: function (res) {
          if (res.confirm) {
            request({
              url: 'api/index/baoPay2',
              data: {
                order_no: that.data.order_no,
                type: that.data.type,
                list_id: that.data.list_id
              }
            }).then(res => {
              console.log(res, "订单支付");
              console.log(res.data.data.type);
              that.setData({
                msg: '支付成功'
              })
              that.popSuccessTest()
              setTimeout(() => {
                wx.redirectTo({
                  url: '/pages/MaintenanceService/MaintenanceService',
                })
              }, 1500);
            }).catch(err => {
              console.log(err);
              this.setData({
                msg: err.msg
              })
              this.popTest()
            })

          } else {
            console.log('点击取消回调')
            that.setData({
              msg: '请重新选择付款方式'
            })
            that.popTest()
          }
        }
      })
    }
  },
  async payendMoney() {
    let that = this;
    if (that.data.all_pay != 0) {
      try {
        const {
          data: {
            data
          }
        } = await
        request({
          url: 'api/my/weiPay2',
          data: {
            order_no: that.data.order_no,
            type: that.data.type,
            list_id: that.data.list_id
          }
        })
        wx.requestPayment({
          timeStamp: data.timeStamp,
          nonceStr: data.nonceStr,
          package: data.package,
          signType: 'MD5',
          paySign: data.paySign,
          success(res) {
            console.log(res);
            wx.redirectTo({
              url: '/pages/MaintenanceService/MaintenanceService?order_no=' + that.data.order_no,
            })
          },
          fail(res) {
            console.log(res)
          }
        })
      } catch (err) {
        that.setData({
          msg: err.msg
        })
        that.popTest()
      }
    } else {
      wx.showModal({
        title: '提示',
        content: '您的积分可以完全抵扣! 纯积分支付商品不支持退款',
        success: function (res) {
          if (res.confirm) {
            request({
              url: 'api/my/weiPay2',
              data: {
                order_no: that.data.order_no,
                type: that.data.type,
                list_id: that.data.list_id
              }
            }).then(res => {
              that.setData({
                msg: '支付成功'
              })
              that.popSuccessTest()
              setTimeout(() => {
                wx.redirectTo({
                  url: '/pages/MaintenanceService/MaintenanceService',
                })
              }, 1500);
            }).catch(err => {
              console.log(err);
              that.setData({
                msg: err.msg
              })
              that.popTest()

            })

          } else {
            console.log('点击取消回调')
            that.setData({
              msg: '请重新选择付款方式'
            })
            that.popTest()
          }
        }
      })
    }
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 1500, //停留时间
    })
  },
  popTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none', //如果要纯文本,不要icon,将值设为'none'
      duration: 1500
    })
  },

})