var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    info: [],
    list:[],
    sign_day:[],
    is_sign:0,
    is_show: true,
    show_q: false,
    page: 1,//当前页码
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    var self = this;
    // var user_info = app.globalData.userInfo;
    // if ($.isEmptyObject(user_info)){
    //   // app.HCerror('提示', "请先登录", true, function (ret) {
    //   //       app.HCswitchTab('../../index/index'); 
    //   //     });
    // }
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
  },
  onShow: function () {
    var self = this;
    app.getUserInfo(function (ret) {
      self.setData({
        info: ret,
      });
      self.getIndex();
    });

  },
  getIndex: function () {
    var self = this;
    var action = 'c=Member&a=my_sign';
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', '', function (ret) {
      //console.log(ret);
     // self.to_sign();//执行签到
      if (ret.status == 1) {
        self.setData({
          info:ret.data.m_info,
          sign_day:ret.data.sign_info_day,
          is_sign:ret.data.f_qd
        })
        self.get_list();
      }
    }, true);
  },
  to_sign: function () {
    if (app.globalData.is_sign == 1) return;
    var self = this;
    var action = 'c=Member&a=to_sign';
    app.ajaxRequest(action, 'GET', '', function (ret) {
      if (ret.status == 1) {
        app.HCtoast('签到成功！');
        app.globalData.is_sign = 1;
        self.getIndex();
      } else {
        if (!ret.msg) ret.msg = '参数错误';
        app.HCtoast(ret.msg);
        // app.HCerror('提示', ret.msg,false);
      }
    }, true);
  },
  get_list:function(){
    var self = this;
    var action = 'c=Member&a=get_bestgoods_list';
    self.setData({
      param: {
        page: self.data.page,
      }
    })
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      // console.log(ret);
      if (ret.status == 1) {
        $.init_page_list(self, ret.data);
      } else if (ret.status == 2) {
        $.init_page_empty_list(self, ret.msg);
      }
    }, true);
  },
  onReachBottom: function () {
    var self = this;
    self.data.page++;
    self.get_list();
  },
  gotoDetial: function (event) {
    // app.HCnavigateTo('../../takeout/cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
    var pt_id = event.currentTarget.dataset.pt_id;
    var pt_price = event.currentTarget.dataset.pt_price;
    var is_overdue = event.currentTarget.dataset.is_overdue;
    var is_ptdue = event.currentTarget.dataset.is_ptdue;

    if (pt_id > 0 && pt_price > 0 && is_ptdue == 0) {
      app.HCnavigateTo('../../../spellgroup/pages/fightgroup/cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
    } else {
      app.HCnavigateTo('../../takeout/cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
    }

  },
  gotoWin: function (event){
    app.HCnavigateTo('../sign_log/list/list');
  },
  gotoRule:function(event){
    app.HCnavigateTo('../sign_log/rule/rule');
  },
})