<template>
	<view>
		<view v-for="(item,index) in data.cabinet" :key="index">
			<view class="title">
				<view class="icon">
					<image src="../icon/canshu.png" mode=""></image>
				</view>
				<view class="text">{{item.title}}</view>
			</view>
			<!-- 水泵 -->
			<view class="pump_list">
				<view class="pump" v-for="(item_2,index_2) in item.data" :key="index_2">
					<view class="icon" v-if="item_2.state == 1">
						<image src="../icon/water_pump_kai.jpg" mode=""></image>
					</view>
					<view class="icon" v-else>
						<image src="../icon/water_pump.png" mode=""></image>
					</view>
					<view class="name">{{item_2.name}}</view>
					<view class="state">
						<view class="label">状态</view>
						<!-- 1-开 2-关 -->
						<view class="value value_1" v-if="item_2.state == 1"></view>
						<view class="value value_2" v-else></view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_3,index_3) in item_2.state_list" :key="index_3">
							<view class="label">{{item_3.name}}</view>
							<!-- 1-开 2-关 -->
							<view class="value value_1" v-if="item_3.state == 1"></view>
							<view class="value value_2" v-else></view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 状态 -->
		<view class="state_list" v-if="data.state_list">
			<view class="title">
				<view class="icon">
					<image src="../icon/canshu.png" mode=""></image>
				</view>
				<view class="text">状态</view>
			</view>
			<view class="list">
				<view class="state" v-for="(item,index) in data.state_list" :key="index">
					<view class="label">{{item.label}}</view>
					<!-- 1-开 2-关 -->
					<view class="value value_1" v-if="item.state == 1"></view>
					<view class="value value_2" v-if="item.state == 2"></view>
				</view>
			</view>
		</view>
		
		<!-- 控制参数 -->
		<view class="parameter" v-if="data.parameter">
			<view class="title">
				<view class="icon">
					<image src="../icon/canshu.png" mode=""></image>
				</view>
				<view class="text">控制参数</view>
			</view>
			<view class="list">
				<view class="item" v-for="(item_2,index_2) in data.parameter" :key="index_2"
					@click="show_state(item_2)">
					<view class="label">{{item_2.label}}</view>
					<view class="value">{{item_2.state}}</view>
					<view class="unit">{{item_2.unit}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import data from "./life_water.json"
	
	export default {
		data() {
			return {
				mine_code: "",
				system_type: "",

				// 数据刷新定时器
				data_timer: {},
				data: null
			};
		},
		onLoad(option) {
			this.data = data
			console.log(this.data)
			uni.setNavigationBarTitle({
				title: option.name
			})
			this.mine_code = option.mine_code
			this.system_type = option.system_type

			// this.get_data()
			// this.data_timer = setInterval(() => {
			// 	this.get_data()
			// }, 5000)
		},
		methods: {
			show_item(item) {
				uni.showToast({
					icon: "none",
					title: item.label + "  " + item.value + "  " + item.unit
				})
			},
			get_data() {
				this.$api.unified_automation_system({
					mine_code: 'renjiazhuang',
					system_type: this.system_type
				}).then((res) => {
					console.log(res)
					this.data = res.data
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #0B163B;
		box-sizing: border-box;
		padding: 30rpx 10rpx;
	}

	.title {
		margin: 0 auto;
		margin-bottom: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		width: 290rpx;
		height: 60rpx;
		background-image: url(../icon/border.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;

		.icon {
			margin-right: 10rpx;

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

		.text {
			color: #00FFF6;
			font-size: 30rpx;
		}
	}


	.pump_list {
		margin-top: 20rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.pump {
			margin-bottom: 40rpx;
			width: 360rpx;
			
			.icon {
				text-align: center;

				image {
					width: 164rpx;
					height: 138rpx;
				}
			}

			.name {
				margin-top: 20rpx;
				text-align: center;
				color: #DEF1FF;
				font-size: 34rpx;
				font-weight: 700;
			}

			.state {
				margin-top: 10rpx;
				height: 60rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.label {
					color: #4CB1FF;
					font-size: 28rpx;
				}

				.value {
					margin-left: 20rpx;
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
				}

				.value_1 {
					background-color: #00FF00;
				}

				.value_2 {
					background-color: #DCDCDC;
				}
			}
			
			.list{
				overflow: hidden;
				.state{
					box-sizing: border-box;
					
					float: left;
					width: 350rpx;
					height: 70rpx;
					display: flex;
					align-items: center;
					.label {
						width: 160rpx;
						color: #4CB1FF;
						font-size: 28rpx;
						
						text-overflow: ellipsis;
						white-space: nowrap;
						overflow: hidden;
					}
								
					.value {
						margin-left: 20rpx;
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
					}
								
					.value_1 {
						background-color: #00FF00;
					}
								
					.value_2 {
						background-color: #DCDCDC;
					}
				}
			}

		}

		.pump:nth-child(Odd) {
			border-right: 2rpx solid;
			border-image: linear-gradient(#0B163B, #00B7F5, #0B163B) 10;
		}
	}
	
	.state_list{
		margin-top: 40rpx;
		.title {
			margin: 20rpx auto;
			display: flex;
			justify-content: center;
			align-items: center;
					
			width: 230rpx;
			height: 60rpx;
			background-image: url(../icon/border.png);
			background-size: 100% 100%;
			background-repeat: no-repeat;
					
			.icon {
				margin-right: 20rpx;
					
				image {
					width: 30rpx;
					height: 30rpx;
				}
			}
					
			.text {
				color: #00FFF6;
				font-size: 30rpx;
			}
		}
					
		.list{
			margin: 0 auto;
			width: 700rpx;
			overflow: hidden;
			
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			.state{
				box-sizing: border-box;
				width: 350rpx;
				height: 70rpx;
				display: flex;
				align-items: center;
				.label {
					width: 240rpx;
					color: #4CB1FF;
					font-size: 28rpx;
					text-align: justify;
					text-align-last: justify;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}
							
				.value {
					margin-left: 20rpx;
					width: 40rpx;
					height: 40rpx;
					border-radius: 50%;
				}
							
				.value_1 {
					background-color: #00FF00;
				}
							
				.value_2 {
					background-color: #DCDCDC;
				}
			}
		}
	}
	
	.parameter {
		box-sizing: border-box;
		margin-top: 40rpx;
	
		.title {
			margin: 0 auto;
			display: flex;
			justify-content: center;
			align-items: center;
	
			width: 230rpx;
			height: 60rpx;
			background-image: url(../icon/border.png);
			background-size: 100% 100%;
			background-repeat: no-repeat;
	
			.icon {
				margin-right: 20rpx;
	
				image {
					width: 30rpx;
					height: 30rpx;
				}
			}
	
			.text {
				color: #00FFF6;
				font-size: 30rpx;
			}
		}
	
		.list {
			margin-left: 20rpx;
			margin-top: 40rpx;
	
			.item {
				height: 60rpx;
				display: flex;
	
				color: #4CB1FF;
				font-size: 28rpx;
	
				.label {
					width: 200rpx;
	
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}
	
				.value {
					margin: 0 20rpx;
					width: 200rpx;
					height: 40rpx;
					box-sizing: border-box;
					padding: 0 10rpx;
					background: rgba(0, 4, 15, 0.36);
					border: 2rpx solid #3D55A5;
	
					color: #FFF600;
					font-size: 24rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}
	
				.unit {
					width: 100rpx;
				}
			}
		}
	}
	
</style>
