var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    list: [],
    page: 1,//当前页码
    param: {},
    //公共提示
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {
    var self = this;
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
  },
  onReady: function () {
    var self = this;
    app.getUserInfo(function (ret) {
      //console.log(ret);
        self.getData();
    });
  },
  getData: function (callback) {
    var self = this;
    app.showLoading('加载中...');
    var action = 'c=Member&a=my_collect';
    self.setData({
      param: {
        page: self.data.page,
      }
    })
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (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.getData();
  },
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      param: {},
      hasMore: false,
      dataNull: true
    });
    this.getData();
  },
  del_collect:function(event){
    var id = event.currentTarget.dataset.id;
    var self = this;
   
    app.HCerror('温馨提示', '确定删除此记录？', true, function (ret) {

      if (ret.confirm){
        app.showLoading('加载中...');
        var action = 'c=Member&a=del_collect';
        var param = new Object;
        param.id = id;
        app.ajaxRequest(action, 'GET', $.ObjectToStr(param), function (ret) {
          app.HCerror('提示', ret.msg, false, function () {
            self.getData();
          }); return;
        }, true)
      }
    })
    
  },
  gotoDetial:function(event){
      app.HCnavigateTo('../../takeout/cont/cont?id=' + event.currentTarget.dataset.id + '&name=' + event.currentTarget.dataset.goodsname);
  }
})