<template>
	<view class="notice" :style="tabidx=='dbtz'?'padding-top:188rpx;':'padding-top:100rpx;'">
		<view class="pfixed" style="background: transparent;">
			<tab-list :tablist="tablist" :height="height" :tabidx="tabidx" @getCheck="getCheck"></tab-list>
			<!-- 筛选条件 -->
			<view class="flexc checkbox" v-if="tabidx=='dbtz'" :class="scroflag?'scbg':''">
				<!-- <picker mode="date"    @change='bindDateChangea'>
					<view class="chekt">
						<view>{{tzsj|| "通知时间"}}</view>
						<image :src="upimg"></image>
					</view>
				</picker> -->
				<picker range-key='label' :value="ydidx" :range="ydztlist"  @change='bindDateChangeb'>
					<view class="chekt">
						<view>{{ydzt || "阅读状态"}}</view>
						<image :src="upimg"></image>
					</view>
				</picker>
				<view class="reset" @click="getResetFn">
					<image :src="resetimg" ></image>
					<!-- <image :src="wresetimg" v-else></image> -->
				</view>
			</view>
		</view>
		<view class="mt12">
			<wait-list :type='tabidx' :datalist="list" :wtdt="wtdt"  @getDetail="getDetail"></wait-list>
		</view>
	</view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import {getNoticeList,getRemindList} 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{
				tablist:[{tit:'系统通知',val:'xttz'},{tit:'待办通知',val:'dbtz'}],
				resetimg:require('@/work/static/images/reset.png'),
				wresetimg:require('@/work/static/images/wreset.png'),
				upimg:require('@/work/static/images/sup.png'),
				tabidx:'xttz',
				height:100,
				scroflag:false,
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				tzsj:'',//通知时间
				ydidx:0,
				ydzt:'',
				ydztlist:[],//阅读状态
				isRead:'',
				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();
			this.getDataFn()
		},
		methods:{
			checkPermi, checkRole,
			init(){
				// 阅读状态
				getDictionaryFn('is_read').then(res=>{
					if(res.code==200){
						this.ydztlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
			},
			bindDateChangea(e){
				var val=e.detail.value;
				this.tzsj=val;
				this.getrefreshData()
			},
			bindDateChangeb(e){
				var val=e.detail.value;
				this.ydzt=this.ydztlist[val].label;
				this.isRead=this.ydztlist[val].value;
				this.getrefreshData()
			},
			getResetFn(){
				this.ydzt='';
				this.tzsj='';
				this.ydidx=0;
				this.getrefreshData()
			},
			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,
				}
				// if(this.tzsj){
				// 	params.createTime=this.tzsj
				// }
				
				var tabidx=this.tabidx;
				if(tabidx=='xttz'){
					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)
						}
					}) 
				}else {
					if(this.ydzt){
						params.isRead=this.isRead
					}
					params.userId=this.userId;
					getRemindList(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;}

.checkbox{
	&.scbg{background-color: #FFFFFF;}
	.chekt{display: flex;align-items: center;margin:0 20rpx;height:88rpx;
		view{text-align: center;font-weight: bold;font-size: 26rpx;color: #374B61;flex:1;word-break: break-all;text-overflow: ellipsis;overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;white-space: normal;}
		image{width: 16rpx;height: 12rpx;flex: 0 0 auto;margin-left: 4rpx;}
	}
}
.reset{width:56rpx; height: 88rpx;display: flex;align-items: center;justify-content: center;flex: 1;
	image{width: 26rpx;height: 30rpx;}
}
</style>