const app = getApp();
Page({
  data: {
    newsNavIndex : 1,
    newsList:[],
    pageSize:10,
    pageNum:1,
    total:0
  },
  setNav(e){
    this.setData({
      newsNavIndex : e.currentTarget.dataset.val,
      newsList:[]
    })
    this.getNewList(e.currentTarget.dataset.val,1,10);
  },
  openNews(e){
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    var chainId = e.currentTarget.dataset.chainid;
    this.getReadMsg(id);
    if(status == 0 && this.data.newsNavIndex == '1'){
      setTimeout(()=>{
        wx.navigateTo({
          url: '/pages/query/details?id='+chainId,
        })
      },1000)
    }
  },//32fd8e38bd4
  onLoad(){
    this.getNewList(this.data.newsNavIndex,1,10);
  },
  getNewList(type,pageNum,pageSize){
    var that = this;
    wx.showLoading({
      title: '正在加载...',
      mask: true
    })
    app.requestP({
      url:'/notice/getList',
      method:'post',
      data:{
        type,
        pageNum,
        pageSize,
      }
    }).then(res=>{
      that.setData({
        newsList:res.data.data.rows,
        total:res.data.data.total
      })
    }).catch(error=>{
      app.showToptip(that,'error',error.data.msg);
    })
  },
  onReachBottom: function () {
    var total = this.data.total;
    if(total < this.data.pageSize){return;}
    this.setData({
      pageSize:this.data.pageSize+10,
      pageNum:this.data.pageNum
    },()=>{
      this.getNewList(this.data.newsNavIndex,this.data.pageNum,this.data.pageSize)
    })
  },
  getReadMsg(id){
    var that = this;
    app.requestP({
      url:'/notice/readSystemMsg',
      method:'post',
      data:{
        id,
      }
    }).then(res=>{
      app.showToptip(that,'success','已读');
      this.getNewList(this.data.newsNavIndex,1,10);
    }).catch(err=>{
      app.showToptip(that,'error',err.data.msg)
    })
  }
})