<template>
	<view>
		<view class="content">
			<view class="section" v-for="(item,index) in data" :key="index">
				<!-- 风扇状态 -->
				<view class="state">
					<view class="icon">
						<view class="img kai" v-if="item.state == 1">
							<image src="./icon/fengshan_kai.gif"></image>
						</view>
						<view class="img guan" v-if="item.state == 2">
							<image src="./icon/fengshan_guan.png"></image>
						</view>
						<view class="title">{{item.title}}</view>
					</view>
					<view class="list">
						<view class="item" v-for="(item_2,index_2) in item.state_list" :key="index_2">
							<view class="label">{{item_2.label}}</view>
							<!-- 1-开 2-关 3-报警 -->
							<view class="value value_1" v-if="item_2.state == 1"></view>
							<view class="value value_2" v-if="item_2.state == 2"></view>
							<view class="value value_3" v-if="item_2.state == 3"></view>
						</view>
					</view>
				</view>
				<!-- 运行参数 -->
				<view class="parameter run_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 item.run_parameter" :key="index_2"
							@click="show_item(item_2)">
							<view class="label">{{item_2.label}}</view>
							<view class="value">{{item_2.value}}</view>
							<view class="unit">{{item_2.unit}}</view>
						</view>
					</view>
				</view>
				<!-- 电机1运行参数 -->
				<view class="parameter electric_parameter">
					<view class="title">
						<view class="icon">
							<image src="./icon/dianji.png" mode=""></image>
						</view>
						<view class="text">电机1运行参数</view>
					</view>
					<view class="list">
						<view class="item" v-for="(item_2,index_2) in item.electric_parameter_1" :key="index_2"
							@click="show_item(item_2)">
							<view class="label">{{item_2.label}}</view>
							<view class="value">{{item_2.value}}</view>
							<view class="unit">{{item_2.unit}}</view>
						</view>
					</view>
				</view>
				<!-- 电机2运行参数 -->
				<view class="parameter electric_parameter">
					<view class="title">
						<view class="icon">
							<image src="./icon/dianji.png" mode=""></image>
						</view>
						<view class="text">电机2运行参数</view>
					</view>
					<view class="list">
						<view class="item" v-for="(item_2,index_2) in item.electric_parameter_2" :key="index_2"
							@click="show_item(item_2)">
							<view class="label">{{item_2.label}}</view>
							<view class="value">{{item_2.value}}</view>
							<view class="unit">{{item_2.unit}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import data from './ventilation.json'

	export default {
		data() {
			return {
				mine_code:"",
				system_type:"",
				
				// 数据刷新定时器
				data_timer:{},
				data: {}
			};
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title:option.name
			})
			this.mine_code = option.mine_code
			this.system_type = option.system_type
			// console.log(data)
			// this.data = data
			this.get_data()
			this.data_timer = setInterval(()=>{
				this.get_data()
			},5000)
			
		},
		onUnload() {
			clearInterval(this.data_timer)
		},
		methods: {
			show_item(item) {
				uni.showToast({
					icon: "none",
					title: item.label + "  " + item.value + "  " + item.unit
				})
			},
			
			get_data(){
				if(this.mine_code == "jinfeng"){
					this.$api.opcdata_getTurboData({
						mine_code: this.mine_code,
						system_type: this.system_type
					}).then((res)=>{
						this.data = res.data.sys_point
					})
				}else{
					this.$api.unified_automation_system({
						mine_code: this.mine_code,
						system_type: this.system_type
					}).then((res)=>{
						this.data = res.data
					})
				}
			}
		}
	}
</script>

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

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

		.section {
			width: 360rpx;

			.state {
				.icon {
					background-image: url(./icon/fengshan_border.png);
					background-size: 160rpx 160rpx;
					background-repeat: no-repeat;
					background-position: center 0;

					.img {
						margin: 0 auto;
						width: 140rpx;
						height: 140rpx;

						image {
							margin-top: 10rpx;
							width: 140rpx;
							height: 140rpx;
						}
					}

					.guan {
						text-align: center;

						image {
							margin-top: 24rpx;
							width: 106rpx;
							height: 106rpx;
						}
					}

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

				.list {
					margin-top: 30rpx;
					padding: 10rpx 0;

					.item {
						height: 60rpx;
						display: flex;
						align-items: center;
						justify-content: center;

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

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

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

						.value_2 {
							background-color: #DCDCDC;
						}

						.value_3 {
							background-color: #FF0000;
						}
					}
				}
			}

			.parameter {
				box-sizing: border-box;
				margin-top: 50rpx;

				.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: 10rpx;

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

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

				.list {
					margin-top: 40rpx;

					.item {
						height: 60rpx;
						display: flex;
						justify-content: space-between;

						color: #4CB1FF;
						font-size: 28rpx;

						.label {
							margin-left: 10rpx;
							width: 130rpx;

							text-overflow: ellipsis;
							white-space: nowrap;
							overflow: hidden;
						}

						.value {
							width: 120rpx;
							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: 70rpx;
						}
					}
				}
			}

			.electric_parameter {
				.title {
					width: 290rpx;
				}

				.list {
					.item {
						.label {
							width: 130rpx;
						}

						.unit {
							width: 70rpx;
						}
					}
				}
			}
		}

		.section:first-child {
			.state {
				.icon {
					border-right: 2rpx solid;
					border-image: linear-gradient(#0B163B, #00B7F5, #0B163B) 10;
				}

				.list {
					border-right: 2rpx solid;
					border-image: linear-gradient(#0B163B, #00B7F5, #0B163B) 10;
				}
			}

			.parameter {
				.list {
					border-right: 2rpx solid;
					border-image: linear-gradient(#0B163B, #00B7F5, #0B163B) 10;
				}
			}
		}


	}
</style>
