var app = getApp();
var $ = require('../../../../js/util.js');
Page({
  data: {
    user: [],
    list: [],
    page: 1,//当前页码
    param: {},
    member_points:0,
    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=points_list';
    
    var param=[];
    param = self.data.param;
    // console.log(param);return;
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'POST', 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);
      }
      if (ret.member_points){
        self.setData({
          member_points: ret.member_points
        })
      }
    }, true);
  },
  onReachBottom: function () {
    var self = this;
    if (self.data.user != '') {
      self.data.page++;
      self.setData({
        param: {
          page: self.data.page,
        }
      });
      self.getIndex();
    }
  },
  gotoDetial: function (event) {
    app.HCnavigateTo('../cont/cont?id=' + event.currentTarget.dataset.gid);
  },
  goToPoster: function (event) {
    app.HCredirectTo('../member_poster/member_poster');

  },
   goToExtension: function (event) {
     app.HCredirectTo('../list/list');
  },
   goToExtensionpoints: function (event) {
    app.HCnavigateTo('../points_list/points_list');
  },
   goToExtensionList: function (event) {
    app.HCredirectTo('../invite_list/invite_list');
  },
  goToWitharawals:function(){
    if (!this.data.user.real_name){
      app.HCtoast('请您先完善个人信息！');
      setTimeout(function () {
        app.HCnavigateTo('../../edit_userinfo/edit?type=1');
      }, 2000);
      return;
    }else{
      app.HCnavigateTo('../../withdrawals/withdrawals');
    }
  }
})