<template>
	<view>
		<view style="position: fixed;z-index: 100;height: 160rpx;background-color: #FFFFFF;">
			<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" style="margin-top: 36rpx;"></uni-nav-bar>
			<view class="">
				<view class="search_top_input">
					<input type="text" v-model="value" placeholder="请选择设备类型" disabled @click="show = true"/>
					<u-icon name="arrow-down-fill" size="20" class="icon" @click="show = true"></u-icon>
					<u-action-sheet :list="options1" v-model="show" @click="actionSheetCallback"></u-action-sheet>
				</view>
				<view class="search_bot_input">
					<input type="text" value="" placeholder="请输入设备ID" v-model="imports" />
					<u-icon name="search" size="40" class="icon" @click="search"></u-icon>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list_item" v-for="(item,index) in eqlistdata" :key="index">
				<view class="list_item_top">
					<p class="p1">
						<image :src="images[current].path" mode=""></image>
						{{item.device_name}}
					</p>
					<p :class="[item.device_status?'p2':'p_out']">{{item.device_status?"在线":"离线"}}</p>
				</view>
				<view class="list_item_text">
					<p>设备ID：{{item.device_id}}</p>
					<p>适配用户：无</p>
					<p>添加设备时间：{{item.status_time|timeFormat()}}</p>
				</view>
				<view class="list_item_btn">
					修改名称
				</view>
			</view>
			<view class="none" v-if="eqlistdatatf">
				暂无数据
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options1: [{
						text: '杀虫灯',
					},
					{
						text: '测报灯',
					},
					{
						text: '智能性诱',
					},
					{
						text: '环境检测',
					},
					{
						text: '监控设备',
					},
					{
						text: '孢子仪',
					},
				],
				imports: '',
				eqlistdata: [],
				current: 0,
				images: [{
						path: "../../static/image/fourMoodBase/杀虫灯.png",
						id: 2
					},
					{
						path: "../../static/image/fourMoodBase/测报灯.png",
						id: 3
					}, {
						path: "../../static/image/fourMoodBase/性诱测报.png",
						id: 4
					}, {
						path: "../../static/image/fourMoodBase/环境监测.png",
						id: 5
					}, {
						path: "../../static/image/fourMoodBase/监控.png",
						id: 6
					}, {
						path: "../../static/image/fourMoodBase/孢子仪.png",
						id: 7
					}
				],
				eqlistdatatf: false,//暂无数据
				show: false,//选择框
				value:'',//选择框值
				indexs:2//设备id
			}
		},
		methods: {
			async eqlist() { //设备列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
					data: {
						device_type_id: this.indexs,
						device_id: this.imports
					}
				})
				this.eqlistdata = res.data
				if (this.eqlistdata.length == 0) {
					this.eqlistdatatf = true
				} else {
					this.eqlistdatatf = false
				}
			},
			clickLeft() {//返回
				uni.switchTab({
					url: "./index"
				})
			},
			search() {//搜索
				this.eqlist()
			},
			actionSheetCallback(index) {//选择框
				this.value = this.options1[index].text;
				this.indexs = index+2
			}
		}
	}
</script>
<style lang="scss">
	.search_top_input {
		width: 80%;
		height: 54rpx;
		background-color: #E4E4E4;
		border-radius: 27rpx;
		position: absolute;
		top: 18rpx;
		right: 18rpx;
		padding-top: 8rpx;

		input {
			width: 85%;
			text-indent: 1rem;
			font-size: 26rpx;
		}

		.icon {
			position: absolute;
			top: 18rpx;
			right: 32rpx;
		}
	}

	.search_bot_input {
		width: 80%;
		height: 54rpx;
		background-color: #E4E4E4;
		border-radius: 27rpx;
		position: absolute;
		top: 44px;
		right: 18rpx;
		padding-top: 8rpx;

		input {
			width: 85%;
			text-indent: 1rem;
			font-size: 26rpx;
		}

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

	.list {
		width: 100%;
		background-color: #FDFDFD;
		position: absolute;
		top: 160rpx;

		.list_item {
			width: 95%;
			margin: 20rpx auto;
			padding: 10rpx 20rpx;
			position: relative;
			background-color: #FFFFFF;

			.list_item_top {
				display: flex;
				justify-content: space-between;

				.p1 {
					height: 60rpx;
					line-height: 60rpx;
					font-size: 28rpx;

					image {
						width: 40rpx;
						height: 40rpx;
						vertical-align: text-top;
						margin-right: 20rpx;
					}
				}

				.p2 {
					height: 60rpx;
					line-height: 60rpx;
					font-size: 28rpx;
					color: #42b983;
				}

				.p_out {
					height: 60rpx;
					line-height: 60rpx;
					font-size: 28rpx;
					color: red;
				}
			}

			.list_item_text {
				margin-top: 20rpx;

				p {
					font-size: 24rpx;
					color: #636363;
					margin-top: 10rpx;
				}

				p:first-child {
					font-size: 28rpx;
					font-weight: 700;
				}
			}

			.list_item_btn {
				width: 126rpx;
				color: #42b983;
				height: 40rpx;
				text-align: center;
				border: 1rpx solid #42b983;
				border-radius: 25rpx;
				font-size: 24rpx;
				line-height: 35rpx;
				position: absolute;
				top: 136rpx;
				right: 20rpx;
			}
		}

		.none {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			text-align: center;
		}
	}
</style>