<template>
	<view>
		<view class="status_bar"></view>
		<view class="" style="position: relative;top: 44px;">
			<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.is_online==1?'../../static/image/cb/onBg.png':'../../static/image/cb/offBg.png'" mode=""
					 class="bgi"></image>
					<p style="font-size: 32rpx;">设备 ID：{{eqinfo.item.equip_id}}</p>
					<p>设备名称：{{eqinfo.item.equip_name?eqinfo.item.equip_name:"无"}}</p>
					<p>最近上报时间：{{eqinfo.item.uptime|timeFormat()}}</p>
					<p>地址：{{city==""?"--":city}}</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="information">
					<image src="../../static/image/environment/9.png" mode=""></image>
					<p>24小时数据</p>
				</view>
				<view class="control_item" @click="charts">
					<image src="../../static/image/environment/10.png" mode=""></image>
					<p>历史数据</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 olddata.conf" :key="index" v-if="item">
							<view class="item_info_img" :style="{'background-color':olddatas[Math.floor(Math.random()*(5-0+1))]}">
								<image :src="'../../static/image/environment/icon_'+olddata.dat[index][1]+'.png'" mode=""></image>
							</view>
							<view class="item_info_text">
								<p>{{item}}</p>
								<p style="margin-top: 20rpx;">{{parseFloat(olddata.dat[index][0]) == -99.99 ?'N/A':parseFloat(olddata.dat[index])}}</p>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				eqinfo: {},
				olddata: {},
				olddatas: ["#fba825", "#53d67c", "#008cf2", "#fb504d", "#d87ffc", "#4ec5f0"],
				city: ""
			}
		},
		methods: {
			clickLeft() {
				uni.navigateBack({
					delta: 1
				})
			},
			async history() { //设备列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=weather.weather.qxz_status',
					data: {
						device_id: this.eqinfo.item.equip_id
					}
				})
				this.olddata = res
				for (var key in this.olddata.conf) {
					if (this.olddata.conf[key].indexOf("#") != -1) {
						this.olddata.conf[key] = this.olddata.conf[key].replace("#", "(") + ")"
					}
					this.olddata.dat[key] = this.olddata.dat[key].split("#")
				}
				console.log(this.olddata)
			},
			control() { //设备控制
				uni.navigateTo({
					url: "./contros?id=" + this.eqinfo.item.d_id
				})
			},
			information() { //24小时数据
				uni.navigateTo({
					url: "./onedaythedata?id=" + this.eqinfo.item.equip_id
				})
			},
			charts() { //历史数据
				uni.navigateTo({
					url: "./history?device_id=" + this.eqinfo.item.equip_id
				})
			},
			reverseGeocode(Object,callback){
				
			}
		},
		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;
			box-sizing: border-box;
			.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;
		box-sizing: border-box;

		.control_item {
			width: 128rpx;
			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 0rpx 20rpx 20rpx;
					box-sizing: border-box;

					.item_info_img {
						width: 90rpx;
						text-align: center;
						margin-right: 28rpx;
						border-radius: 50%;
						height: 90rpx;
						image {
							width: 64rpx;
							height: 64rpx;
							margin-top: 15rpx
						}
					}

					.item_info_text {
						font-size: 24rpx;
					}
				}
			}
		}

	}
</style>
