const util = require('../../../utils/util.js');
const app = getApp();
Page({
  data: {
    nav:[],
    list:[],
    isLoadMore:false,
    pageSize: 20,
    page:1,
    vtype:0
  },
  onLoad: function (options) {
    let that = this;
    util.ajax({
      func:"v2/articleReviewType/list",
      data:{},
      load:false
    },function(res){
      if(res.code == 0){
        let nav = [{ id: 0, title: '全部' }, ...res.data.list];
        that.setData({nav});
        that.getList(true);
      }else{
        util.showTips(res.reason);
      }
    })
  },
  chooseNav(e) {
    this.setData({ vtype: e.currentTarget.dataset.vtype, page:1 });
    this.getList(true);
  },
  getList:function(load){
    let that = this;
    util.ajax({
      func:"v2/articleReview/list",
      data: {"type":that.data.vtype,"pageIndex":that.data.page,"pageSize":that.data.pageSize},
      load: load
    },function(res){
      if(res.code == 0){
        let isLoadMore = true;
        let list = load ? res.data.list : [...that.data.list, ...res.data.list];
        if (res.data.list.length < that.data.pageSize && list.length > that.data.pageSize) {
          isLoadMore = false;
        }
        that.setData({ list, isLoadMore: isLoadMore });
      }else{
        util.showTips(res.reason)
      }
    })
  },
  onPullDownRefresh: function () {
    var self = this;
    wx.showNavigationBarLoading();
    setTimeout(function () {
      self.setData({ page: 1 });
      self.getList(true);
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    }, 1000);
  },
  onReachBottom() {
    var self = this;
    if (self.data.isLoadMore == false) return false;

    setTimeout(function () {
      self.setData({ page: self.data.page + 1 });
      self.getList(false);
    }, 1000);
  },
  onShareAppMessage() {
    return {
      title: '精彩回顾',
      path: '/pages/public/wonderful/index'
    }
  }
})