var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    user:[],
    list: [],//数据
    page: 1,//当前页码
    param: {
      page: 1,//当前页码
    },
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    app.HCsetNavigationBarTitle('订单');
    var self=this;
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
  },
  onReady: function () {
    var self = this;
    app.getUserInfo(function (ret) {
      self.setData({
        user: ret
      });
      if (self.data.user != '') {
        self.setData({
          param: {
            page: self.data.page
          }
        });
        self.getData();
      }
    });
  },
  //加载数据
  getData: function (callback) {
    var self = this;
    app.showLoading('加载中...');
    var action = 'c=LittleShop&a=order_info';
    // console.log(self.data.param);
    app.ajaxRequest(action, 'GET',$.ObjectToStr(self.data.param), function (ret) {
      // console.log(ret); console.log('2----');
      if (ret.status == 1) {
        $.init_page_list(self,ret.data.list);
      } else if (ret.status == 2) {
        $.init_page_empty_list(self, ret.msg);
      }
    }, true);
  },
  onReachBottom: function () {
    // console.log('155555');
    var self = this;
      self.data.page++;
      self.setData({
        param: {
          page: self.data.page,
        }
      });
      self.getData();
  },
  goToInfo: function(event){
    if (this.data.user != '') {
      app.HCnavigateTo('../../../pages/buycart/order_infor/order_infor?id=' + event.currentTarget.dataset.id +'&invite_key=' + app.globalData.init_invite_key+'&is_notshow=1');
    }
  }
});