const app = getApp()
// pages/list/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardUrl: app.cardUrl,
    cardList: []
  },
  getList: function () {
    var self = this
    wx.showNavigationBarLoading()
    app.http.get(app.urls.getCardList, {
        header: {
          token: app.globalData.token
        }
      }).then(res => {
        self.setData({
          cardList: res.data
        })
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      })
      .catch(err => {
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      })
  },
  goDetail: function (e) {
    var id = e.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url: '../cardDetail/cardDetail?id=' + id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var self = this
    wx.getStorage({
      key: 'token',
      success: function (res) {
        self.setData({
          token: res.data
        })
        app.globalData.token = res.data
        self.getList()
      }
    })
  },



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