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

Page({
  data: {
    list: [],
    status:0
  },
  onLoad: function (option) {
    let status = option.status;
    if(status){
      this.setData({
        status:status
      })
    }
    wx.setNavigationBarTitle({
      title: option.title
    })
  },

  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++;
      }
    }
    page = 1;
    flag = 0;
    this.showData();
  },

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

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

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

  showData:function(){
    if(flag == 1){
      return false;
    }

    var userId = app.globalData.userinfo.userId; 
    app.ajax({
      url: app.globalData.serverUrl + '/orders/queryUserOrdersByMode',
      type: 'POST',
      data: {
        page: page,
        size: size,
        type:this.data.status
      }
    });
  }
})
