//index.js
//获取应用实例
const app = getApp()
var page = 1;
var flag = 0;
var size = 10;

Page({
  data: {
    list: []
  },
  onLoad: function () {
    page = 1;
    flag = 0;
    this.showData();
  },
  
  onShow:function(){
    var that = this;
    app.ajaxReadyCallback = res => {
      var oldlist = that.data.list;
      var list = res.data.data;
      if (page == 1) {
        oldlist = [];
      }
      var newlist = oldlist.concat(list);
      that.setData({
        list: newlist
      });

      if (list.length < size) {
        flag = 1;
      } else {
        page++;
      }
    }

  },

  onPullDownRefresh() { //下拉刷新
    page = 1;
    flag = 0;
    this.showData();
  },

  onReachBottom() { //上拉加载
    this.showData();
  },

  showData: function () {
    if (flag == 1) {
      return false;
    }
    app.ajax({
      url: app.globalData.serverUrl + '/complain/selectAllByOrgId',
      type: 'POST',
      data: {
        page: page,
        size: size
      }
    });
  },

  detail: function(e){ //跳转到详情
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/complain/detail/index?id=' + id
    })
  }
  
})
