<!-- 计划列表 -->
<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>
		<!-- 安全检查 -->
		<scanCodeCheck v-if="securityCheck"  :subjectData="subjectData"></scanCodeCheck>
		<!-- 弹窗部分 -->
		<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>

</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		securityAppCheckPlanTitleList,
	} from '@/pages_safetyCheck/api/index.js'
	import {
		scanCodeCheck
	} from '@/pages_safetyCheck/views/scanCodeCheck.vue'
	
	export default {
		name: "planDetail",
		components: {
			scanCodeCheck,
		},
		data() {
			return {
				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) {

		},
		onShow() {
			this.$set(this,'securityCheck',false)
			this.getList()
		},
		mounted() {

		},
		methods: {
			//滚动加载事件
			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() {
				let self = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						let list = res.result.split("?")[1].split("&");
						let codeData = {};
						list.forEach((item) => {
							codeData[item.split("=")[0]] = item.split("=")[1];
						})
						if (codeData.code) {
							console.log(codeData.subId)
							self.$set(self.subjectData, 'subId', codeData.subId);
							self.$set(self, "securityCheck", true)
						} else {
							uni.showToast({
								title: '请扫描正确的二维码',
								icon: "none",
								mask: true,
								duration: 2000
							});
						}
					}
				});
			},
			//安全检查扫码控制显示隐藏
			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;
			}
		}
	}
</style>
