<template>
  <view class="box">
	<view class="flex1 overh boxtop">
		<tablist :tablist="tablist" :tabval="tabval" @getCheck="getCheck"></tablist>
	</view>
	<view class="stepbox" >
		<box-list :datainfo="list" type="notice" :wtdt="wtdt" @getDetail="getDetail"></box-list>
	</view>
	<loading></loading>
  </view>
</template>

<script>
import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
import {getDictionaryFn} from "@/api/mine/register.js";
import {getNoticeList} from "@/api/common.js"
import tablist from '@/components/tabs/index.vue'
import boxList from "@/news/components/box/list.vue"
  export default {
	components:{tablist,boxList},
	data(){
		return{
			list:[],
			pageSize: 10,
			pageNum: 1,
			reachflag: true,
			tabval:'',
			tablist:[],
			wtdt:'',
			tzList:[],
		}
	},
	onShow() {
		
	},
    onLoad: function() {
		this.init();
    },
	// 上拉触底加载更多触发事件
	onReachBottom() {
		if (this.reachflag) {
			this.pageNum++
			this.getDataFn()
		}
	},
	methods:{
		checkPermi,checkRole,
		init(){
			//通知类型
			getDictionaryFn('sys_notice_type').then(res => {
				if (res.code == 200) {
					this.tablist = res.data.map(v => {
						this.tabval=res.data[0].dictValue
						return {
							dictLabel: v.dictLabel,
							dictValue: v.dictValue
						}
					})
					this.getDataFn()
				}
			})
		},
		getCheck(val){
			this.tabval=val;
			this.getrefreshData()
		},
		getrefreshData(){
			this.pageNum=1;
			this.list=[];
			this.reachflag=true;
			this.getDataFn()
		},
		getDetail(ite){
			var id=ite.noticeId;
			if(ite.noticeType==3){
				this.$tab.navigateTo(`/news/pages/notice/detail?id=${id}&type=`+ite.noticeType) 
			}else{
				this.$tab.navigateTo(`/news/pages/notice/tzdetail?id=${id}&type=`+ite.noticeType) 
			}
			
		},
		getDataFn(){
			var params={
				pageSize:this.pageSize,
				pageNum: this.pageNum,
			}
			params.noticeType=this.tabval
			getNoticeList(params).then(res=>{
				if(res.code==200){
					if (res.rows.length < this.pageSize) {
						this.reachflag = false
						this.wtdt = '到底了~';
					} else {
						var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
						if (num < res.total) {
							this.reachflag = true
							this.wtdt = ''
						} else {
							this.reachflag = false
							this.wtdt = '到底了~';
						}
					}
					if (this.pageNum == 1) {
						this.list = res.rows;
					} else {
						this.list = this.list.concat(res.rows)
					}
				}else{
					this.$toast(res.msg)
				}
			})
				
		},
		
		
		
	}
  }
</script>
<style lang="scss" scoped>
.boxtop{padding: 18rpx 0 0;background-color: #ffffff;
	position: fixed;left: 0;top: 0;right: 0;z-index: 2;
}
.box{padding-top: 100rpx;}
.stepbox{padding: 18rpx 24rpx 0;}
</style>
