const app = getApp();
const util = require("../../../util/util.js")
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    loadModal:false,
    from:0,
    size:6,
    list:[
    ]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function ( ) {
    app.checkLogin( ()=>{
      this.loadData()
    } )
  },
  onReachBottom: function () {
    var that = this
    let newFrom = that.data.from
    if (newFrom == -1) {
      wx.stopPullDownRefresh();
      return;
    }
    this.getTaskList(newFrom, wx.stopPullDownRefresh);
  },
  getTaskList: function( newFrom, cb){
    let param = { from: newFrom, size:this.data.size }
    let list = this.data.list
    let that = this
    
    util.http("/wx/getTradeCenter", param, function (err, res) {
      if( err != 0) return;
      if (newFrom == 0) list = [];
      let newlist = res.list.map( item =>{
        item.finish_at = item.finish_at.substr(0,19).replace("T", " ");
        return item
      });
      that.setData({
        from: res.from || -1,
        list: list.concat(newlist)
      })
      cb && cb()
    });
  },
  loadData :function( ){
    this.getTaskList(0)
  },
})