<!-- 计划列表 -->
<template>
	<view class="planDetail">
		<view class="header">
			<img class="header-bg" :src="imagesUrl('commonality/bg_1.png')">
			<view class="tabTitle">
				<view class="tabTitle_li" @tap="tabClick(index)" :key="index" v-for="(item,index) in tabText">
					<view class="tabTitle_text">
						<img :src="item.img">
						<view
							:id="curTab==index && curTab==0?'fontColor-A':(curTab==index && curTab==1?'fontColor-B':'')">
							{{item.name}}
						</view>
						<view>{{item.title}}</view>
					</view>
					<view class="line"></view>
					<view :class="{on:curTab==index}" class="tabTitle_across">
						<img :src="imagesUrl('commonality/img_xyzc_bg@1x.png')">
					</view>
				</view>
			</view>
		</view>
		<!-- 列表部分 -->
		<scroll-view scroll-y @scrolltolower="scrollGet" class="for-max-box">
			<view class="list">
				<view class="list-li" @click="planClick(item)" v-for="(item,index) in dataList">
					<img :src="imagesUrl('safetyCheck/icon_aqjc_jh@1x.png')">
					<view>{{item.planTitle}}</view>
					<img :src="imagesUrl('commonality/icon_wd_gd@1x.png')">
				</view>
			</view>
			<view class="get-data-p" v-if="!getDataType">
				<img class="get-data-img" :src="imagesUrl('safetyCheck/icon_aqjc_sl.png')">
				<view class="get-data-text">上拉加载</view>
			</view>
			<view class="get-data-null-p" v-if="getDataType">- 没有更多数据 -</view>
		</scroll-view>
		<view class="subBtn">
			<img class="subBtn-img" @click="saoCode()"
				:src="imagesUrl('safetyCheck/icon_aqjc_saoma.png')">
		</view>
		<view class="patrolLoginButton" v-if="patrolLoginType" @click="clickOut()">退出登录</view>
		<!-- 弹窗部分 -->
		<view class="shade" v-if="dialogVisible">
			<view class="null-box" @click="dialogClose()"></view>
			<view class="shade_n">
				<view class="title">
					<view>检查批次</view>
				</view>
				<view class="batch">
					<view class="batch-li" @click="batchClick(item)"
						v-for="(item,index) in batchList.checkPlanSetVoList">
						<view class="batch-li-l">
							<text>{{item.checkName}}</text>
							<text>开始检查日期：{{item.checkStartTime}}</text>
						</view>
						<view class="batch-li-r">检查进度{{item.checkSetProgress}}%
							<img :src="imagesUrl('commonality/icon_wd_gd@1x.png')">
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="shade-box" v-if="securityCheck">
			<view class="null-box" @click="goPage('securityCheck',false)"></view>
			<view class="shade_n">
				<view class="title">
					<view>请选择实验室</view>
				</view>
				<view class="batch">
					<view class="batch-li" @click="batchClickTow(item)" v-for="(item,index) in subjectData">
						<view class="batch-li-l">
							<text>{{item.planTitle}}-{{item.checkName}}</text>
							<text>{{item.subName}}{{item.roomNum?'('+item.roomNum+')':''}}</text>
						</view>
						<view class="batch-li-r">
							<img :src="imagesUrl('commonality/icon_wd_gd@1x.png')">
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		logout
	} from '@/pages/api/index.js'
	import {
		config
	} from '@/api/request/config.js'
	import {
		securityAppCheckPlanTitleList,
	} from '@/pages_safetyCheck/api/index.js'
	import {
		securityAppCheckPlanScanCode,
	} from '@/pages_safetyCheck/api/index.js'
	import { pageScanCode } from '@/utils/scanTheCode'
	export default {
		name: "planDetail",
		data() {
			return {
				patrolLoginType:uni.getStorageSync('patrolLoginType'),
				pageType: 0,
				tabText: [{
						name: '校级检查',
						title: '学校检查计划',
						img: this.imagesUrl('safetyCheck/icon_aqjc_xjjc@1x.png'),
					},
					{
						name: '学院自查',
						title: '学院自查计划',
						img: this.imagesUrl('safetyCheck/icon_aqjc_xxzc@1x.png'),
					},
					// {
					// 	name: '现场检查',
					// 	title: '检查隐患草稿',
					// 	img: this.imagesUrl('safetyCheck/icon_aqjc_xcjc@1x.png'),
					// },
					{
						name: '随手拍',
						title: '隐患上报整改',
						img: this.imagesUrl('safetyCheck/icon_aqjc_ssp@1x.png'),
					},
				],
				//校级/院级
				curTab: 0,
				queryParams: {
					page: 1,
					pageSize: 20,
					checkCategory: 1, //1校院巡查 2学院自查
				},
				total: 0,
				dataList: [],
				getDataType: false,
				dialogVisible: false,
				batchList: [],
				batchData: {},
				securityCheck:false,
				subjectData: [],
			}
		},
		onLoad(option) {
			this.$set(this,'securityCheck',false)
			this.getList()
		},
		onShow() {
			this.acceptSaoCode();
		},
		onHide() {
		  uni.$off('acceptSaoCode');
		},
		mounted() {

		},
		methods: {
			
			//退出按钮
			clickOut() {
				let self = this;
				uni.showModal({
					// title: '确认要退出吗?',
					content: '确认要退出吗',
					cancelColor: "#999",
					confirmColor: "#0183FA",
					success: function(res) {
						if (res.confirm) {
							self.logout();
						} else if (res.cancel) {}
					}
				});
			},
			//退出登录
			async logout() {
				let self = this;
				const {
					data
				} = await logout();
				if (data.code == 200) {
					uni.removeStorageSync('token');
					uni.removeStorageSync('userId');
					uni.removeStorageSync('userType');
					uni.redirectTo({
						url: '/pages/views/login/patrolLogin',
					});
				}
			},
			//滚动加载事件
			scrollGet() {
				let self = this;
				if (self.total / self.queryParams.pageSize <= self.queryParams.page) {
					this.$set(this, 'getDataType', true);
				} else {
					this.queryParams.page += 1;
					this.$nextTick(() => {
						this.getList();
					})
				}
			},
			/******调用摄像头******/
			saoCode() {
				pageScanCode();
			},
			acceptSaoCode(){
				let self = this;
				uni.$on('acceptSaoCode', (codeData) => {
					if (codeData.subId) {
						self.securityAppCheckPlanScanCode(codeData.subId,self.planSetId);
					} else {
						uni.showToast({
							title: '请扫描正确的二维码',
							icon: "none",
							mask: true,
							duration: 2000
						});
					}
				});
			},
			//查询计划
			async securityAppCheckPlanScanCode(subId,planSetId) {
				let self = this;
				let checkCategory = null;
				if(uni.getStorageSync('identityData')){
					if(uni.getStorageSync('identityData').type=='collegeAdmin'){
						checkCategory=2
					}else if(uni.getStorageSync('identityData').type=='schoolAdmin'){
						checkCategory=1
					}
				}
				let obj = {
					subId:subId,
					checkCategory:checkCategory,
				};
				if(planSetId){
					obj.planSetId = planSetId;
				}
				const {
					data
				} = await securityAppCheckPlanScanCode(obj);
				if (data.code == 200) {
					if(data.data[0]){
						if(data.data[1]){
							//多个
							self.$set(self,'subjectData',data.data);
							self.$set(self,'securityCheck',true);
						}else{
							//单个
							let infoData = data.data[0];
							infoData.pageType = 0;
							uni.navigateTo({
								url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItems?infoData=' + encodeURIComponent(
									JSON.stringify(infoData))
							});
						}
					}else{
						//没有
						uni.showToast({
							title: '该实验室暂无检查计划!',
							icon: "none",
							mask: true,
							duration: 2000
						});
					}
				}
			},
			batchClickTow(row) {
				let infoData = row;
				infoData.pageType = 0;
				uni.navigateTo({
					url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItems?infoData=' + encodeURIComponent(
						JSON.stringify(infoData))
				});
			},
			//安全检查扫码控制显示隐藏
			goPage(type,status) {
				if (type == 'securityCheck') {
					if(status){
						this.$set(this, "securityCheck", true)
					}else{
						this.$set(this, "securityCheck", false)
					}
				} 
			},
			
			//顶部tab点击
			tabClick(index) {
				this.$set(this.queryParams, 'page', 1);
				this.$set(this, 'total', 0);

				if (this.curTab != index) {
					this.$set(this, 'dataList', []);
					if (index == 0) {
						//校级检查
						this.$set(this, 'curTab', index);
						this.$set(this.queryParams, 'checkCategory', 1);
						this.getList()
					} else if (index == 1) {
						//学院自查
						this.$set(this, 'curTab', index);
						this.$set(this.queryParams, 'checkCategory', 2);
						this.getList()
					} else if (index == 2) {
						//随手拍
						uni.navigateTo({
							url: "/pages_safetyCheck/views/snapshotManage/snapshotList",
						});
					}
				}
			},
			//检查批次点击
			batchClick(row) {
				this.$set(this.batchData, 'checkPlanSetVoList', row);
				this.$nextTick(() => {
					uni.navigateTo({
						url: '/pages_safetyCheck/views/inspectManage/inspectList?infoData=' +
							encodeURIComponent(JSON.stringify(this.batchData))
					});
				})
			},
			planClick(row) {
				if (row.checkPlanSetVoList.length > 1) {
					this.$set(this, 'batchData', {
						planId: row.planId,
						planTitle: row.planTitle,
						checkCategory: row.checkCategory,
						checkTypeName: row.checkTypeName,
						crossCheck: row.crossCheck,
					});
					this.$set(this, 'batchList', row);
					this.dialogVisible = true;
				} else {
					//如果只有1个检查批次不弹窗
					this.$set(this, 'batchData', {
						planId: row.planId,
						planTitle: row.planTitle,
						checkCategory: row.checkCategory,
						checkTypeName: row.checkTypeName,
						crossCheck: row.crossCheck,
						checkPlanSetVoList: row.checkPlanSetVoList[0]
					});
					this.$nextTick(() => {
						uni.navigateTo({
							url: '/pages_safetyCheck/views/inspectManage/inspectList?infoData=' +
								encodeURIComponent(JSON.stringify(this.batchData))
						});
					})
				}
			},
			dialogClose() {
				this.dialogVisible = false;
			},
			async getList() {
				let self = this;
				const {
					data
				} = await securityAppCheckPlanTitleList(this.queryParams);
				if (data.code == 200) {
					if (self.queryParams.page == 1) {
						this.dataList = data.data.records;
						this.total = data.data.total;
						if (data.data.total / self.queryParams.pageSize <= self.queryParams.page) {
							this.$set(this, 'getDataType', true);
						}
					} else {
						this.dataList = [...this.dataList, ...data.data.records]
						this.total = data.data.total;
						if (data.data.total / self.queryParams.pageSize <= self.queryParams.page) {
							this.$set(this, 'getDataType', true);
						}
					}
				}
			},
		},
	}
