coupon.js 2.2 KB
// pages/coupon/coupon.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
   status:1,
   goods_id:'',
   couponlist:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goods_id:options.goods_id,
      type:options.type
    })
    if(options.type==1){
      this.getcoupon()
    }else if(options.type==2){
      this.getordercoupon()
    }
    
  },

  getcoupon(){
    let that=this;
    let url = '/ticket/goods_ticket'
    let param={
      goods_id:that.data.goods_id
    }
    app.postk(url, param).then((res) => {
      console.log(res)
      that.setData({
        couponlist:res.data
      })
      
    
    })
  },
  getordercoupon(){
    let that=this;
    let url = '/ticket/order_ticket'
    let param={
      
    }
    app.postk(url, param).then((res) => {
      console.log(res)
      that.setData({
        couponlist:res.data
      })
      
    
    })
  },

  selcoupon(e){
    console.log(48344834)
    this.status=e.currentTarget.dataset.id;
    this.page=1;
    // this.couponlist=[];
    // this.getmycoupon();
  },
  lingqu(e){
    let id=e.currentTarget.dataset.id;
    let that=this;
    let url = '/ticket/get_ticket1'
    let param={
      user_ticket_id:id
    }
    app.postk(url, param).then((res) => {
      console.log(res)
     wx.showToast({
       title: '领取成功',
       icon:'none'
     })
     setTimeout(function(){
      if(that.data.type==1){
        that.getcoupon()
      }else if(that.data.type==2){
        that.getordercoupon()
      }
        
     },1000)

     
    
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})