const app = getApp()
var Api = require("../../../utils/util.js");
Page({
  data: {
    list:[],
    pageNum: 1,
    pageSize: 10,
  },
  onShow: function () {
    var that = this;
    that.setData({
      list: [],
      page: 1,
    })
    that.getNotice()
  },
  getNotice:function(){
    var that = this
    var data = {
      current: this.data.pageNum,
      size: this.data.pageSize,
    }
    wx.showLoading({
      title: '加载中...',
    }) 
    Api.req('sf/platformAnnouncement/list', data, 'get').then(res => {
      wx.stopPullDownRefresh()
      wx.hideLoading()
      if(res.code== 200){
        this.data.loadEnd = res.data.length < this.data.pageSize
        if (this.data.pageNum == 1) {
          this.data.records = res.data
        } else {
          this.data.records = this.data.records.concat(res.data)
        }
        if (!this.data.loadEnd) {
          this.data.pageNum++;
        }
        this.setData({
          list: this.data.records,
          loadEnd: this.data.loadEnd,
        })
        console.log(898,  this.data.loadEnd)
      }else{
        wx.showToast({
          title: res.errMsg,
          icon: 'none'
        })
      }
    })
  },  
  //通告详情
  detail:function(e){
    wx.navigateTo({
      url: '../noticeDetail/noticeDetail?id=' + e.currentTarget.dataset.id
    })
  },
  /** 下拉刷新 **/
  onPullDownRefresh(e) {
    this.setData({
      pageNum: 1,
      pageSize: 10,
      loadEnd: false,
    })
    this.getNotice()     
  },
  /** 页面触底上拉刷新 **/
  onReachBottom(e) {   
    if (!this.data.loadEnd) {       
      this.getNotice()
    } else {
      wx.showToast({
        title: '暂无更多数据',
        icon: 'none',
        duration: 1500
      })
    }
  },
})