<!-- 实验室搜索 -->
<template>
	<view class="hiddenDangerItemsSearch">
		<scroll-view scroll-y @scrolltolower="scrollGet" class="info-max-box">
			<view class="header">
				<view class="search">
					<view class="search-r">
						<img :src="imagesUrl('commonality/icon_aqjc_ss.png')" @click="searchBtn">
						<input type="text" v-model="queryParams.searchValue" placeholder="学院单位、实验室名称或房间号" name="search"
							@confirm='searchBtn' confirm-type='search' maxlength="50"
							placeholder-style="color: #333333;font-size:24rpx;">
						<view v-if="queryParams.searchValue" class="left-icons" @click="delSearchValue()">
							<uni-icons color="#0183FA" type="clear" size="20"></uni-icons>
						</view>
					</view>
					<view class="cancel" @click="cancelBtn()">取消</view>
				</view>
			</view>
			<view class="list">
				<view class="list-li" @click="listClick(item)" v-for="(item,index) in dataList">
					<view class="list-li-t">
						<img class="list-li-t-l" :src="imagesUrl('commonality/icon_aqjc_shiyanshi.png')">
						<view class="list-li-t-c">{{item.subName}}</view>
						<view class="list-li-t-r" :style="'border:1rpx solid '+item.classLevelColor+';background:'+item.classLevelColorTow+';'">
							<text
								:style="'border-right:1rpx solid '+item.classLevelColor+';color:'+item.classLevelColor+';'">{{item.classLevelName?item.classLevelName:''}}</text>
							<text
								:style="'color:'+item.classLevelColor+';'">{{item.classTypeNames?item.classTypeNames:''}}</text>
						</view>
					</view>
					<view class="list-li-b">
						<view class="list-li-b-t">
							<img :src="imagesUrl('commonality/icon_sy_zc@1x.png')">
							{{(laboratoryStatus==0 || laboratoryStatus==3)?(item.roomNum?item.roomNum:'-'):(item.subRoom?item.subRoom:'-')}}房间＆{{item.buildName?item.buildName:''}}
						</view>
						<view class="list-li-b-b">
							<view class="list-li-b-b-l">
								<img :src="imagesUrl('commonality/icon_sy_zc@1x.png')">
								{{item.deptName}}
							</view>
							<view  :class="item.manageStatus==2?'finished':'notFinished'" v-if="laboratoryStatus==0">
								{{item.manageStatus==2?'已完成':'未完成'}}</view>
						</view>
					</view>
			
				</view>
				<view class="get-data-null-p" v-if="getDataType">- 没有更多数据 -</view>
			</view>
			<!-- <view class="lab">
				<view class="lab-info" @click="listClick(item)" v-for="(item,index) in dataList">
					<img v-if="laboratoryStatus!=0" class="lab-info-l"
						:src="imagesUrl('commonality/icon_aqjc_shiyanshi.png')">
					<view :class="item.manageStatus==2?'finished':'notFinished'" v-if="laboratoryStatus==0">
						{{item.manageStatus==2?'已完成':'未完成'}}
					</view>
					<view class="lab-info-c">
						<view class="lab-info-c-t">
							<view class="lab-info-c-t-l">{{item.subName}}</view>
							<view class="lab-info-c-t-r"
								:style="'border:1rpx solid '+item.levelColor+';background:'+item.levelColorTow+';'">
								<text
									:style="'border-right:1rpx solid '+item.levelColor+';color:'+item.levelColor+';'">{{item.levelName?item.levelName:''}}</text>
								<text :style="'color:'+item.levelColor+';'">{{item.typeName?item.typeName:''}}</text>
							</view>
						</view>
						<view class="lab-info-c-b">
							<text
								v-if="laboratoryStatus==0">{{item.roomNum?item.roomNum:'-'}}房间＆{{item.buildName}}</text>
							<text
								v-if="laboratoryStatus==1 || laboratoryStatus==2">{{item.subRoom?item.subRoom:'-'}}房间＆{{item.buildName}}</text>
							<text>{{item.deptName}}</text>
						</view>
					</view>
				</view>
			</view> -->
			

		</scroll-view>
	</view>

</template>

