OrderPopup.js 3.94 KB
// components/OrderPopup/OrderPopup.js
import api from '~/api/api.js'
Component({
  /**
   * 组件的属性列表
   */
  options: {
    styleIsolation: 'shared', // 自定义覆盖vant样式 
  },
  properties: {
    show: Boolean,
    orderType: {
      type: String,
      observer: function (n) {
      }
    },
    resetTransNo: String,
    resetOrder: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
    textareaValue: '',
    routerBack: null,
    outTradeNo: '',
    payVoucherList: []
  },

  /** 组件生命周期 */
  lifetimes: {
    attached: function () {
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    noScroll() { },
    close() {
      let thisPage = wx.$router.getPageInstance()
      let { routerBack } = this.data
      if (routerBack) {
        wx.navigateBack()
        return
      }
      this.setData({
        show: false
      })
      // 点击关闭 情况门店付款数据
      thisPage.setData({
        showPopup: false,
        ['orderInfo.transactionNo']: '',
        ['orderInfo.paymentDocList']: []
      })
    },
    input(e) {
      let { value } = e.detail
      let val = value.replace(/[\u4E00-\u9FA5]/g, '')
      this.setData({
        outTradeNo: val
      })
    },
    // 上传付款凭证
    upLoad(event) {
      let _this = this
      let { payVoucherList } = _this.data
      const { file } = event.detail
      let tempFiles = file?.url
      let imgType = tempFiles.split('.')[1]
      let type = imgType == 'unknown' ? 'jpg' : imgType
      wx.getFileSystemManager().readFile({
        filePath: tempFiles, //选择图片返回的相对路径
        encoding: 'base64', //编码格式
        success(_res) {
          wx.$util.showLoading('上传中...')
          api
            .uploadImg({
              file: `${type}@${_res.data}`
            })
            .then(img => {
              wx.$util.hideLoading()
              console.log(img)
              let { code, data, message } = img
              if (code == 0) {
                payVoucherList.push({ url: data })
                _this.setData({
                  payVoucherList
                })
              } else {
                wx.$util.showToast(message)
              }
            })
        }
      })
    },
    // 删除上传
    deletePayVoucher(e) {
      let { index } = e?.detail
      let _this = this
      let { payVoucherList } = _this.data
      payVoucherList.splice(index, 1)
      this.setData({
        payVoucherList
      })
    },
    changeOrderSource(e) {
      console.log(e)
      let { index } = e.currentTarget.dataset
      let { orderTypeList } = this.data
      orderTypeList.map(i => (i.active = false))
      orderTypeList[index].active = true
      this.setData({
        orderTypeList
      })
    },
    confirm(e) {
      let { outTradeNo, payVoucherList, resetOrder } = this.data
      // debugger
      // console.log(wx.$router)
      let thisPage = wx.$router.getPageInstance()
      if (resetOrder) return this.newResetOrder()
      // if (orderType == 2) {
      if (payVoucherList.length && outTradeNo) {
        thisPage.setData({
          ['orderInfo.transactionNo']: outTradeNo,
          ['orderInfo.paymentDocList']: payVoucherList.map(item => item.url)
        })
        console.log(thisPage.handleSecondConfirm);
        thisPage.handleSecondConfirm()
      } else {
        wx.$util.showToast('交易流水号或付款凭证不能为空!')
      }
      // } 
    },
    // 标记错误订单&补录订单
    newResetOrder() {
      let { resetTransNo, payVoucherList } = this.data
      let thisPage = wx.$router.getPageInstance()
      if (payVoucherList.length && resetTransNo) {
        thisPage.setData({
          ['orderInfo.transactionNo']: resetTransNo,
          ['orderInfo.paymentDocList']: payVoucherList.map(item => item.url)
        })
        thisPage.handleSecondConfirm()
      } else {
        wx.$util.showToast('交易流水号或付款凭证不能为空!')
      }
    }

  }
})