directional.js 5.18 KB
Page({
  data: {
    IMGURL: 'https://img02.glsx.com.cn/weapp/resource/miniprogram/hmd/',
    IMGURKBASE: 'equity/version/1_0_0/',
    show: false,

    showPage: false,
    // 背景图-映射值 1不送会员 2送会员
    pageBg: {
      1: {
        max: 'wine_c_bg_icon',
        mid: 'wine_bg_icon',
        footer: 'direct_r_bg_icon',
        int: 'direct_bg_icon_2_r',
        modal: 'c_bag_r_icon'
      },
      2: {
        max: 'direction_bg_icon',
        mid: 'direct_vip_icon',
        footer: 'direct_bg_icon_1',
        int: 'direct_bg_icon_2',
        modal: 'c_bag_g_icon'
      }
    },
    giveMemberFlag: 2,
    couponsList: []
  },
  onLoad(options) {
    console.log(options)
    if (options) {
      let para = {
        id: options.id
      }
      if (options.childId) {
        para.childId = options.childId
        this.childId = childId
      }
      if (options.staffUUID) {
        const { staffUUID, staffName } = options
        this.staff = {
          staffUUID,
          staffName
        }
      }
      if (!para.id) return wx.p.wxApi.showToast('缺少参数ID')
      this.getGiftsDetailData(para)
    }
  },
  // 领取定向礼包
 async toRecivedGifts() {
    const { giftsData } = this.data
    const mPattern = /^[1]([3-9])[0-9]{9}$/
    const { merchantId } = wx.p.storage.get('merchant_info')
    const userInfo = wx.p.storage.get('userInfo')
    const receiveWay = giftsData.receiveWay
    if (!this.userPhone&& receiveWay == 1) return wx.p.wxApi.showToast('请输入手机号码')
    if (receiveWay == 1&&!this.userPhone.match(mPattern)) return wx.p.wxApi.showToast('请输入正确的手机号')
    if (!this.userPhone&& receiveWay == 2) return wx.p.wxApi.showToast('请输入您车架号后6位领取')
    if (receiveWay == 2&&this.userPhone.length < 6) return wx.p.wxApi.showToast('请输入您车架号后6位领取')
    let para = {
      directionalGiftId: giftsData.id,
      nickName: userInfo.nickName,
      nickUrl: userInfo.headImgUrl,
      phone: userInfo.phone,
      receiveCondition: this.userPhone || '',
      merchantId: merchantId,
      directionalGiftChildId: this.childId
    }
    if (this.staff) {
      Object.assign(para, this.staff)
    }
    // 先判断登录
    const loginStatus = await wx.p.router.intercept()
    if (loginStatus) return
    wx.p.wxApi.showLoading('领取中')
    wx.p.api.couponsApi.giftsRecive(para).then(res => {
      wx.hideLoading();
      if (res) {
        res.forEach(item => {
          item.receiveStartTime = new Date(item.receiveStartTime).format('yyyy.MM.dd')
          if (item.effectiveType == 1) {
            item.receiveEndTime = new Date(item.receiveEndTime).format('yyyy.MM.dd hh:mm:ss')
          } else {
            item.receiveEndTime = new Date(item.receiveEndTime).format('yyyy.MM.dd')
          }
          // 这是为了适应详情跳转
          item.couponId = item.id
          item.id = item.userCouponId
        })
        this.toShowSuccess(res)
      }
    })
  },
  // 查询定向礼包详情
  getGiftsDetailData(para) {
    wx.p.wxApi.showLoading()
    wx.p.api.couponsApi
      .giftsDetail(para)
      .then(res => {
        wx.hideLoading()
        this.setNaviTitle(res.name)
        this.handlerPageShow(res)
      })
  },
  // 处理页面展示内容
  handlerPageShow(info) {
    if (!info) return wx.p.wxApi.showToast(+JSON.stringify(info))
    const { giveMemberFlag, giveMemberType } = info
    let { pageBg } = this.data

    // 送会员 giveMemberType 1 普通会员;2 银卡会员;3 金卡会员
    if (giveMemberFlag == 2) {
      const IMAGETYPE = {
        1: 'direct_vip_icon',
        2: 'direct_sliver_vip_icon',
        3: 'direct_gold_vip_icon',
      }
      pageBg[2].mid = IMAGETYPE[giveMemberType]
    }
    this.setData({
      showPage: true,
      giveMemberFlag: giveMemberFlag || 1,
      pageBg,
      giftsData: info
    })
  },
  toMineCoupons() {
    wx.p.router.go('/packageMine/pages/coupon/index/index')
  },
  // 去使用
  toUseGifts(e) {
    let {
      item
    } = e.currentTarget.dataset
    let temp = JSON.stringify(item)
    let {
      discountType,
      useChannel,
      id
    } = item
    if (discountType == 2 || discountType == 4) {
      wx.p.router.go('/packageMall/pages/coupon/coupon', {
        userCouponId: id,
        useMemberType: item.useMemberType
      })
      return
    }
    /**线上商品代金券 */
    if (discountType == 3 && useChannel == 1) {
      if (item.useMemberType == 1) {
        wx.p.wxApi.showToast('代金券已使用')
        return
      }
      wx.p.router.go('/packageMine/pages/coupon/recommend/recommend', {
        couponInfo: item
      })
      return
    }
    wx.p.router.go('/packageMine/pages/coupon/detail/detail', {
      item
    })
  },
  setNaviTitle(title) {
    wx.setNavigationBarTitle({
      title
    })
  },
  intPhone(e) {
    this.userPhone = e.detail.value
  },
  toShowSuccess(list) {
    this.setData({
      show: true,
      couponsList: list
    })
    wx.setPageStyle({
      style: {
        overflow: 'hidden'
      }
    })
  },
  // 关闭弹框放开页面滚动
  toCloseModal() {
    this.setData({
      show: false
    })
    wx.setPageStyle({
      style: {
        overflow: 'unset'
      }
    })
  },
})