<script>
	import {
		config
	} from '@/api/request/config.js'

	import {
		laboratorySubRelInfoSelectInfoByPage,
	} from '@/api/commonality/permission.js'
	import {
		securityCheckOptionList,
		laboratorySubRelInfoGetRelList,
		securityAppCheckManageList,
		securityAppCheckDangerReviewSubList,
		securityAppCheckDangerGetCheckDangerSubList,
	} from '@/pages_safetyCheck/api/index.js'
	export default {
		name: "hiddenDangerItemsSearch",
		components: {

		},
		data() {
			return {
				baseUrl: config.base_url,
				pageType: 1,
				checkOptionList: [],
				dataList: [],
				searchValue: '',
				form: {}, //接收上个页面传过来的参数
				getDataType: false,
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 20,
					searchValue: '',
					subId: '',
				},
				total: 0,
				laboratoryStatus: 0, // 0检查任务1复查验证2隐患整改 3从随手拍页面进入

			}
		},
		onLoad(option) {
			if (option.form) {
				this.form = JSON.parse(decodeURIComponent(option.form));
				console.log(this.form)
				if (this.form.subId) {
					this.queryParams.subId = this.form.subId
				}
				if (this.form.laboratoryStatus) {
					this.laboratoryStatus = this.form.laboratoryStatus
				}
			}
		},
		onShow() {

		},
		mounted() {
			this.getList();
		},
		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();
					})
				}
			},
			//实验室搜索
			searchBtn() {
				this.dataList = [];
				this.getList();
			},
			//清除输入框内容
			delSearchValue() {
				if (this.queryParams.searchValue) {
					this.$set(this.queryParams, 'searchValue', '');
					this.$set(this, 'dataList', []);
					this.getList();
				}
			},
			//级联等级
			//取消
			cancelBtn() {
				let self = this;
				/* self.queryParams.searchValue = '';
				self.dataList = [];
				self.getList(); */

				if (this.form.laboratoryStatus == 0 || this.form.laboratoryStatus == 1 || this.form.laboratoryStatus ==
					2) {
					uni.redirectTo({
						url: '/pages_safetyCheck/views/inspectManage/inspectList?infoData=' +
							encodeURIComponent(
								JSON.stringify(this.form))
					});

				} else if (this.form.laboratoryStatus == 3) { //从计划实验室列表返回
					uni.redirectTo({
						url: '/pages_safetyCheck/views/snapshotManage/snapshotList?form=' +
							encodeURIComponent(JSON.stringify(this.form))
					});

				}


			},
			//十六进制颜色值和RGB格式转换
			hexToRgb(hex, opacity = 1) {
				// 去除#号
				var color = hex.replace("#", "");
				// 分割成红、绿、蓝三部分的16进制字符串
				var red = parseInt(color.substring(0, 2), 16);
				var green = parseInt(color.substring(2, 4), 16);
				var blue = parseInt(color.substring(4, 6), 16);
				return `RGB(${red}, ${green}, ${blue},${opacity})`;
			},
			listClick(item) {
				if (this.form.laboratoryStatus == 0 || this.form.laboratoryStatus == 1 || this.form.laboratoryStatus ==
					2) {
					let infoData = {
						...item,
						...this.form
					};
					uni.redirectTo({
						url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItems?infoData=' +
							encodeURIComponent(
								JSON.stringify(infoData))
					});
				} else if (this.form.laboratoryStatus == 3) { //从计划实验室列表返回
					this.$set(this.form, "subId", item.subId)
					this.$set(this.form, "subName", item.subName)
					this.$set(this.form, "subRoom", item.roomNum)
					this.$set(this.form, "deptId", item.deptId)
					this.$set(this.form, "deptName", item.deptName)
					this.$set(this.form, "buildId", item.buildId)
					this.$set(this.form, "buildName", item.buildName)
					this.$set(this.form, "floorId", item.floorId)
					this.$set(this.form, "floorName", item.floorName)
					this.$set(this.form, "typeId", item.typeId)
					this.$set(this.form, "classTypeNames", item.classTypeNames)
					this.$set(this.form, "levelId", item.levelId)
					this.$set(this.form, "classLevelName", item.classLevelName)
					uni.redirectTo({
						url: '/pages_safetyCheck/views/snapshotManage/snapshotList?form=' +
							encodeURIComponent(JSON.stringify(this.form))
					});
				}


			},

			//搜索房间接口
			async getList() {
				let self = this;
				let obj = JSON.parse(JSON.stringify(this.queryParams));
				if (this.laboratoryStatus == 0) {
					obj.planSetId = this.form.checkPlanSetVoList.planSetId;
					obj.planId = this.form.checkPlanSetVoList.planId;
					//检查计划
					const {
						data
					} = await securityAppCheckManageList(obj);
					if (data.code == 200) {

						data.data.records.forEach(function(item) {
							if (item.classLevelColor) {
								item.classLevelColorTow = self.hexToRgb(item.classLevelColor, 0.2)
							}

						})
						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);
							}
						}

					}
				} else if (this.laboratoryStatus == 1) {
					obj.planSetId = this.form.checkPlanSetVoList.planSetId;
					obj.planId = this.form.checkPlanSetVoList.planId;
					obj.userId = uni.getStorageSync('userId');
					const {
						data
					} = await securityAppCheckDangerReviewSubList(obj);
					if (data.code == 200) {
						this.dataList = data.data;
						this.$set(this, 'getDataType', true);
					}
				} else if (this.laboratoryStatus == 2) {
					obj.planSetId = this.form.checkPlanSetVoList.planSetId;
					obj.planId = this.form.checkPlanSetVoList.planId;
					obj.userId = uni.getStorageSync('userId');
					const {
						data
					} = await securityAppCheckDangerGetCheckDangerSubList(obj);
					if (data.code == 200) {
						this.dataList = data.data;
						this.$set(this, 'getDataType', true);
					}
				} else if (this.laboratoryStatus == 3) {
					const {
						data
					} = await laboratorySubRelInfoSelectInfoByPage(this.queryParams);
					if (data.code == 200) {
						if (data.data.records[0]) {
							data.data.records.forEach(function(item) {
								if (item.levelColor) {
									item.classTypeNames = item.typeName
									item.classLevelName = item.levelName
									item.classLevelColor = item.levelColor
									item.classLevelColorTow = self.hexToRgb(item.levelColor, 0.2)
								}

							})
							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);
								}
							}
						} else {
							uni.showToast({
								title: '未找到相关实验室',
								icon: "none",
								mask: true,
								duration: 2000
							});
						}
					}
				}

			},

		}
	}
