discount.js 1.58 KB
// components/reserve/discount.js
import App from '../../../utils/api'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    cla:String,
    hasPTactivity:Boolean,//平台红包开启状态
    seller:{
      type:Object,
      value:{}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    display:false,
    hiddenAni:'',
    mycards:[],
    money:0,//最大优惠
    red_envelopes_price:0,//获得金额
  },
  lifetimes: {
    // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
    attached: function () {
      App.Customer.SetCardRel({
        sid:this.data.seller.id
      }).then(res=>{
        if(!res.data) return;
        this.setData({
          red_envelopes_price:res.data.red_envelopes_price,
          money:res.data.money,
          mycards:res.data.list,
        })
        if(res.data.red_envelopes_price>0){
          setTimeout(()=>{
            this.setData({
              red_envelopes_price:0,
            })
          },3000)
        }
      })
    },
    moved: function () { },
    detached: function () { },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    hide(){
      this.setData({
        hiddenAni:'discountHide',
      })
      this.triggerEvent('hide')
      setTimeout(()=>{
        this.setData({
          display:false,
          hiddenAni:'',
        })
      },250)
    },
    show(){
      this.setData({
        display:true,
        hiddenAni:'',
      })
      this.triggerEvent('show')
    },
    useCard(){
      this.hide()
      this.triggerEvent('event',{type:'gotoReserve'})
    },
  },
})