orderPromptPop.js 3.85 KB
// components/orderPromptPop/orderPromptPop.js
const FULL_PAY_TYPE_LIST = [
  {
    label: '收款方为门店收款',
    value: '3'
  },
  {
    label: '收款方为嘀加且属于对公转账收款',
    value: '4'
  },
  {
    label: '收款方为嘀加二维码收款',
    value: '5',
    tips: '适用于已有交易收款流水需补录订单时'
  },
  {
    label: '特殊收款',
    value: '6',
    tips: '仅用于无法关联流水或混合支付场景,请谨慎选择。'
  }
]

const DJ_QR_ONLY_PAY_TYPE_LIST = FULL_PAY_TYPE_LIST.filter(item => item.value === '5')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer(n) {
        if (n) {
          this.applyDjQrOnlyPresentation(this.properties.djQrOnlyMode)
        }
      }
    },
    /** 异常流水锁单态:仅允许嘀加二维码收款 */
    djQrOnlyMode: {
      type: Boolean,
      value: false,
      observer(n) {
        if (this.data.show) {
          this.applyDjQrOnlyPresentation(n)
        }
      }
    },
    popupSlotStyle: {
      type: String,
      value: 'height: calc(100% - var(--fontSize120));'
    },
    height: {
      type: String,
      value: 'var(--fontSize500)'
    },
    includesChildHeight: {
      type: String,
      value: 'var(--fontSize1020)'
    },
    sceneObj: {
      type: Object,
      value: {},
      observer: function (v) {
        if (this.properties.djQrOnlyMode) return
        // 是否是扫码核销或再次下单,是的话不显示补录入口
        if (Object.keys(v)?.length) {
          let { payTypeList } = this.data
          let index = payTypeList?.findIndex(v => v.value == 5)
          if (index > -1) {
            payTypeList?.splice(index, 1)
            this.setData({
              payTypeList,
              includesChildHeight: 'var(--fontSize870)'
            })
          }
          this.setData({
            payTypeList
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    infoData: {},
    payTypeList: FULL_PAY_TYPE_LIST.map(item => ({ ...item }))
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 锁单态仅展示嘀加二维码,并预选已支付 + 嘀加二维码
     * @param {boolean} djQrOnlyMode
     */
    applyDjQrOnlyPresentation(djQrOnlyMode) {
      if (djQrOnlyMode) {
        this.setData({
          payTypeList: DJ_QR_ONLY_PAY_TYPE_LIST.map(item => ({ ...item })),
          includesChildHeight: 'var(--fontSize870)',
          infoData: { payFlag: '2', payType: '5' }
        })
        return
      }
      this.setData({
        payTypeList: FULL_PAY_TYPE_LIST.map(item => ({ ...item })),
        includesChildHeight: 'var(--fontSize1020)',
        infoData: {}
      })
    },
    chooseParent(e) {
      if (this.properties.djQrOnlyMode) {
        return wx.$util.showToast('存在异常流水未处理,请选择嘀加二维码收款')
      }
      let { type } = e.currentTarget.dataset
      this.setData({
        'infoData.payFlag': type
      })
    },
    chooseChild(e) {
      let { type } = e.currentTarget.dataset
      if (this.properties.djQrOnlyMode && String(type) !== '5') {
        return wx.$util.showToast('存在异常流水未处理,请选择嘀加二维码收款')
      }
      this.setData({
        'infoData.payType': type
      })
    },
    cancel() {
      this.triggerEvent('cancel')
    },
    confirm() {
      let { infoData } = this.data
      const { djQrOnlyMode } = this.properties
      if (djQrOnlyMode && String(infoData.payType) !== '5') {
        return wx.$util.showToast('存在异常流水未处理,请选择嘀加二维码收款')
      }
      if (!infoData.payFlag || (infoData.payFlag == 2 && !infoData.payType)) {
        return wx.$util.showToast('请选择订单收款方式')
      }
      this.cancel()
      this.triggerEvent('confirm', infoData)
    }
  }
})