<template>
	<view>
		<!-- 公共参数 -->
		<view class="common">
			<view class="section">
				<view class="item" v-for="(item,index) in data.common.position" :key="index" @click="show_item(item)">
					<view class="label">{{item.label}}</view>
					<view class="value">{{item.value}}</view>
					<view class="unit">{{item.unit}}</view>
				</view>
			</view>
			<view class="section">
				<view class="state" v-for="(item,index) in data.common.direction" :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-else></view>
				</view>
			</view>
		</view>

		<!-- 提升机参数 -->
		<view class="content">
			<view class="hoist" v-for="(item,index) in data.hoist" :key="index">
				<view class="box" v-if="item.state == 1">
					<image src="./icon/hoist.jpg" mode=""></image>
				</view>
				<view class="box" v-else>
					<image src="./icon/hoist.png" mode=""></image>
				</view>
				<view class="name">{{item.name}}</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>
				<!-- 提升机运行模式 -->
				<view class="state_section run_mode">
					<view class="title">
						<view class="icon">
							<image src="./icon/warn.png" mode=""></image>
						</view>
						<view class="text">提升机运行模式</view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_2,index_2) in item.run_mode" :key="index_2"  @click="show_label(item_2.label)">
							<view class="label">{{item_2.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>
				</view>

				<!-- 提升机系统信号 -->
				<view class="state_section system_signal">
					<view class="title">
						<view class="icon">
							<image src="./icon/warn.png" mode=""></image>
						</view>
						<view class="text">提升机系统信号</view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_2,index_2) in item.system_signal" :key="index_2" @click="show_label(item_2.label)">
							<view class="label">{{item_2.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>
				</view>
				
				<!-- 提升机状态 -->
				<view class="state_section two_row_state">
					<view class="title">
						<view class="icon">
							<image src="./icon/warn.png" mode=""></image>
						</view>
						<view class="text">提升机状态</view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_2,index_2) in item.hoist_state" :key="index_2" @click="show_label(item_2.label)">
							<view class="label">{{item_2.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>
				</view>
				
				<!-- 提升机运行状态 -->
				<view class="state_section two_row_state">
					<view class="title">
						<view class="icon">
							<image src="./icon/warn.png" mode=""></image>
						</view>
						<view class="text">提升机运行状态</view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_2,index_2) in item.hoist_run_state" :key="index_2" @click="show_label(item_2.label)">
							<view class="label">{{item_2.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>
				</view>
				
				<!-- 小罐提升过程状态 -->
				<view class="state_section two_row_state">
					<view class="title">
						<view class="icon">
							<image src="./icon/warn.png" mode=""></image>
						</view>
						<view class="text">小罐提升过程状态</view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_2,index_2) in item.small_lifting_process" :key="index_2" @click="show_label(item_2.label)">
							<view class="label">{{item_2.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>
				</view>
				
				<!-- 大罐提升过程状态 -->
				<view class="state_section two_row_state">
					<view class="title">
						<view class="icon">
							<image src="./icon/warn.png" mode=""></image>
						</view>
						<view class="text">大罐提升过程状态</view>
					</view>
					<view class="list">
						<view class="state" v-for="(item_2,index_2) in item.big_lifting_process" :key="index_2" @click="show_label(item_2.label)">
							<view class="label">{{item_2.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>
				</view>

			</view>
		</view>

	</view>
</template>

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

	export default {
		data() {
			return {
				mine_code:"",
				system_type:"",
				
				// 数据刷新定时器
				data_timer:{},
				data: {}
			};
		},
		onLoad(option) {
			// console.log(data)
			// this.data = 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)
		},
		onUnload() {
			clearInterval(this.data_timer)
		},
		methods: {
			get_data(){
				this.$api.unified_automation_system({
					mine_code: this.mine_code,
					system_type: this.system_type
				}).then((res)=>{
					console.log(res.data)
					this.data = res.data
				})
			},
			show_item(item) {
				uni.showToast({
					icon: "none",
					title: item.label + "  " + item.value + "  " + item.unit
				})
			},
			show_label(label){
				uni.showToast({
					icon: "none",
					title: label
				})
			}
		}
	}
</script>

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

	.common {
		margin: 0 auto;
		width: 700rpx;

		background-image: url(./icon/common.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;

		box-sizing: border-box;
		padding: 40rpx;

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

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

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

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

				.label {
					width: 120rpx;

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

				.value {
					margin: 0 20rpx;
					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: 100rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}
			}

			.state {
				height: 60rpx;
				display: flex;
				align-items: center;

				.label {
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;

					width: 120rpx;
					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: #E5E5E5;
				}
			}
		}
	}

	.content {
		margin-top: 40rpx;

		.hoist {
			margin: 0 auto;
			width: 700rpx;

			.box {
				text-align: center;

				image {
					width: 150rpx;
					height: 174rpx;
				}
			}

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

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

					.item {
						height: 60rpx;
						display: flex;

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

						.label {
							width: 200rpx;
							text-align: justify;
							text-align-last: justify;

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

						.value {
							margin: 0 40rpx;
							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;
						}
					}
				}
			}

			.state_section {
				margin-top: 40rpx;

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

					width: 300rpx;
					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 {
					overflow: hidden;

					.state {
						box-sizing: border-box;

						float: left;
						margin-right: 20rpx;
						width: 160rpx;
						height: 70rpx;
						display: flex;
						align-items: center;

						.label {
							width: 80rpx;
							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;
						}
					}

					.state:nth-child(4n) {
						margin-right: 0;
					}
				}
			}

			.system_signal {
				.list {
					overflow: hidden;
					.state {
						margin-right: 30rpx;
						width: 210rpx;

						.label {
							width: 140rpx;
						}

					}
					.state:nth-child(3n){
						margin-right: 0;
					}
					.state:nth-child(4n) {
						margin-right: 30rpx;
					}
				}
			}
			
			.two_row_state{
				.list {
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					.state {
						margin-right: 0;
						width: 350rpx;

						.label {
							width: 200rpx;
							margin-right: 40rpx;
						}

					}
				}
			}
		}
	}
</style>
