var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    user: [],
    list: [],
    article_cat_list:[],
    page: 1,//当前页码
    param: {
      page: 1,//当前页码
      catid:0
    },
    catename:'',
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
  },
  onReady: function () {
    //初始化数据
    var self = this;
    self.setData({
      param: {
        page: self.data.page
      }
    });
    self.getIndex();
      
  },
  getIndex: function () {
    var self = this;
    var action = 'c=Article&a=article_list';
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      // console.log($.ObjectToStr(self.data.param));
      if (ret.status == 1) {
        $.init_page_list(self,ret.data.list.list);
        self.setData({
          // list: ret.data.list.list,
          catename:ret.data.catname,
          article_cat_list: ret.data.article_cat_list
        })
        if(ret.data.catname!=''){
          app.HCsetNavigationBarTitle(ret.data.catname);
        }
      } else {
        // self.setData({
        //   dataNull:false,
        // })
        $.init_page_empty_list(self, ret.msg);
      }
    });
  },
  onReachBottom: function () {
    // console.log('155555');
    var self = this;
      self.data.page++;
      self.setData({
        param: {
          page: self.data.page,
        }
      });
      self.getIndex();
  },
  gotoDetial: function (event) {
    app.HCnavigateTo('../cont/cont?id=' + event.currentTarget.dataset.gid);
  },
  gotoList:function(event){
    var self = this;
    self.setData({
      param: {
        page: 1,
        catid: event.currentTarget.dataset.catid
      }
    })
    self.getIndex();
    
  }
})