index.js 4.11 KB

import MineApi from '~/api/mineApi/index'
const discountTypes = ['','满减券','折扣券','代金券','兑换券','购车代金券','商品折扣券','服务券']
Page({
  data: {
    coupons: [
      {
        label: '',
        value: '',
        tip: '',
        sign: '',
        type: ''
      },
      {
        label: '优惠券名称',
        value: '',
        tip: '',
        sign: '',
        type: ''
      },
      {
        label: '类型',
        value: '',
        tip: '',
        sign: '',
        type: ''
      },
      {
        label: '有效期',
        value: '',
        tip: '',
        sign: '',
        type: ''
      },
      {
        label: '',
        value: '',
        tip: '',
        sign: '',
        type: ''
      },
      {
        label: '发放门店',
        value: '',
        tip: '',
        sign: '',
        type: ''
      },
    ],
    customer: [
      {
        label: '客户姓名',
        value: ''
      },
      {
        label: '手机号',
        value: ''
      },
      {
        label: '领取时间',
        value: ''
      },
    ],
    discountType:0,
    pageShow:false
  },

  onRoute(options) {
    if(options.code){
      const userStorage = wx.$storage.get('userInfo')
      let para = {
        verficationCode:options.code,
        merchantId:userStorage.merchantId
      }
      this.query = para
      wx.$api.showLoading()
      MineApi.couponsDetailByScan(para).then(res => {
        wx.hideLoading();
        let {customer,coupons} = this.data
        let {effectiveType,effectiveDays,effectiveStartTime,effectiveEndTime} = res
        // 客户信息
        customer[0].value = res.userName || ''
        customer[1].value = res.phone || ''
        customer[2].value = res.receiveStartTime?new Date(res.receiveStartTime).format('yyyy-MM-dd'):''
        // 优惠券信息
        coupons[1].value = res.couponName || ''
        coupons[2].value = discountTypes[res.discountType] || ''
        coupons[5].value =res.userCouponMerchantName || ''
        // 有效期
        let effectiveStr = ''
        if(effectiveType==1){
          effectiveStr = `${effectiveDays}天`
        }else if(effectiveType==2){
          effectiveStr = `${new Date(effectiveStartTime).format('yyyy/MM/dd')}~${new Date(effectiveEndTime).format('yyyy/MM/dd')}`
        }else{
          effectiveStr = '无有效期'
        }
        coupons[3].value = effectiveStr


        if(res.discountType==7){
          coupons[4].tip =`已核销${res.usedAmount || 0}次`
          let str1 = ''
          if(res.useType==0){
            str1 = '不限次数'
          }else if(res.useType ==1){
            str1 = (res.effectiveType >2?'':'有效期内')+'可用'+`${res.useAllAmount}次`
          }else{
            str1 = '每隔'+`${res.useLimitDays}天`+'|'+`可用${res.useAmount}次`
          }
          coupons[4].value =`已核销${res.usedAmount || 0}次`
          coupons[4].label =`使用限制`
          coupons[1].label =`服务名称`
        }
        // 套餐
        if(res.packageId){
          coupons[0].label = '所属套餐'
          coupons[0].value = res.packageName || ''
          coupons[0].sign = res.receiveWay==6?'集团套餐':''
        }
        // 定向礼包
        if(res.directionalGiftName){
          coupons[0].label = '所属定向礼包'
          coupons[0].value = res.directionalGiftName || ''
          coupons[0].sign = res.merchantType==2?'集团':''
          coupons[0].type = res.directionalGiftReceiveCondition?(res.directionalGiftReceiveWay==1?`手机号:${res.directionalGiftReceiveCondition}`:`车架号后6位:${res.directionalGiftReceiveCondition}`):'直接领取'
        }

        if(res.activityName){
          coupons[0].label = '所属活动'
          coupons[0].value = res.activityName
        }
        this.setData({
          customer,
          coupons,
          discountType:res.discountType,
          pageShow:true
        })
      })
    }
  },
  toComfirm(){
    wx.$api.showLoading('提交中')
    MineApi.comfirmHx(this.query).then(res => {
      wx.hideLoading();
      wx.$router.go('/packageStoreAssistant/packageMine/pages/success/index')
    })
  },
})