element.js 2.52 KB
import {
  couponsApi
} from '~/api/api'
import {
  componentsMixin
} from '../../mixins/index'
import {
  IMG_URL
} from '~/utils/constantData.js'
Component({
  behaviors: [componentsMixin],
  properties: {
    coupons: {
      type: Object,
      value: {}
    },
    mode: {
      type: String,
      value: 'coupon' //coupon卡券 center领券中心
    },
    btnStatus: {
      type: Number,
      value: 0
    },
    useMemberType: Number,
    hideBtn: Boolean,
    couponStyle: String
  },
  data: {
    // 2 折扣券,3 代金券,4 兑换券,7 服务券
    IMGURL: wx.$imgUrl,
    IMG_URL
  },
  methods: {
    toRecive() {
      let para = {
        couponIdList: [this.data.coupons.id],
        receiveWay: 1,
      }
      couponsApi.toReciveCard(para).then(res => {
        if (res) {
          wx.navigateTo({
            url: '/packageShopmall/packageMine/pages/coupon/success/success'
          })
        }
      })
    },
    toDetail() {
      let temp = JSON.stringify(this.data.coupons)
      let {
        discountType,
        useChannel,
        id
      } = this.data.coupons
      let detailInfo = {
        xx: 'xx'
      }
      if (discountType == 2 || discountType == 4) {
        wx.$router.go('/packageShopmall/packageMall/pages/coupon/coupon', {
          userCouponId: id,
          useMemberType: this.data.useMemberType,
          detailInfo
        })
        return
      }
      /**线上商品代金券 */
      if (discountType == 3 && useChannel == 1) {
        // if(this.data.useMemberType == 1) {
        //   wx.$api.showToast('代金券已使用')
        //   return
        // }
        wx.$router.go('/packageShopmall/packageMine/pages/coupon/recommend/recommend', {
          couponInfo: this.data.coupons
        })
        return
      }
      wx.navigateTo({
        url: '/packageShopmall/packageMine/pages/coupon/detail/detail?item=' + temp
      })
    },
    //领券中心去领取
    toGet() {
      let merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
      let para = {
        couponId: this.data.coupons.couponId,
        merchantId
      }
      couponsApi.reciveCenterCouponApi(para).then(res => {
        if (res) {
          wx.showToast({
            title: '领取成功',
            icon: 'success'
          })
          setTimeout(() => {
            const thisPage = wx.$router.getPageInstance()
            thisPage.setData({
              couponsList: [],
              pageNum: 1
            })
            thisPage.getCarCenterdData()
          }, 500)

        }
      })
    }
  }
})