// pages/coupon/coupon.js
var app = getApp()
Page({
  data: {
    frameShow: false,//兑换码弹框
    couponList: [],
    status: 1,//优惠券状态// status=0 已过期 2已使用 1未使用
    tabList: [
    {
      id: 1,
      name: '未使用'
    },
    {
      id: 2,
      name: '已使用'
    },
    {
      id: 0,
      name: '已过期'
    }]
  },
  couponCode: function () {
    this.setData({
      frameShow: true
    })
  },
  closeFrame: function () {
    let that = this
    that.setData({
      frameShow: false
    })
  },
  sureSubmit: function () {
    let that = this
    that.setData({
      frameShow: false
    })
  },
  onLoad: function (options) {
    var that = this;
  
   
  that.getCoupon()
  },
  //获取优惠券列表
  getCoupon: function () {
    let that=this
    // status=0 已过期 2已使用 1未使用
    my.showLoading({
      content: '加载中...',
      mask: true
    })
    let data={
      status:that.data.status
    }
    app.request('/coupon', data, 'GET').then(res => {
      //已使用
      console.log(res)
      that.setData({ couponList: res.data.data })
      my.hideLoading()
    })
  },
  //当前选中tab
  currentTab:function(e){
    let that=this
    console.log(e.currentTarget.dataset.id,'tab')
    that.setData({
      status:e.currentTarget.dataset.id
    })
    that.getCoupon()

  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  }
})