var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    list: [],
    category: [],
    current_catid: 0,
    page: 1,//当前页码
    param: {},
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  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();
      }
    });
  },
  getData: function (callback) {
    var self = this;
    app.showLoading('加载中...');
    var action = 'c=Activity&a=promat_sale';
    var body = $.ObjectToStr(self.data.param);
    app.ajaxRequest(action, 'GET', body, function (ret) {
      //console.log(ret);
      if (ret.status == 1) {
        self.setData({
          action_info: ret.data.act_info,
          category: ret.data.category,
          is_show: 1,
        })

        setInterval(function(){
          var Countdowndata = $.Countdown(ret.data.act_info.end_time);
          self.setData({
            Countdowndata: Countdowndata,
          })
        },1000);
        $.init_page_list(self, ret.data.list.goods_info.list);
      } else if (ret.status == 2) {
        $.init_page_empty_list(self, ret.msg);
        self.setData({
          dataNull:false
        })
      } else{
        app.HCerror('提示', ret.msg, false);
      }
    },true)
  },
  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();
  },
  get_cate: function (event) {
    var self = this;
    var catid = event.currentTarget.dataset.id;
    var param = self.data.param;
    param.catid = catid;
    param.page = 1;
    self.setData({
      param: param,
      current_catid: catid
    })
    self.getData();
  },
  //跳转详情
  goToDetaile: function (event) {
    app.HCnavigateTo('../../takeout/cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
  },
})