<!-- 实验室搜索 -->
<template>
	<view class="hiddenDangerItemsSearch">
		<view class="header">
			<view class="search">
				<view class="search-r">
					<img src="@/pages_safetyCheck/images/icon_aqjc_ss.png" @click="searchBtn">
					<input type="text" v-model="searchValue" placeholder="模糊搜索检查项" name="search" @confirm='searchBtn'
						confirm-type='search' maxlength="50" placeholder-style="color: #333333;font-size:24rpx;">
				</view>
				<view class="cancel" @click="cancelBtn">取消</view>
			</view>
		</view>
		<!-- 
		<view class="list">
			<view class="list-li" v-for="(item,index) in dataList" @click="confirm(item)">
				{{item.hazardCheckCode}}{{item.hazardCheckName}}
			</view>
		</view> -->
		<view class="lab-info" @click="listClick(item)" v-for="(item,index) in dataList">
			<img class="lab-info-l" src="@/pages_safetyCheck/images/icon_aqjc_shiyanshi.png">
			<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.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="lab-info-c-b">
					<text>{{tabIndexTow==0?item.roomNum:item.subRoom}}房间＆{{item.buildName}}</text>
					<text>{{item.deptName}}</text>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	
	import {
		systemSubjectGetList,
	} from '@/api/commonality/permission.js'
	import {
		securityCheckOptionList,
		laboratorySubRelInfoGetRelList
	} from '@/pages_safetyCheck/api/index.js'
	export default {
		name: "hiddenDangerItemsSearch",
		components: {

		},
		data() {
			return {
				baseUrl: config.base_url,
				pageType: 1,
				checkOptionList: [],
				dataList: [],
				searchValue: '',
				form: {}, //接收上个页面传过来的参数
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 20,
				},
				total:0,

			}
		},
		onLoad(option) {
			if (option.form) {
				this.form = JSON.parse(decodeURIComponent(option.form));
				this.pageType = this.form.pageType;
			}
		},
		onShow() {

		},
		mounted() {
			this.buildBySub();
			//this.treeselect();
		},
		methods: {
			//滚动事件
			scrollGet() {},
			//实验室搜索
			searchBtn() {
				this.dataList = [];
				this.treeselect();
			},
			//取消
			cancelBtn() {
				this.searchValue = '';
				this.dataList = [];
				this.treeselect();
			},
			confirm(row) {
				this.$set(this.form, "hazardCheckId1", row.hazardCheckId1)
				this.$set(this.form, "hazardCheckName1", row.hazardCheckName1)
				this.$set(this.form, "hazardCheckCode1", row.hazardCheckCode1)
				this.$set(this.form, "hazardCheckId2", row.hazardCheckId2)
				this.$set(this.form, "hazardCheckName2", row.hazardCheckName2)
				this.$set(this.form, "hazardCheckCode2", row.hazardCheckCode2)
				this.$set(this.form, "hazardCheckId", row.hazardCheckId)
				this.$set(this.form, "hazardCheckName", row.hazardCheckName)
				this.$set(this.form, "hazardCheckCode", row.hazardCheckCode)
				this.$set(this.form, "hazardCheckPoint", row.hazardCheckPoint)
				if (this.pageType == 1) {
					//随手拍进入
					uni.redirectTo({
						url: '/pages_safetyCheck/views/snapshotManage/snapshotList?form=' + encodeURIComponent(JSON
							.stringify(this.form))
					});
				} else if (this.pageType == 2) {
					//隐患项列表进入
					uni.redirectTo({
						url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItems?infoData=' +
							encodeURIComponent(JSON.stringify(this.form))
					});
				}

			},
			
			//搜索房间接口
			async buildBySub() {
				let self = this;
				const {
					data
				} = await systemSubjectGetList({
					'searchValue': this.form.searchValue,
					'subId': this.form.subId,
				});
				if (data.code == 200) {
					if (data.data[0]) {
						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
						});
					}
				}
			},
			async treeselect() {
				let self = this;
				const {
					data
				} = await securityCheckOptionList({
					searchValue: this.searchValue
				});
				if (data.code == 200) {
					let list = [];
					data.data.forEach(function(item) {
						item.children.forEach(function(item2) {
							item2.children.forEach(function(item3) {
								list.push({
									hazardCheckId1: item.id,
									hazardCheckName1: item.name,
									hazardCheckCode1: item.code,
									hazardCheckId2: item2.id,
									hazardCheckName2: item2.name,
									hazardCheckCode2: item2.code,
									hazardCheckId: item3.id,
									hazardCheckName: item3.name,
									hazardCheckCode: item3.code,
									hazardCheckPoint: item3.mainPoint
								})
							})
						})
					})
					this.dataList = list
				}
			},
		}
	}
</script>

<style lang="stylus" scoped>
	.hiddenDangerItemsSearch {
		height: 100%;
		display flex;
		box-sizing: border-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;
			background: #FFFFFF;
			margin-top: 110rpx;
			padding-top: 12rpx;
			box-sizing: border-box;

			.list-li {
				min-height: 80rpx;
				margin: 0 30rpx;
				font-size: 29rpx;
				color: #3D3D3D;
				line-height: 80rpx;
				text-align: left;
				border-bottom: 1rpx solid #E0E0E0;
			}
		}

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

			.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: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>
