index.js 1.04 KB
import { IMG_URL } from '~/config';
import NP from 'number-precision'
Page({


  data: {
    IMGURL: IMG_URL,
    handleStatus: 0
  },


  onLoad(options) {
    if (options.couponId) {
      this.getEquityCouponsDetail(options.couponId)
    }
  },
  // 查询优惠券详情
  getEquityCouponsDetail(id) {
    wx.p.api.couponsApi.getEquityCouponsDetail({ couponId: id }).then(res => {
      if (res.denomination) {
        res.denomination = NP.divide(res.denomination, 100)
      }
      this.setData({
        detailInfo: res
      })
      this.couponId = id
    })
  },
  // 领取
  async toGet() {
    const {
      detailInfo
    } = this.data
    // const authStatus = await wx.p.router.intercept()
    // if (authStatus) return
    wx.p.wxApi.showLoading()
    wx.p.api.couponsApi.getEquityCoupons({ couponId: this.couponId, merchantId: detailInfo.merchantId }).then(res => {
      wx.hideLoading();
      if (res) {
        wx.p.wxApi.showToast('优惠券领取成功!')
        this.setData({
          handleStatus: 1
        })
      }
    })
  },


})