// pages/kabaw/viplist.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mycoupon:'',
    userinfo:'',
    users: '',
    is_vip: '',
    levelname: '',
    user_info_show: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  dis: function () {
    this.setData({
      user_info_show: false
    })
  },
  onLoad: function (t) {
    getApp().page.onLoad(this, t), t.page_id || (t.page_id = -1), this.setData({
      options: t
    })
    if (t.go && t.go == 'nd') {
      this.setData({
        user_info_show: false
      })
    }
    var userinfo = wx.getStorageSync('USER_INFO') ? wx.getStorageSync('USER_INFO') : ''
    this.setData({
      userinfo: userinfo
    })
    this.getlist()
    this.getinfo()
  },
  gokaquan: function () {
    wx.redirectTo({
      url: '/pages/kabaw/kabaw',
    })
  },
  gohuiyuan: function () {
    wx.redirectTo({
      url: '/pages/kabaw/buyvip',
    })
  },
  gocenter: function () {
    var that = this
    var is_vip = this.data.is_vip
    // if(is_vip==1){
    wx.navigateTo({
      url: '/pages/kabaw/kabaw_center',
    })
    // }else{
    //   wx.showModal({
    //     title: '提示',
    //     content: '您还不是会员哦',
    //     confirmText:'成为会员',
    //     success:function(res){
    //       if(res.confirm){
    //         that.bevip()
    //       }
    //     }
    //   })
    // }
  },
  govip: function () {
    wx.navigateTo({
      url: '/pages/kabaw/viplist',
    })
  },
  getinfo: function () {
    var that = this
    console.log(getApp().api.everyday_coupon.user_info)
    getApp().request({
      url: getApp().api.everyday_coupon.user_info,
      data: {
      },
      success: function (t) {
        console.log(t)
        var data = t.data.user
        var lname = t.data.levelname
        var is_vip = t.data.user.is_vip
        var levelname = lname == '' ? '普通用户' : lname

        that.setData({
          users: data,
          is_vip: is_vip,
          levelname: levelname
        })
      }
    })
  },
  getlist: function () {

    var that = this
    console.log(getApp().api.everyday_coupon.user_info)
    getApp().request({
      url: getApp().api.everyday_coupon.vipbuylist,
      data: {
      },
      success: function (t) {
        console.log(t)
        var list = t.data.list
        that.setData({
          mycoupon: list
        })
      }
    })
  },
  godetail:function(e){
    var id = e.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url: '/pages/kabaw/carddetail?id=' + id + '&way=buy',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

    this.getlist()
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})