</script>

<style lang="stylus" scoped>
	.planDetail {
		height: 100%;
		display: flex;
		flex-direction: column;

		.header {
			width: 100%;
			height: 482rpx;
			// position: fixed;
			// top: 0rpx;
			// z-index: 100;

			.header-bg {
				width: 750rpx;
				height: 310rpx;
				position: absolute;

			}

			.tabTitle {
				width: 690rpx;
				height: 242rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				display flex;
				justify-content: flex-start;
				align-items: center;
				position: absolute;
				left: 30rpx;
				top: 208rpx;

				.tabTitle_li {
					height: 242rpx;
					flex: 1;
					position: relative;
					text-align center;

					.line {
						width: 2rpx;
						height: 20rpx;
						background: #D8D8D8;
						border-radius: 0rpx 0rpx 0rpx 0rpx;
						position: absolute;
						top: 40%;
					}

					.tabTitle_text {
						display: flex;
						justify-content: center;
						flex-direction: column;
						align-items: center;

						>img {
							width: 82rpx;
							height: 82rpx;
							margin-top: 44rpx;
						}

						>view:nth-of-type(1) {
							font-size: 30rpx;
							color: #333333;
							line-height: 40rpx;
							text-align: left;
							margin-top: 8rpx;
						}

						>view:nth-of-type(2) {
							font-size: 24rpx;
							color: #666666;
							line-height: 30rpx;
							text-align: left;
							margin-top: 6rpx;
						}


						position: relative;

						&.on {}
					}

					.tabTitle_across {
						/* width: 50rpx;
						height: 4rpx;
						background: #0183FA;
						border-radius: 2rpx; */
						margin-left: 38%;
						margin-top: 37rpx;
						display none;

						>img {
							width: 40rpx;
							height: 26rpx;
						}

						&.on {
							display block;
						}
					}

				}

			}
		}

		.for-max-box {
			flex: 1;
			overflow-y scroll;

			.list {
				width: 690rpx;
				margin-left: 30rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;

				.list-li:nth-child(1) {
					border-top: none;
				}

				.list-li {
					border-top: 1rpx dashed #E0E0E0;
					height: 100rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					padding: 0 30rpx;
					box-sizing: border-box;

					>view:nth-of-type(1) {
						flex: 1;
						font-size: 28rpx;
						color: #333333;
						line-height: 39rpx;
						text-align: left;
						margin: 0 52rpx 0 20rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					>img:nth-of-type(1) {
						width: 42rpx;
						height: 42rpx;
					}

					>img:nth-of-type(2) {
						width: 24rpx;
						height: 24rpx;
					}

				}
			}

			.get-data-p {
				height: 100rpx;
				text-align: center;

				.get-data-img {
					width: 30rpx;
					height: 30rpx;
					margin: 0 auto;
					margin-top: 15rpx;
				}

				.get-data-text {
					text-align: center;
				}
			}

			.get-data-null-p {
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
			}
		}

		.shade {
			height: 100%;
			width: 100%;
			position: fixed;
			display: flex;
			flex-direction: column;
			z-index: 200;
			background: rgba(0, 0, 0, 0.2);

			.null-box {
				flex: 1;
			}

			.shade_n {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 750rpx;
				height: 466rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 0rpx 0rpx;
				overflow-y: auto;

				.title {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 50rpx 0 284rpx;
					box-sizing: border-box;
					border-bottom: 1rpx solid #E0E0E0;

					>view {
						font-size: 30rpx;
						color: #3D3D3D;
						line-height: 90rpx;
						text-align: left;
					}

					>img {
						width: 24rpx;
						height: 12rpx;
					}
				}

				.batch {
					padding: 0 30rpx;
					box-sizing: border-box;

					.batch-li {
						display: flex;
						justify-content: space-between;
						align-items: center;
						border-bottom: 1rpx solid #E0E0E0;
						padding: 20rpx 0 16rpx 0rpx;
						box-sizing: border-box;

						.batch-li-l {
							>text:nth-of-type(1) {
								display: block;
								font-size: 30rpx;
								color: #333333;
								line-height: 42rpx;
								text-align: left;
							}

							>text:nth-of-type(2) {
								display: block;
								font-size: 28rpx;
								color: #666666;
								line-height: 39rpx;
								text-align: left;
								margin-top: 6rpx;
							}
						}

						.batch-li-r {
							font-size: 28rpx;
							color: #666666;
							line-height: 39rpx;
							text-align: left;
							display: flex;
							justify-content: flex-start;
							align-items: center;

							>img {
								width: 24rpx;
								height: 24rpx;
								margin-left: 9rpx;
							}
						}
					}
				}
			}
		}

		#fontColor-A {
			color: #0040C1;
		}

		#fontColor-B {
			color: #009519;
		}

		#bgColor-A {
			color: #0183FA;
			background: rgba(1, 131, 250, 0.2);
		}

		#bgColor-B {
			color: #16B531;
			background: rgba(22, 181, 49, 0.2);
		}
		.subBtn{
			position: fixed;
			bottom: 90rpx;
			left: 295rpx;
			z-index: 100;
			.subBtn-img{
				width: 160rpx;
				height: 160rpx;
			}
		}
		.patrolLoginButton{
			position: absolute;
			top:80rpx;
			right:20rpx;
			color:#fff;
			background-color: red;
			padding:10rpx 20rpx;
			border-radius:10rpx;
			font-size:24rpx;
			line-height:30rpx;
			height:32rpx;
		}
		.shade-box {
			height: 100%;
			width: 100%;
			position: fixed;
			display: flex;
			flex-direction: column;
			z-index: 200;
			background: rgba(0, 0, 0, 0.2);
			top: 0;
		
			.null-box {
				flex: 1;
			}
		
			.shade_n {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 750rpx;
				height: 466rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 0rpx 0rpx;
				overflow-y: auto;
		
				.title {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding: 0 50rpx 0 284rpx;
					box-sizing: border-box;
					border-bottom: 1rpx solid #E0E0E0;
		
					>view {
						font-size: 30rpx;
						color: #3D3D3D;
						line-height: 90rpx;
						text-align: left;
					}
		
					>img {
						width: 24rpx;
						height: 12rpx;
					}
				}
		
				.batch {
					padding: 0 30rpx;
					box-sizing: border-box;
		
					.batch-li {
						display: flex;
						justify-content: space-between;
						align-items: center;
						border-bottom: 1rpx solid #E0E0E0;
						padding: 20rpx 0 16rpx 0rpx;
						box-sizing: border-box;
		
						.batch-li-l {
							>text:nth-of-type(1) {
								display: block;
								font-size: 30rpx;
								color: #333333;
								line-height: 42rpx;
								text-align: left;
							}
		
							>text:nth-of-type(2) {
								display: block;
								font-size: 28rpx;
								color: #666666;
								line-height: 39rpx;
								text-align: left;
								margin-top: 6rpx;
							}
						}
		
						.batch-li-r {
							font-size: 28rpx;
							color: #666666;
							line-height: 39rpx;
							text-align: left;
							display: flex;
							justify-content: flex-start;
							align-items: center;
		
							>img {
								width: 24rpx;
								height: 24rpx;
								margin-left: 9rpx;
							}
						}
					}
				}
			}
		}
	}
</style>
