<template>
	<view class="pb50" :style="'padding-top:'+nvaHeight+'px;'">
		<view class="navbox">
			<!-- <uni-nav-bar  color="#ffffff" rightWidth="150rpx" title="政协提案" @clickLeft="getBack" @clickRight="getChFn"  :background-color="backgroundColor" :border="false" statusBar='true' fixed="true">
				<block slot="left">
					<view class="topl">
						<image :src="backimg" ></image>
					</view>
				</block>
				<block slot="right">
					<view class="topr">
						<image :src="ccicoimg"></image>
						<view>提案查重</view>
					</view>
				</block>
			</uni-nav-bar> -->
			<view class="plr12 mt18">
				<view class="search flex0 mb10">
					<image :src="searchimg"></image>
					<input placeholder="输入关键字进行查询" v-model="title" @confirm="getConfirm"/>
				</view>
			</view>
			<view class="tablists flexc mb20">
				<block v-for="(ite,idx) in tabList" :key="idx">
					<view v-if="!ite.limit||ite.limit&&checkPermi([ite.limit])"  @click="getTabFn(ite.val)" :class="{act:tabidx==ite.val}" >{{ite.tit}}</view>
				</block>
				
			</view>
			<view style="height: 56rpx;"></view>
			<view class="lbtab flexc">
				<image :src="lbicoimg" class="limg"></image>
				<view class="lbtabs flexc">
					<view class="lbtabp" v-if="tabidx!='hdtz'&&tabidx!='zxhd'">
						<picker mode="date" :value="time"   @change='bindDateChangeb'>
							<view :class="time?'':'f16 co80'">{{time || "会议日期"}}</view>
						</picker>
						<image :src="upimg" class="upimg"></image>
					</view>
					<view class="lbtabp" v-if="tabidx=='hdtz'||tabidx=='zxhd'">
						<picker mode="date" :value="time"   @change='bindDateChangeb'>
							<view :class="time?'':'f16 co80'">{{time || "活动日期"}}</view>
						</picker>
						<image :src="upimg" class="upimg"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="mbox">
			<meet-list :datalist="list" :wtdt="wtdt" :hdlxlist="hdlxlist" :fylxlist='fylxlist' :qjlxlist="aqjlxlist"  :type='tabidx' @getDetail="getDetail" @getReadFn="getReadFn" @getTuiFn="getTuiFn"></meet-list>
		</view>
		<view v-if="checkPermi(['zxConference:conference:add'])&&tabidx=='hyhd'||checkPermi(['zx:speak:add'])&&tabidx=='wdfy'||checkPermi(['zxActivity:activity:add'])&&tabidx=='hdtz'">
			<view style="height: 100rpx;"></view>
			<view class="fwbtns" @click="getAddMeet" v-if="checkPermi(['zxConference:conference:add'])&&tabidx=='hyhd'">创建会议</view>
			<view class="fwbtns" @click="getAddSpeak" v-if="checkPermi(['zx:speak:add'])&&tabidx=='wdfy'">录入发言</view>
			<view class="fwbtns" @click="getAddActive" v-if="checkPermi(['zxActivity:activity:add'])&&tabidx=='hdtz'">创建活动</view>
			<!--  -->
		</view>
		
		<!-- 弹窗 -->
		<pop-up :type='ptype' :codeQr="codeQr" @getClose="getClose" @getupSubmit="getupSubmit" :qjlxlist="qjlxlist"></pop-up>
	</view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import {getMeetListFn,getSpeakListFn,getupdateReplyFn,getzxActivityListFn,getzxActivityReplyFn} from "@/api/mine/meeting.js"
	import popUp from "@/work/components/popup/popup.vue"
	import meetList from "@/work/components/meeting/list.vue"
	import {getDictionaryFn} from "@/api/mine/register.js"
	export default{
		components:{meetList,popUp},
		data(){
			return{
				searchimg: require("@/work/static/images/search.png"),
				ccicoimg:require("@/work/static/images/ccico.png"),
				lbicoimg:require("@/work/static/images/lbico.png"),
				backimg:require("@/work/static/images/back.png"),
				upimg:require("@/work/static/images/up.png"),
				backgroundColor:"#1D64E2",
				tabidx:'hytz',
				// 会议活动 管理员看的{tit:'会议发言',val:'hyfy',limit:'zx:speak:list'},
				tabList:[{tit:'会议通知',val:'hytz',limit:'zxConference:conference:list'},{tit:'会议活动',val:'hyhd',limit:'zxConference:conference:alllist'},{tit:'我的发言',val:'wdfy',limit:'zx:speak:list'},{tit:'会议发言',val:'hyfy',limit:'zx:speak:alllist'},
					{tit:'政协活动',val:'zxhd',limit:'zxActivity:activity:alllist'},{tit:'活动通知',val:'hdtz',limit:'zxActivity:activity:list'}
				],
				litablist:[{tit:'会议日期',val:0},],
				nvaHeight:44,
				talbList:[{},],
				taztList:[{label:'是',value:'0'},{label:'否',value:'1'}],
				talbidx:'',
				datainfo:{
					talb:'',
				},
				ptype:'',//弹窗类型
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				qjlxlist:[],
				fylxlist:[],
				hdlxlist:[],
				aqjlxlist:[],
				userId:this.$store.state.user.userId,
				id:'',
				title:'',//关键词
				time:"",
				codeQr:""
			}
		},
		onUnload(){
			uni.$off('refreshlist')
		},
		onLoad(e) {
			this.getDataFn()
			this.init()
			uni.$on('refreshlist', (e) => {
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			})
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		mounted() {
			this.getHeightFn()
		},
		methods:{
			checkPermi, checkRole,
			
			init(){
				// 请假类型
				getDictionaryFn('leave').then(res=>{
					if(res.code==200&&res.data.length){
						this.qjlxlist = res.data.map(v => {
							return {
								text: v.dictLabel,
								value: v.dictValue
							}
						})
						this.aqjlxlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
				// 发言类型
				getDictionaryFn('speak_type').then(res=>{
					if(res.code==200&&res.data.length){
						this.fylxlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
				//活动类型
				getDictionaryFn('activity_type').then(res=>{
					if(res.code==200&&res.data.length){
						this.hdlxlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
			},
			bindDateChangeb(e){
				var val=e.detail.value;
				this.time=val;
				this.getConfirm()
			},
			getConfirm(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getHeightFn(){
				var s=uni.getSystemInfoSync().statusBarHeight;
				let query = uni.createSelectorQuery().in(this);
					//需要给黄色区域设置一个id标识,在这里是demo
				query.select('.navbox').boundingClientRect(data => {
					// this.nvaHeight =s? data.height:Number(data.height)-20//赋值,待会要用
					this.nvaHeight =Number(data.height)//赋值,待会要用
				}).exec();
			},
			getClose(){
				this.ptype=""
			},
			getTabFn(idx){
				this.tabidx=idx;
				this.pageNum=1;
				this.list=[],
				this.reachflag=true;
				// this.tabtype=ite.jd||"";
				this.getDataFn()
			},
			getBack(){
				uni.navigateBack({
					delta:1
				})
			},
			bindDateChangea(e){
				console.log(e,2)
			},
			getReadFn(e){
				if(this.tabidx=='hyhd'||this.tabidx=='hdtz'||this.tabidx=='zxhd'){
					this.$tab.navigateTo('/work/pages/meeting/readdetail?id='+e+'&a='+this.tabidx)
				}else if(this.tabidx=='hyfy'){
					this.$tab.navigateTo('/work/pages/meeting/speaklist?id='+e)
				}
				
			},
			getTuiFn(ite){
				if(ite.type=='hyqd'){
					this.$tab.navigateTo('/work/pages/meeting/signin?id='+ite.id)
				}else{
					this.codeQr=ite.item.conferenceQr
					this.ptype=ite.type;
					this.id=ite.id
				}
			},
			getDetail(data){
				var type=this.tabidx;
				if(type=='hyhd'||type=='hytz'){
					this.$tab.navigateTo('/work/pages/meeting/details?id='+data+"&pt="+type)	
				}else if(type=='wdfy'||type=='hyfy'){
					this.$tab.navigateTo('/work/pages/meeting/speakdetails?id='+data)	
				}else if(type=='hdtz'||type=='zxhd'){
					this.$tab.navigateTo('/work/pages/meeting/activedetails?id='+data+"&pt="+type)	
				}	
			},
			getAddMeet(){
				this.$tab.navigateTo('/work/pages/meeting/add')	
			},
			getAddSpeak(){
				this.$tab.navigateTo('/work/pages/meeting/addspeak')	
			},
			getAddActive(){
				this.$tab.navigateTo('/work/pages/meeting/addactive')	
			},
			getupSubmit(e){
				var that=this;
				var type=this.type;
				var params=JSON.parse(JSON.stringify(e))
				params.userId=this.userId;
				if(this.tabidx=='hdtz'){
					params.activityId=this.id;
					getzxActivityReplyFn(params).then(res=>{
						if(res.code==200){
							this.$toast("答复成功");
							setTimeout(function(){
								that.ptype='';
								that.pageNum=1;
								that.list=[];
								that.reachflag=true;
								that.getDataFn()
							},1200)
							
						}
					})
				}else {
					params.conferenceId=this.id;
					getupdateReplyFn(params).then(res=>{
						if(res.code==200){
							this.$toast("答复成功");
							setTimeout(function(){
								that.ptype='';
								that.pageNum=1;
								that.list=[];
								that.reachflag=true;
								that.getDataFn()
							},1200)
							
						}
					})
				}
				
				
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					// visitType:3
				}
				if(this.tabidx=='wdfy'){
					params.userId=this.userId;
					params.conferenceTitle=this.title
					getSpeakListFn(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.tabidx=='hyfy'){
					params.conferenceTitle=this.title
					getSpeakListFn(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.tabidx=='hdtz'||this.tabidx=='zxhd'){
					if(this.time){
						params.activityDate=this.time
					}
					if(this.tabidx=='hdtz'){
						params.userId=this.userId
					}
					params.activityTitle=this.title
					getzxActivityListFn(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.tabidx=='hytz'){
						params.userId=this.userId
					}
					if(this.time){
						params.conferenceDate=this.time
					}
					params.conferenceTitle=this.title
					getMeetListFn(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 scoped lang="scss">
.navbox{position: fixed;left: 0;right: 0;top: 0;z-index: 4;background-color: $com-cd3;
	.topl{width: 60rpx;height: 60rpx;display: flex;align-items: center;justify-content: center;
		image{width: 40rpx;height: 30rpx;}
	}
	.topr{display: flex;align-items: center;
		image{width: 26rpx;height: 26rpx;margin-right: 12rpx;}
		view{font-weight: 500;font-size: 26rpx;color: #FFFFFF;}
	}
	.tablists{
		overflow: auto;flex-wrap: nowrap;
		view{font-weight: bold;font-size: 26rpx;color: #FFFFFF;position: relative;flex: 1 0 auto;padding: 22rpx 24rpx;margin-right: 6rpx;box-sizing: border-box;text-align: center;
			&:last-child{margin-right: 0;}
			&.act{font-size: 30rpx;
				&::after{content: '';width: 62rpx;height: 10rpx;background: #FFFFFF;border-radius: 4rpx;left: 50%;margin-left: -31rpx;bottom: 0rpx;position: absolute;}
			}
		}
	}
	.lbtab{height: 114rpx;background: #FFFFFF;border-radius: 30rpx;padding-left: 24rpx;position: absolute;left:24rpx;right: 24rpx;bottom: -58rpx;
		.limg{width: 40rpx;height: 34rpx;margin-right: 10rpx;flex:0 0 auto;}
		.lbtabs{overflow: auto;flex-wrap: nowrap;
			.lbtabp{display: flex;align-items: center;flex: 0 0 auto;margin-right: 24rpx;}
			.upimg{width: 18rpx;height: 10rpx;}
			
		}
	}
}
.mbox{padding:58rpx 24rpx 28rpx;}
.lbtabs /deep/ picker{padding: 0 18rpx;}
</style>