<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">
					<block v-if="tabidx!='hdtz'&&tabidx!='zxhd'">
						<view class="lbtabp">
							<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=='hytz'||tabidx=='hyhd'">
							<picker  range-key='label'  :range="hylxlist"  @change='bindDateChangec'>
								<view :class="hylxtxt?'':'f16 co80'">{{hylxtxt || "会议类型"}}</view>
							</picker>
							<image :src="upimg" class="upimg"></image>
						</view>
					</block>
					<block v-if="tabidx=='hdtz'||tabidx=='zxhd'">
						<view class="lbtabp" >
							<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" >
							<picker  range-key='label' :range="hdlxlist"  @change='bindDateChanged'>
								<view :class="hdlxtxt?'':'f16 co80'">{{hdlxtxt || "活动类型"}}</view>
							</picker>
							<image :src="upimg" class="upimg"></image>
						</view>
					</block>
					
				</view>
				<view class="czbtns" @click='getResetFn'>重置</view>
			</view>
		</view>
		<!-- 列表 -->
		<view class="mbox">
			<meet-list :datalist="list" :wtdt="wtdt" :xsztlist="xsztlist" :hdlxlist="hdlxlist" :fylxlist='fylxlist' :qjlxlist="aqjlxlist"  :type='tabidx' @getDetail="getDetail" @getReadFn="getReadFn" @getTuiFn="getTuiFn"></meet-list>
		</view>
		<view v-if="checkPermi(['zxConference:conference:add'])||checkPermi(['zx:speak:add'])||checkPermi(['zxActivity:activity:add'])">
			<view style="height: 100rpx;"></view>
			<view class="fwbtns" @click="getAddMeet" v-if="checkPermi(['zxConference:conference:add'])&&(tabidx=='hyhd'||tabidx=='hytz')">创建会议</view>
			<view class="fwbtns" @click="getAddSpeak" v-if="checkPermi(['zx:speak:add'])&&(tabidx=='wdfy'||tabidx=='hyfy')">录入发言</view>
			<view class="fwbtns" @click="getAddActive" v-if="checkPermi(['zxActivity:activity:add'])&&(tabidx=='zxhd'||tabidx=='hdtz')">创建活动</view>
			<view class="fwbtns" @click="getAddzsyz" v-if="checkPermi(['zx:investment:add'])&&(tabidx=='zsyz'||tabidx=='wdzs')">上报线索</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,getinvestmentListFn,getinvestmentshlFn} 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:'hdtz',limit:'zxActivity:activity:list'},{tit:'政协活动',val:'zxhd',limit:'zxActivity:activity:alllist'},{tit:'我的招商',val:'wdzs',limit:'zx:investment:list'},{tit:'招商引资',val:'zsyz',limit:'zx:investment:alllist'},
				],
				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:[],
				hylxlist:[],
				xsztlist:[],
				hdlxtxt:'',
				hdlxid:'',
				hylxtxt:'',
				hylxid:'',
				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
							}
						})
					}
				})
				// 会议类型
				getDictionaryFn('conference_type').then(res=>{
					if(res.code==200&&res.data.length){
						this.hylxlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
				// 线索状态
				getDictionaryFn('investment_type').then(res=>{
					if(res.code==200&&res.data.length){
						this.xsztlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
			},
			bindDateChangeb(e){
				var val=e.detail.value;
				this.time=val;
				this.getConfirm()
			},
			bindDateChangec(e){
				var val=e.detail.value;
				this.hylxtxt=this.hylxlist[val].label;
				this.hylxid=this.hylxlist[val].value;
				this.getConfirm()
			},
			bindDateChanged(e){
				var val=e.detail.value;
				this.hdlxtxt=this.hdlxlist[val].label;
				this.hdlxid=this.hdlxlist[val].value;
				this.getConfirm()
			},
			getConfirm(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getResetFn(){
				var tabidx=this.tabidx;
				if(tabidx!='hdtz'&&tabidx!='zxhd'){
					this.time=''
					if(tabidx=='hytz'||tabidx=='hyhd'){
						this.hylxtxt=''
					}
				}
				
				if(tabidx=='hdtz'||tabidx=='zxhd'){
					this.time=''
					this.hdlxtxt=''
				}
				this.title='';
				this.getConfirm()
			},
			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){
				var that=this;
				if(ite.type=='hyqd'){
					this.$tab.navigateTo('/work/pages/meeting/signin?id='+ite.id)
				}else if(ite.type=='zsyzsh'){
					uni.showModal({
						title: '确认审核',
						content: "是否确认审核",
						cancelText: '取消',
						confirmText: '确认',
						success: function(res) {
							if (res.confirm) {
								var params={
									investmentId:ite.id,
									type:2
								}
								getinvestmentshlFn(params).then(res=>{
									if(res.code==200){
										that.$toast('审核成功')
										that.ptype='';
										that.pageNum=1;
										that.list=[];
										that.reachflag=true;
										that.getDataFn()
									}
								})
							} else if (res.cancel) {
								
							}
						}
					})
				}else if(ite.type=='zsyzqy'){
					uni.showModal({
						title: '确认签约',
						content: "是否确认签约",
						cancelText: '取消',
						confirmText: '确认',
						success: function(res) {
							if (res.confirm) {
								var params={
									investmentId:ite.id,
									type:2
								}
								getinvestmentshlFn(params).then(res=>{
									if(res.code==200){
										that.$toast('签约成功')
										that.ptype='';
										that.pageNum=1;
										that.list=[];
										that.reachflag=true;
										that.getDataFn()
									}
								})
							} else if (res.cancel) {
								
							}
						}
					})
				}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)	
				}else if(type=='zsyz'||type=='wdzs'){
					this.$tab.navigateTo('/work/pages/meeting/zsyzdetails?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')	
			},
			getAddzsyz(){
				this.$tab.navigateTo('/work/pages/meeting/addzsyz')	
			},
			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
					}
					if(this.hdlxtxt){
						params.activityType=this.hdlxid
					}
					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=='zsyz'||this.tabidx=='wdzs'){
					if(this.time){
						params.activityDate=this.time
					}
					if(this.tabidx=='wdzs'){
						params.userId=this.userId
					}
					params.clueName=this.title
					getinvestmentListFn(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.hylxtxt){
						params.conferenceType=this.hylxid
					}
					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;flex:1;
			.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>