var app = getApp();
var $ = require('../../../../js/util.js');
Page({
  data: {
    user: [],
    list: [],
    page: 1,//当前页码
    param: {},
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    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.getIndex();
      }
    });
  },
  getIndex: function () {
    var self = this;
    var action = 'c=Extension&a=extension';
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      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 () {
    var self = this;
    if (self.data.user != '') {
      self.data.page++;
      self.setData({
        param: {
          page: self.data.page,
        }
      });
      self.getIndex();
    }
  },
  goToExtensionList: function (event) {
    app.HCredirectTo('../invite_list/invite_list');
  },
  gotoDetial: function (event) {
    app.HCnavigateTo('../cont/cont?id=' + event.currentTarget.dataset.gid);
  },
  goToPoster: function (event) {
    app.HCredirectTo('../member_poster/member_poster');
  },
  goToExtensionpoints: function (event) {
    app.HCnavigateTo('../points_list/points_list');
  },
})