PickerSelect.js 3.46 KB
// packageCrowdFunding/components/PickerSelect/PickerSelect.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      observer: function(n) {
        let { pickerObj, orderInfo } = this.data
        orderInfo = wx.$util.deepClone(orderInfo)
        if (n) {
          pickerObj?.optionList?.map(i => {
            i.active = false
            if (i[pickerObj?.optionId] == orderInfo[pickerObj?.optionId]) {
              i.active = true
            }
            return i
          })
          this.setData({
            optionList: pickerObj?.optionList || []
          })
        }
      }
    },
    title: String,
    orderInfo: Object,
    pickerObj: Object,
    isAdditionRecordOrder: Boolean,
    popupHeight: {
      type: String,
      value: '60%'
    },
    goodsNumber: {
      type: Number,
      value: 1
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeitem(e) {
      let { target } = e.currentTarget.dataset
      let { optionList, pickerObj } = this.data
      optionList.map(i => {
        i.active = false
        if (i[pickerObj?.optionId] == target[pickerObj?.optionId]) {
          i.active = true
        }
        return i
      })
      this.setData({optionList})
    },
    confirm() {
      let { optionList, orderInfo, pickerObj, title, isAdditionRecordOrder, goodsNumber } = this.data
      let arr = optionList?.filter(v => v.active) || []
      if (!arr.length) {
        return wx.showToast({
          title: `请${title}`,
          icon: 'none'
        })
      }
      let thisPage = wx.$router.getPageInstance()
      let copyOrderInfo = wx.$util.deepClone(orderInfo)
      orderInfo[pickerObj.optionId] = arr[0][pickerObj.optionId] || ''
      orderInfo[pickerObj.optionName] = arr[0][pickerObj.optionName] || ''
      if (pickerObj.flag) { // 商品带出金额
        // 定金金额
        orderInfo['depositPrice'] = `¥${this.priceFilter(arr[0]?.activityPrice * goodsNumber / 100 || 0)}`
        // 尾款金额 = 众筹价 - 定金金额
        orderInfo['tailPayment'] = `¥${this.priceFilter((arr[0]?.crowdFundingPrice - arr[0]?.activityPrice) * goodsNumber / 100 || 0)}`
        orderInfo['crowdFundingPrice'] = `¥${this.priceFilter(arr[0]?.crowdFundingPrice * goodsNumber / 100 || 0)}`
        // 筛选交易流水号 补录用订单总价 关联尾款单(有定金支付时间 用尾款 没有支付时间 用订单总价)
        if (isAdditionRecordOrder) {
          // orderInfo['tailPayment'] = `¥${this.priceFilter(arr[0]?.crowdFundingPrice / 100 || 0)}`
          orderInfo['totalFee'] = arr[0]?.crowdFundingPrice || 0
        } else {
          orderInfo['totalFee'] = (arr[0]?.crowdFundingPrice - arr[0]?.activityPrice) || 0
        }
        // 切换商品 清空选中的交易流水号
        if (copyOrderInfo.goodsId !== arr[0][pickerObj.optionId]) orderInfo['outTradeNo'] = ''
        // 特殊处理 一个id是众筹商品id 一个是嘀加智享车生活平台商品id
        orderInfo.specialGoodsId = arr[0]?.goodsId
      }
      thisPage.setData({
        orderInfo,
        showPickerSelect: false
      })
      this.triggerEvent('confirm', orderInfo)
    },

    priceFilter(num) {
      var pow = Math.pow(10, 2)
      return (Math.round(num * pow) / pow).toFixed(2)
    },
    cancel() {
      let thisPage = wx.$router.getPageInstance()
      thisPage.setData({
        showPickerSelect: false
      })
    }
  }
})