</script>

<style lang="stylus" scoped>
	.hiddenDangerItemsSearch {
		height: 100%;
		display flex;
		overflow: hidden;

		.info-max-box {}

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

		#totalColor-B {
			color: #16B531;
			background: rgba(22, 181, 49, 0.2);
		}

		#totalColor-C {
			color: #FF8C00;
			background: rgba(255, 140, 0, 0.2);
		}

		.header {
			width: 100%;
			position: fixed;
			top: 0rpx;
			z-index: 100;
			background: #fff;

			.search {
				width: 750rpx;
				height: 100rpx;
				background: #FFFFFF;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				.search-r {
					width: 610rpx;
					height: 60rpx;
					background: #FFFFFF;
					border-radius: 50rpx 50rpx 50rpx 50rpx;
					border: 1rpx solid #E0E0E0;
					font-size: 24rpx;
					color: #999999;
					line-height: 60rpx;
					text-align: left;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					padding: 0 20rpx;
					box-sizing: border-box;

					>img {
						width: 30rpx;
						height: 30rpx;
						margin-right: 20rpx;
					}

					>input {
						width: 500rpx;
					}
				}
			}

			.cancel {
				font-size: 28rpx;
				color: #0183FA;
				line-height: 30rpx;
				text-align: left;
				margin-left: 18rpx;
			}
		}

		.list {
			width: 750rpx;
			padding: 0 30rpx;
			box-sizing: border-box;
			margin-top: 120rpx;
		
			.list-li {
				width: 690rpx;
				min-height: 240rpx;
				background: #FFFFFF;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				padding: 0 30rpx;
				box-sizing: border-box;
				margin-top: 20rpx;
				.list-li-t {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					height: 90rpx;
					border-bottom: 2rpx dashed #D8D8D8;
		
					.list-li-t-l {
						width: 40rpx;
						height: 40rpx;
						margin-right: 16rpx;
					}
		
					.list-li-t-c {
						width: 264rpx;
						font-size: 30rpx;
						color: #333333;
						line-height: 30rpx;
						text-align: left;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						margin-right: 24rpx;
					}
		
					.list-li-t-r {
						display: flex;
						justify-content: flex-start;
						border-radius: 10rpx 10rpx 10rpx 10rpx;
						width: 200rpx;
						height: 40rpx;
						margin-left: 10rpx;
		
						>text {
							display: inline-block;
							flex: 1;
							text-align: center;
							font-size: 24rpx;
							line-height: 40rpx;
							text-align: center;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}
				}
		
				.list-li-b {
					overflow: hidden;
					.list-li-b-t {
						display: flex;
						justify-content: flex-start;
						align-items: center;
		
						>img {
							width: 28rpx;
							height: 26rpx;
							margin-right: 16rpx;
						}
		
						font-size: 28rpx;
						color: #666666;
						line-height: 30rpx;
						text-align: left;
						margin-top: 32rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
		
					}
		
					.list-li-b-b {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-top: 20rpx;
		
						.list-li-b-b-l {
							display: flex;
							justify-content: flex-start;
							align-items: center;
		
							>img {
								width: 28rpx;
								height: 26rpx;
								margin-right: 16rpx;
							}
		
							font-size: 28rpx;
							color: #666666;
							line-height: 30rpx;
							text-align: left;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
		
						.finished {
							width: 110rpx;
							height: 40rpx;
							background: rgba(1,131,250,0.2);
							border-radius: 20rpx 20rpx 20rpx 20rpx;
							font-size: 24rpx;
							color: #0183FA;
							line-height: 40rpx;
							text-align: center;
						}
		
						.notFinished {
							width: 110rpx;
							height: 40rpx;
							background: #E0E0E0;
							border-radius: 20rpx 20rpx 20rpx 20rpx;
							font-size: 24rpx;
							color: #666666;
							line-height: 40rpx;
							text-align: center;
						}
					}
				}
			}
		}
		.get-data-null-p {
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
		}
		.lab {
			margin-top: 120rpx;

			.lab-info {
				background: #FFFFFF;
				display: flex;
				justify-content: space-between;
				border: 2rpx dashed #D8D8D8;


				.lab-info-l {
					width: 80rpx;
					height: 80rpx;
					background: #0183FA;
					border-radius: 10rpx 10rpx 10rpx 10rpx;
					margin-left: 30rpx;
					margin-top: 30rpx;
					margin-bottom: 42rpx;
				}

				.finished {
					width: 90rpx;
					height: 90rpx;
					background: #0183FA;
					border-radius: 100rpx 100rpx 100rpx 100rpx;
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 90rpx;
					text-align: center;
					margin-left: 30rpx;
					margin-top: 30rpx;
					margin-bottom: 32rpx;
				}

				.notFinished {
					width: 90rpx;
					height: 90rpx;
					background: #E0E0E0;
					border-radius: 100rpx 100rpx 100rpx 100rpx;
					font-size: 24rpx;
					color: #999999;
					line-height: 90rpx;
					text-align: center;
					margin-left: 30rpx;
					margin-top: 30rpx;
					margin-bottom: 32rpx;
				}

				.lab-info-c {
					margin: 24rpx 30rpx 0 20rpx;
					flex: 1;

					.lab-info-c-t {
						display: flex;
						justify-content: space-between;

						.lab-info-c-t-l {
							font-size: 30rpx;
							color: #333333;
							line-height: 42rpx;
							text-align: left;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.lab-info-c-t-r {
							display: flex;
							justify-content: flex-start;
							border-radius: 10rpx 10rpx 10rpx 10rpx;
							width: 180rpx;
							height: 40rpx;
							margin-left: 10rpx;

							>text {
								display: inline-block;
								flex: 1;
								text-align: center;
								font-size: 24rpx;
								line-height: 40rpx;
								text-align: center;
							}
						}
					}

					.lab-info-c-b {
						margin-top: 16rpx;
						display: flex;
						justify-content: space-between;

						>text {
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
						>text:nth-of-type(1) {
							font-size: 30rpx;
							color: #666666;
							line-height: 30rpx;
							text-align: left;
						}

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

		}

	}
</style>
