var util = require('../../../utils/jmsUtil.js');
const api = require('../../../api/jms.js');

Page({
  data: {
    list: [],
    page: 1,
    limit: 10,
    totalPages: 1
  },
  onLoad: function (options) {
    this.getList();
  },
  onPullDownRefresh() {
    this.getList();
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  getList: function () {
    wx.showLoading({
      title: '加载中',
    });

    setTimeout(function () {
      wx.hideLoading()
    }, 2000);

    let that = this;
    util.request(api.getApplyList, {}).then(function (res) {
      if (res.errno === 0) {
        console.log(res.data);
        that.setData({
          list: that.data.list.concat(res.data.list),
          totalPages: res.data.pages
        });
      }
      wx.hideLoading();
    });
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  onReachBottom: function () {
    if (this.data.totalPages > this.data.page) {
      this.setData({
        page: this.data.page + 1
      });
      this.getList();
    } else {
      wx.showToast({
        title: '没有更多提现申请了',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
  }
})