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

  /**
   * 页面的初始数据
   */
  data: {
    quans: ['1', '2', '1', '2', '1', '2'],
    lindex: 0,
    lquans:[
      { name: '洗车券', shop_name: '', use_limit: 1, pic_url: '' },
      { name: '洗车券', shop_name: '', use_limit: 1, pic_url: '' },
      { name: '洗车券', shop_name: '', use_limit: 1, pic_url: '' }
    ] ,
    is_vip: 1,
    userinfo: '',
    users: '',
    levelname: '',
    send_id: '',
    keyword:'',
    list:''
  },
  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,
    })
  },
  getkey:function(e){
    var vl = e.detail.value
    console.log(vl)
    this.setData({
      keyword:vl
    })
    this.getcoupon()
  },
  bevip: function () {
    wx.navigateTo({
      url: '/pages/member/member',
    })
  },
  gocenter: function () {
    var that = this
    var is_vip = this.data.is_vip
    if (is_vip == 1) {
      wx.navigateTo({
        url: '/pages/kabaw/mykabaw',
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '您还不是会员哦',
        confirmText: '成为会员',
        success: function (res) {
          if (res.confirm) {
            that.bevip()
          }
        }
      })
    }
  },
  govip: function () {
    wx.navigateTo({
      url: '/pages/member/member',
    })
  },
  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
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userinfo = wx.getStorageSync('USER_INFO') ? wx.getStorageSync('USER_INFO') : ''
    this.setData({
      userinfo: userinfo
    })
    this.getcoupon()
  },
  getcoupon: function () {
    var that = this
    var keyword = this.data.keyword
    console.log(getApp().api.everyday_coupon.user_info)
    getApp().request({
      url: getApp().api.everyday_coupon.getquans,
      data: {
        keyword:keyword
      },
      success: function (t) {
        console.log(t)
        var quan = t.data.list
        that.setData({
          list:quan,
          send_id:t.data.send_id
        })
      }
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var userinfo = wx.getStorageSync('USER_INFO') ? wx.getStorageSync('USER_INFO') : ''
    this.setData({
      userinfo: userinfo
    })
    this.getcoupon()
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})