var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    list: [],
    page: 1,//当前页码
    param: {},
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true,//未获取到数据提示
    Countdowndata: {}
  },
  onLoad: function (options) {
    var self = this;
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
    if (options.id) {
      this.setData({
        param: {
          id: options.id,
        },
      });
    }
  },
  onReady: function () {
    var self = this;
    app.getUserInfo(function (ret) {
      if (ret) {
        self.getData();
      }
      self.getData();
    });
  },
  getData: function (callback) {
    var self = this;
    app.showLoading('加载中...');
    var action = 'c=Activity&a=activity_list';
    var body = $.ObjectToStr(self.data.param);
    app.ajaxRequest(action, 'GET', body, function (ret) {
      //console.log(ret);
      if (ret.status == 1) {
        self.countDown();
        $.init_page_list(self, ret.data);
      } else if (ret.status == 2) {
        $.init_page_empty_list(self, ret.msg);
      } else {
        app.HCerror('提示', ret.msg, false);
      }
    }, true)
  },
  countDown:function(){
    var list=this.data.list;
    for (var i in list) {
      list[i].Countdowndata = $.Countdown(list[i].end_time);
    }
    this.setData({
      list:list
    })
    setTimeout(this.countDown, 1000);
  },
  onReachBottom: function () {
    var self = this;
    var param = self.data.param;
    param.page = 1;
    param.page++;
    self.setData({
      param: param
    });
    self.getData();
  },
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      param: {},
      hasMore: false,
      dataNull: true
    });
    this.getData();
  },
  //跳转详情
  goToDetaile: function (event) {
    app.HCnavigateTo('../cont/cont?id=' + event.currentTarget.dataset.id);
  },
})