<template>
	<view class="notice" :style="tabidx=='dbtz'?'padding-top:188rpx;':'padding-top:100rpx;'">
		<view class="pfixed" style="background: transparent;">
			<tab-list :tablist="tzlxlist" :height="height" :tabidx="tabidx" @getCheck="getCheck"></tab-list>
		</view>
		<view class="mt12">
			<wait-list type='xxtz' :datalist="list" :wtdt="wtdt"  @getDetail="getDetail"></wait-list>
		</view>
	</view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import {getNoticeList} from "@/api/common.js"
	import {getDictionaryFn} from "@/api/mine/register.js"
	import waitList from "@/components/wait/list.vue"
	import tabList from '@/components/toptab/tab.vue'
	export default{
		components:{tabList,waitList},
		data(){
			return{
				tzlxlist:[],
				tabidx:'',
				height:100,
				scroflag:false,
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				userId:this.$store.state.user.userId,
			}
		},
		onPageScroll(e) {
			var scrollTop = Number(e.scrollTop);
			// var listTop=Number(this.listTop)-Number(this.nvaHeight)
			if(scrollTop>2){
				this.scroflag=true
			}else{
				this.scroflag=false
			}
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		onLoad(e) {
			if(e.type){
				this.tabidx=e.type
			}
			this.init();
		},
		methods:{
			checkPermi, checkRole,
			init(){
				// 通知类型
				getDictionaryFn('sys_notice_type').then(res=>{
					if(res.code==200){
						if(res.data&&res.data.length>0){
							this.tabidx=res.data[0].dictValue;
							this.getDataFn()
							this.tzlxlist = res.data.map(v => {
								return {
									tit: v.dictLabel,
									val: v.dictValue
								}
							})
						}
					}
				})
			},
			getCheck(val){
				this.tabidx=val;
				this.getrefreshData()
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getDetail(e){
				this.$tab.navigateTo("/pages/index/noticedetail?type="+this.tabidx+'&id='+e)
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				params.noticeType=this.tabidx
				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>
.notice /deep/	uni-picker{flex: 1;}

</style>