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

  /**
   * 页面的初始数据
   */
  data: {
    quans: ['1', '2', '1', '2', '1', '2'],
    lquans:'',
    lindex:0,
    mycoupon:'',
    isvvip:0,
    is_vip:0,
    userinfo:'',
    users:'',
    levelname:'',
    send_id:'',
    user_info_show:false
  },
  gousers:function(){
    wx.redirectTo({
      url: '/pages/user/user',
    })
  },
  gouser: function () {
    var id = e.currentTarget.dataset.id
  },
  godetail: function (e) {
    var id = e.currentTarget.dataset.way
    var item = e.currentTarget.dataset.item
    var send_id = this.data.send_id
    // console.log(item)
    // var it = JSON.stringify(item)
    wx.navigateTo({
      url: '/pages/kabaw/detail?id=' + item+'&send_id='+send_id+'&way='+id,
    })
  },
  bevip:function(){
    wx.navigateTo({
      url: '/pages/member/member',
    })
  },
  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
      wx.navigateTo({
        url: '/pages/kabaw/kabaw_center',
      })
  },
  govip:function(){
    wx.navigateTo({
      url: '/pages/kabaw/viplist',
    })
  },
  showmore:function(){
    wx.navigateTo({
      url: '/pages/kabaw/mykabaw',
    })
  },
  thisone:function(e){
    var index = e.currentTarget.dataset.index
    var li = index==0?1:0
    this.getlingcoupon(li)
    this.setData({
      lindex:index
    })
  },

  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.getinfo()
    this.getmycoupon()
  },
  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 ? t.data.user.is_vip:0
        that.getlingcoupon(is_vip)
        var levelname = lname==''?'普通用户':lname

        that.setData({
          users:data,
          is_vip: is_vip,
          levelname: levelname
        })
      }
    })
  },
  getmycoupon: function () {
    var that = this
    console.log(getApp().api.everyday_coupon.user_info)
    getApp().request({
      url: getApp().api.everyday_coupon.mycoupon,
      data: {
        status:0
      },
      success: function (t) {
        console.log(t)
        var list = t.data.list
        that.setData({
          mycoupon:list
        })
      }
    })
  },
  getlingcoupon: function (is_vip) {
    var that = this
    console.log(getApp().api.everyday_coupon.user_info)
    getApp().request({
      url: getApp().api.everyday_coupon.getcoupon,
      data: {
        is_vip: is_vip
      },
      success: function (t) {
        console.log(t)
        var list = t.data.list
        that.setData({
          lquans:list,
          send_id:t.data.send_id
        })
      }
    })
  },

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

  },

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

    var userinfo = wx.getStorageSync('USER_INFO') ? wx.getStorageSync('USER_INFO') : ''
    this.setData({
      userinfo: userinfo,
      lindex: 0,
    })
    this.getinfo()
    this.getmycoupon()
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})