freecard.js 1.75 KB
Page({
  data: {
    freeDay: 0,
    paddingH: 86,
    textpadding: 508,
    showAuthBtn: true
  },
  toPostFreeCard(merchantId, phone, userInfo) {
    let para = {
      merchantId,
      phone
    }
    wx.p.api.couponsApi.tolqFreecard(para).then(res => {
      wx.hideLoading()
      const { errId, code, message } = res
      if ((code == -1 && errId == 20313) || (code == -1 && errId == 20322)) {
        wx.showModal({
          title: '提示',
          content: res.message,
          confirmText: '确定',
          showCancel: false,
          confirmColor: '#F13C3D'
        })
        return
      }
      let bindInfo = {
        code,
        errId,
        message,
        data: {
          sessionId: userInfo.sessionId
        }
      }
      let temp = encodeURIComponent(JSON.stringify(bindInfo))
      wx.p.storage.set('bindInfo', temp)
      wx.p.router.reLaunch('/pages/tab/equity/index');
    })
  },
  toGetFreeCardDay(merchantId) {
    wx.p.api.couponsApi
      .getFreeCardDay({
        merchantId
      })
      .then(res => {
        if (res) {
          this.setData({
            freeDay: res.freeDay || 0
          })
        }
      })
  },
  async tofreeReceive() {
    // 先判断登录
    const loginStatus = !wx.p.isLogin
    if (loginStatus) return
   
    const userInfo = wx.p.storage.get('userInfo')
     let { merchantId, phone } = userInfo
    wx.p.wxApi.showLoading()
    this.toPostFreeCard(merchantId, phone, userInfo)
  },

  onLoad(options) {
    let system = wx.getSystemInfoSync()
    const { merchantId } = wx.p.storage.get('merchant_info')
    this.toGetFreeCardDay(merchantId)
    this.setData({
      paddingH: system.windowHeight * 0.11,
      textpadding: system.windowHeight * 0.31
    })
  },
  onUnload: function () {
  }
})