<template>
	<view>
		<view class="status_bar"></view>
		<view class="" style="position: relative;top: 40px;">
			<view style="position: fixed;z-index: 100;background-color: #FFFFFF;height: 80px;">
				<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备搜索"></uni-nav-bar>
				<view class="search_top_input">
					<input type="text" value="" placeholder="请输入设备ID或设备名称" v-model="imports" @input="searchinp" />
					<u-icon name="search" size="40" class="icon" @click="search"></u-icon>
				</view>
			</view>
			<view class="prevents">
				<view class="prevents_item" v-for="item,index in eqlistdata" :key="index" @click="eqdetails(item)">
					<view class="" v-if="side_type == 5">
						<image
							:src="item.is_online==1?'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png':'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/7.png'"
							mode="" class="prevents_item_img"></image>
						<view class="prevents_item_top">
							<p>设备名称：{{item.equip_name==""?"无":item.equip_name}}</p>
							<p :class="item.is_online==1?'green':'red'" v-text="item.is_online==1?'在线':'离线'"></p>
						</view>
						<view class="prevents_item_bot">
							<p>设备 ID：{{item.equip_id || item.device_id}}</p>
							<p>最新上报时间：{{item.uptime|timeFormat()}}</p>
						</view>
					</view>
					<view class="" v-if="side_type == 15">
						<image src="http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png" mode=""
							class="prevents_item_img"></image>
						<view class="prevents_item_top">
							<p>设备名称：{{item.device_name==""?"无":item.device_name}}</p>
						</view>
						<view class="prevents_item_bot">
							<p>设备 ID：{{item.device_id}}</p>
							<p>最新上报时间：{{item.uptime|timeFormat()}}</p>
						</view>
					</view>
					<view class="" v-if="side_type == 11 || side_type == 19 || side_type == 20">
						<image src="http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png" mode=""
							class="prevents_item_img"></image>
						<view class="prevents_item_top">
							<p>
								设备名称：{{
					  item.device_name == "" ? "暂无" : item.device_name
					}}
							</p>
						</view>
						<view class="prevents_item_bot">
							<p>设备 ID：{{ item.device_id }}</p>
							<p>最新上报时间：{{item.uptime|timeFormat()}}</p>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		Debounce,
		Throttle
	} from "../../util/anitthro.js"
	export default {
		data() {
			return {
				imports: '',
				eqlistdata: [],
				page: 1,
				size: 10,
				value: '',
				side_type: 5
			}
		},
		methods: {
			async eqlist() { //设备列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=weather.weather.qxz_page',
					data: {
						device_type_id: 2,
						page: this.page,
						size: this.size,
						device_id: this.imports
					}
				})
				// console.log(res)
				this.eqlistdata = this.eqlistdata.concat(res.ids)
				console.log(this.eqlistdata)
			},
			async tubulareqlist() { //设备列表 环境监测
				this.loadingtf = true
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=weather.weather.nd_qxz_page',
					data: {
						page: this.page,
						page_size: 10,
						device_id: this.imports
					}
				})
				this.loadingtf = false
				this.eqlistdata = this.eqlistdata.concat(res.ids)
				console.log(res.ids)
			},
			async getEquipList() { //设备列表 环境监测
				this.loadingtf = true;
				const res = await this.$myRequest({
					method: "POST",
					url: "/api/api_gateway?method=wheat.wheat.wheat_list",
					data: {
						device_id: this.imports,
						device_name: "",
						page: this.page,
						device_type: this.side_type,
					},
				});
				this.loadingtf = false;
				this.eqlistdata = this.eqlistdata.concat(res.ids);
			},
			clickLeft() {
				uni.navigateTo({
					url: "./index"
				})
			},
			search() {
				this.eqlistdata = []
				if (this.side_type == 5) {
					this.eqlist()
				} else if (this.side_type == 15) {
					this.tubulareqlist()
				} else if (this.side_type == 11 || this.side_type == 19 || this.side_type == 20) {
					this.getEquipList()
				}
			},
			searchinp() {
				Debounce(() => {
					this.search()
				}, 1000)()
			},
			eqdetails(data) {
				if (this.side_type == 5) {
					uni.navigateTo({
						url: "./equipment?shebei=" + JSON.stringify(data)
					})
				} else if (this.side_type == 15) {
					uni.navigateTo({
						url: "./gsequipment?shebei=" + JSON.stringify(data)
					})
				}
			}
		},
		onLoad(option) {
			this.side_type = option.type
			console.log(this.side_type)
		}
	}
</script>

<style lang="scss">
	.search_top_input {
		width: 90%;
		height: 54rpx;
		background-color: #E4E4E4;
		border-radius: 27rpx;
		position: absolute;
		top: 100rpx;
		right: 5%;
		padding-top: 8rpx;
		box-sizing: border-box;

		input {
			width: 85%;
			// text-indent: 1rem;
			font-size: 26rpx;
			padding-left: 20px;
			box-sizing: border-box;
		}

		.icon {
			position: absolute;
			top: 8rpx;
			right: 26rpx;
		}
	}

	.prevents {
		width: 100%;
		position: absolute;
		top: 94px;

		.prevents_item {
			width: 95%;
			margin: 0 auto 30rpx;
			border-radius: 10rpx;
			box-shadow: 0 0 10rpx #bcb9ca;
			padding: 20rpx 40rpx 20rpx 80rpx;
			position: relative;
			box-sizing: border-box;

			.prevents_item_img {
				width: 30rpx;
				height: 50rpx;
				position: absolute;
				top: -4rpx;
				left: 30rpx;
			}

			.prevents_item_top {
				display: flex;
				justify-content: space-between;
				height: 60rpx;
				border-bottom: 2rpx solid #F4F4F4;
				line-height: 60rpx;
				font-size: 26rpx;

				.red {
					color: #ff0000;
				}

				.green {
					color: #7DBB91;
				}
			}

			.prevents_item_bot {
				margin-top: 20rpx;
				font-size: 26rpx;
				color: #BDBDBD;
			}
		}
	}
</style>
