<template>
	<view>
		<view style="position: fixed;z-index: 100;width: 100%;">
			<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备详情"></uni-nav-bar>
		</view>
		<view class="info">
			<view class="info_item">
				<image :src="eqinfo.item.device_status==1?'../../static/image/cb/onBg.png':'../../static/image/cb/offBg.png'" mode="" class="bgi"></image>
				<p style="font-size: 32rpx;">设备 ID：{{eqinfo.item.device_id}}</p>
				<p>设备名称：{{eqinfo.item.device_name}}</p>
				<p>设备型号：{{eqinfo.item.dver_num}}</p>
				<p>最近上报时间：{{eqinfo.item.status_time|timeFormat()}}</p>
				<p>设备地址：{{eqinfo.item.address}}</p>
			</view>
		</view>
		<view class="control">
			<view class="control_item" @click="control">
				<image src="../../static/image/prevention/8.png" mode=""></image>
				<p>设备控制</p>
			</view>
			<view class="control_item" @click="charts">
				<image src="../../static/image/prevention/9.png" mode=""></image>
				<p>历史数据</p>
			</view>
			<view class="control_item" @click="sim">
				<image src="../../static/image/prevention/10.png" mode=""></image>
				<p>SIM卡详情</p>
			</view>
		</view>
		<view class="realtime">
			<p class="realtime_title">实时数据</p>
			<view class="realtime_text">
				<view class="realtime_text_item">
					<view class="realtime_text_item_info" v-for="item,index in olddatas" :key="index">
						<view class="item_info_img">
							<image :src="item.icon" mode=""></image>
						</view>
						<view class="item_info_text">
							<p>{{item.txt}}</p>
							<p style="margin-top: 20rpx;">{{item.value}}</p>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				eqinfo: {},
				olddata: {},
				olddatas: [],
			}
		},
		methods: {
			modification() {
				this.olddatas = [{
						icon: '../../static/image/cb/icon02.png',
						txt: '设备开关',
						value: this.olddata.ds == 1 ? '在线' : '离线',
					},
					{
						icon: '../../static/image/cb/icon05.png',
						txt: '工作状态',
						value: this.olddata.ws == 1 ? "工作":"待机"
					},
					{
						icon: '../../static/image/prevention/44.png',
						txt: '电击次数',
						value: this.olddata.ct
					},
					{
						icon: '../../static/image/prevention/33.png',
						txt: '定时时长',
						value: Math.abs(this.olddata.et - this.olddata.st)
					}, {
						icon: '../../static/image/cb/icon08.png',
						txt: '环境温度(℃)',
						value: this.olddata.at
					}, {
						icon: '../../static/image/cb/icon07.png',
						txt: '环境湿度(%)',
						value: this.olddata.ah
					}, {
						icon: '../../static/image/cb/icon16.png',
						txt: '信号强度',
						value: this.olddata.csq
					}, {
						icon: '../../static/image/prevention/100.png',
						txt: '清虫间隔(min)',
						value: this.olddata.clt
					}, {
						icon: '../../static/image/prevention/101.png',
						txt: '雨控状态',
						value: this.olddata.rps == 1 ? "雨控" : '正常'
					}, {
						icon: '../../static/image/prevention/102.png',
						txt: '温控状态',
						value: this.olddata.tps == 1 ? "温控" : '正常'
					}, {
						icon: '../../static/image/prevention/104.png',
						txt: '灯管状态',
						value: this.olddata.lamp == 1 ? "亮" : '灭'
					},
					{
						icon: '../../static/image/prevention/105.png',
						txt: '充电电压',
						value: this.olddata.cv / 100
					},
					{
						icon: '../../static/image/prevention/106.png',
						txt: '电压状态',
						value: this.olddata.batStatus == 1 ? "欠压" : '正常'
					},
					{
						icon: '../../static/image/prevention/107.png',
						txt: '纬度',
						value: this.olddata.lat
					},
					{
						icon: '../../static/image/prevention/108.png',
						txt: '经度',
						value: this.olddata.lng
					}
				]
			},
			async history() { //设备列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
					data: {
						device_type_id: 2,
						device_id: this.eqinfo.item.device_id
					}
				})
				this.olddata = res.data[0].d_h_t
				console.log(this.olddata)
				this.modification()
			},
			clickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			sim(){//sim卡详情
				uni.navigateTo({
					url:"./sim?id="+this.eqinfo.item.d_id
				})
			},
			control(){//设备控制
				uni.navigateTo({
					url:"./control?id="+this.eqinfo.item.d_id 
				})
			},
			charts(){//历史数据
				uni.navigateTo({
					url:"./ucharts?d_id="+this.eqinfo.item.d_id+"&device_id="+this.eqinfo.item.device_id
				})
			}
		},
		onLoad(option) {
			this.$forceUpdate()
			this.eqinfo.item = JSON.parse(option.shebei)
			console.log(this.eqinfo)
			this.history()
		}
	}
</script>

<style lang="scss">
	.info {
		width: 100%;
		position: absolute;
		top: 44px;

		.info_item {
			width: 90%;
			margin: 0 auto;
			height: 260rpx;
			padding: 26rpx 50rpx;
			position: relative;

			.bgi {
				width: 100%;
				height: 260rpx;
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
			}

			p {
				font-size: 24rpx;
				color: #FFFFFF;
				margin-bottom: 10rpx;
			}
		}
	}

	.control {
		width: 90%;
		position: absolute;
		top: 372rpx;
		left: 5%;
		display: flex;
		justify-content: space-between;
		text-align: center;
		padding: 0 30rpx;

		.control_item {
			width: 120rpx;
			height: 120rpx;

			image {
				width: 70rpx;
				height: 70rpx;
			}

			p {
				font-size: 24rpx;
			}
		}
	}
	.realtime {
		width: 100%;
		position: absolute;
		top: 500rpx;
		.realtime_title{
			font-weight: 700;
			width: 90%;
			margin: 0 auto;
		}
		.realtime_text {
			width: 90%;
			margin: 0 auto;
	
			.realtime_text_item {
				width: 100%;
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				margin-bottom: 50rpx;
	
				.realtime_text_item_info {
					width: 48%;
					box-shadow: 0 0 10rpx #bcb9ca;
					margin-top: 20rpx;
					display: flex;
					padding: 20rpx 20rpx;
	
					.item_info_img {
						width: 30%;
						text-align: center;
						margin-right: 30rpx;
	
						image {
							width: 64rpx;
							height: 64rpx;
							margin-top: 10rpx;
						}
					}
	
					.item_info_text {
						font-size: 24rpx;
	
					}
				}
			}
		}
	
	}
</style>
