<template>
	<view id="emergencyEvacuationSubList">
		<view class="top-search-max-box">
			<view class="left-search-box">
				<uni-icons class="icon-view-left" type="search" size="20"></uni-icons>
				<input class="search-input" @confirm="searchButton()"
				v-model="getData.subName" maxlength="10" focus placeholder="搜索实验室/房间号">
				<uni-icons v-if="getData.subName" @click="clearButton()"
				type="clear" class="icon-view-right" size="20" color="#999999"></uni-icons>
			</view>
			<view class="right-search-button" @click="searchButton()">搜索</view>
		</view>
		<scroll-view scroll-y @scrolltolower="scrollGet" class="bottom-for-max-box">
			<view class="for-max-big-sub-box" v-for="(item,index) in dataList" :key="index">
				<view class="left-big-box">
					<view class="sub-name-box">
						{{item.subName}}{{item.roomName?'('+item.roomName+')':''}}
					</view>
					<view class="sub-type-box">
						<view v-if="item.levelName" class="level-p"
							:style="'border:1px solid '+item.levelColor+';color:'+item.levelColor+';'">{{item.levelName}}</view>
						<view v-if="item.typeName" class="type-p">{{item.typeName}}</view>
						<view v-if="item.moldName" class="type-p">{{item.moldName}}</view>
						<view v-if="item.subArea" class="type-p">{{item.subArea}}m²</view>
					</view>
					<view class="sub-address-box">
						<img :src="imagesUrl('commonality/icon_14.png')">
						<view>
							{{item.deptName?item.deptName:''}}{{item.deptName&&item.buildName?'丨':''}}{{item.buildName?item.buildName:''}}{{item.buildName&&item.floorName?'-':''}}{{item.floorName?item.floorName:''}}
						</view>
					</view>
				</view>
				<view class="right-button" @click="goPage(item)">
					<view></view>
					<view>确认</view>
					<view></view>
				</view>
			</view>
			<view class="get-data-null-p" v-if="getDataType">- 没有更多数据 -</view>
			<view class="get-data-null-p" v-else="getDataType">- 滑动加载更多 -</view>
		</scroll-view>
	</view>
</template>


<script>
	import {
		laboratorySubRelInfoSelectAdminBySubPage,
		laboratoryBigViewGetFloorByBigView,
	} from '@/pages_manage/api/index.js'
	export default {
		data() {
			return {
				dataList: [],
				total: 0,
				getData: {
					page: 1,
					pageSize: 10,
					subName: '',
				},
				getDataType: false,
			}
		},
		created() {

		},
		mounted() {
			this.laboratorySubRelInfoSelectAdminBySubPage();
		},
		methods: {
			//跳转
			goPage(item) {
				if(!item.buildId){
					uni.showToast({
						title: '该实验室为绑定楼栋,请联系管理员.',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}else if(!item.floorId){
					uni.showToast({
						title: '该实验室为绑定楼层,请联系管理员.',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}else if(!item.subId){
					uni.showToast({
						title: '实验室数据异常,请联系管理员.',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				let obj = {
					type: 'skip',
					buildId: item.buildId,
					floorId: item.floorId,
					subId: item.subId,
					adminId: item.adminId,
				};
				this.laboratoryBigViewGetFloorByBigView(obj);
			},
			
			async laboratoryBigViewGetFloorByBigView(obj) {
				const {
					data
				} = await laboratoryBigViewGetFloorByBigView({
					id: obj.floorId
				})
				if (data.code == 200) {
					if(data.data[0]){
						if(data.data[0].buildLayoutVoList){
							if (data.data[0].buildLayoutVoList[0]) {
								uni.navigateTo({
									url: '/pages_manage/views/emergencyEvacuationBig?item=' + encodeURIComponent(JSON.stringify(obj))
								});
							}else{
								uni.showToast({
									title: '该实验室楼层未配置地图数据,请联系管理员.',
									icon: "none",
									mask: true,
									duration: 4000
								});
							}
						}else{
							uni.showToast({
								title: '该实验室楼层未配置地图数据,请联系管理员.',
								icon: "none",
								mask: true,
								duration: 4000
							});
						}
					}else{
						uni.showToast({
							title: '该实验室楼层未配置地图数据,请联系管理员.',
							icon: "none",
							mask: true,
							duration: 4000
						});
					}
				}
			},
			//搜索按钮
			clearButton(){
				this.$set(this, 'getDataType', false);
				this.$set(this, 'dataList', []);
				this.$set(this, 'total', 0);
				this.$set(this.getData, 'subName','');
				this.$set(this.getData, 'page', 1);
				this.laboratorySubRelInfoSelectAdminBySubPage();
			},
			//搜索按钮
			searchButton() {
				this.$set(this, 'getDataType', false);
				this.$set(this, 'dataList', []);
				this.$set(this, 'total', 0);
				this.$set(this.getData, 'page', 1);
				this.laboratorySubRelInfoSelectAdminBySubPage();
			},
			//滚动加载事件
			scrollGet() {
				let self = this;
				if (self.total / self.getData.pageSize <= self.getData.page) {
					this.$set(this, 'getDataType', true);
				} else {
					this.getData.page += 1;
					this.$nextTick(() => {
						this.laboratorySubRelInfoSelectAdminBySubPage();
					})
				}
			},
			//获取实验室
			async laboratorySubRelInfoSelectAdminBySubPage() {
				let self = this;
				const {
					data
				} = await laboratorySubRelInfoSelectAdminBySubPage(this.getData);
				if (data.code == 200) {
					if (self.getData.page == 1) {
						this.dataList = data.data.records;
						this.total = data.data.total;
						if (data.data.total / self.getData.pageSize <= self.getData.page) {
							this.$set(this, 'getDataType', true);
						}
					} else {
						this.dataList = [...this.dataList, ...data.data.records]
						this.total = data.data.total;
						if (data.data.total / self.getData.pageSize <= self.getData.page) {
							this.$set(this, 'getDataType', true);
						}
					}
				}
			},
		},
	}
</script>

<style lang="stylus" scoped>
	#emergencyEvacuationSubList {
		height: 100%;
		display flex;
		flex-direction column;
		overflow: hidden;

		.top-search-max-box {
			height: 130rpx;
			display: flex;
			background-color: #fff;
			margin-bottom: 20rpx;

			.left-search-box {
				display: flex;
				height: 78rpx;
				width: 590rpx;
				border: 1px solid #E0E0E0;
				border-radius: 50rpx;
				margin: 25rpx 9rpx 0 30rpx;

				.icon-view-left {
					margin: 18rpx 18rpx;
				}

				.search-input {
					width: 430rpx;
					height: 78rpx;
					line-height: 78rpx;
				}
				.icon-view-right{
					width:80rpx;
					height:80rpx;
					line-height:80rpx;
					text-align: center;
				}
			}

			.right-search-button {
				width: 110rpx;
				line-height: 100rpx;
				margin: 15rpx 0;
				color: #0183FA;
				text-align: center;
			}
		}

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

			.for-max-big-sub-box {
				background-color: #fff;
				border-radius: 20rpx;
				margin: 0 30rpx 20rpx;
				overflow: hidden;
				display: flex;

				.left-big-box {
					flex: 1;
					overflow: hidden;
					word-wrap: break-word;
					/* 旧版本浏览器支持 */
					overflow-wrap: break-word;
					/* 标准属性 */
					padding: 20rpx 0 26rpx 37rpx;

					.sub-name-box {
						font-size: 30rpx;
					}

					.sub-type-box {
						margin: 17rpx 0 26rpx 0;

						view:nth-child(1) {
							margin-left: 0 !important;
						}

						view {
							font-size: 24rpx;
							text-align: center;
							display: inline-block;
							margin: 10rpx 0 0 10rpx;
							border-radius: 10rpx;
							padding: 0 15rpx;
						}

						.level-p {
							height: 38rpx;
							line-height: 38rpx;
						}

						.type-p {
							height: 40rpx;
							line-height: 38rpx;
							background-color: rgba(1, 131, 250, 0.2);
							color: #0183FA;
						}
					}

					.sub-address-box {
						display: flex;

						img {
							display: inline-block;
							height: 30rpx;
							width: 30rpx;
							margin: 4rpx 14rpx 0 0;
						}

						view {
							flex: 1;
							font-size: 28rpx;
							line-height: 39rpx;
							margin-right: 20rpx;
						}
					}
				}

				.right-button {
					width: 100rpx;
					display: flex;
					flex-direction: column;
					background-color: #CCE6FE;

					view:nth-child(1) {
						flex: 1;
					}

					view:nth-child(2) {
						font-size: 24rpx;
						color: #0183FA;
						text-align: center;
					}

					view:nth-child(3) {
						flex: 1;
					}
				}
			}

			.get-data-null-p {
				text-align: center;
				line-height: 100rpx;
				padding-bottom: 80px;
				color: #999;
			}
		}
	}
</style>