<template>
	<!-- 精编机 -->
	<view class="equipmentDtl">
		<commons-header :title="$t('warpKnitting.name')"></commons-header>
		<view class="equ-img">
			<image src="../../static/img_jbj.png" mode=""></image>
			<!-- <view class="err-modal">
				<image src="../../static/icon_jb@2x.png" mode=""></image>
			</view> -->
		</view>
		<view class="state">
			<view class="state-box">
				<image src="../../static/jinbian/icon_sbzt.png" mode=""></image>
				<view class="text">
					<view class="label">
						设备状态
					</view>
					<view class="state-text" style="color: #3FBF31;">
						{{swichType ? '在线' : '离线'}} 
					</view>
				</view>
			</view>
			<view class="state-box">
				<image src="../../static/jinbian/icon_gzms.png" mode=""></image>
				<view class="text">
					<view class="label">
						主轴转速 
					</view>
					<view class="state-text">
						{{equData.properties.status.main_speed / 2}} RPM
					</view>
				</view>
			</view>
			
		</view>
		<ul class="action">
			<li>
				<image src="../../static/jinbian/icon_ebc2.png" mode=""></image>
				<p>EBC</p>
				<view class="state-text">{{swichType ? '在线' : '离线'}}</view>
			</li>
			<li>
				<image src="../../static/jinbian/icon_jk2.png" mode=""></image>
				<p>贾卡</p>
				<view class="state-text">离线</view>
			</li>
			<li>
				<image src="../../static/jinbian/icon_hy.png" mode=""></image>
				<p>横移</p>
				<view class="state-text">离线</view>
			</li>
		</ul>
		<view class="echarts">
			<view class="title">
				<image src="../../static/jinbian/btn_kanban_blue.png" mode=""></image>
				<span>产量数据</span>
			</view>
			<view class="content">
				<view class="text">
					12小时产量
				</view>
				<qiun-data-charts type="line" :opts="opts" :chartData="chartData" />
			</view>
		</view>
		<view class="ebc-content">
			<view class="commons-title">
				EBC
			</view>
			<view class="list-bc">
				<view class="bc-box">
					<image src="../../static/jinbian/icon_currentl.png" mode=""></image>
					<view class="text">
						<view class="list-label">当前布长</view>
						<view class="list-val">
							{{equData.properties.status.bu_len / 100}} M
						</view>
					</view>
				</view>
				<view class="bc-box">
					<image src="../../static/jinbian/icon_currentl.png" mode=""></image>
					<view class="text">
						<view class="list-label">设定布长</view>
						<view class="list-val">
							{{equData.properties.parameter.max_bulen}} M
						</view>
					</view>
				</view>
			</view>
			<view class="list-long">
				<view class="" style="display: flex;">
					<image src="../../static/jinbian/icon_density.png" mode=""></image>
					<view class="list-label" style="line-height: 80rpx;">密度</view>
				</view>
				<view class="list-val"  style="line-height: 80rpx;">
					{{equData.properties.parameter.bumi}} Row/cm
				</view>
			</view>
			<view class="list-long" v-for="i in axisData">
				<view class="" style="display: flex;">
					<image src="../../static/jinbian/icon_xlj.png" mode=""></image>
					<view class="list-label" style="line-height: 80rpx;font-size: 28rpx;font-weight: bold;">送经轴{{i.index}}</view>
				</view>
				<view class="list-val"  style="line-height: 40rpx;color: #666666;font-size: 24rpx;">
					<!-- {{i.axis - i.curr}} -->
					<p>剩余圈数：{{i.curr}} N</p>
					<p>剩余时间：{{i.time}} H</p>
				</view>
			</view>
			<view class="list-bc mt-24">
				<view class="bc-box">
					<image src="../../static/jinbian/icon_drawoff.png" mode=""></image>
					<view class="text" style="line-height: 80rpx;">
						牵拉
					</view>
				</view>
				<view class="bc-box">
					<image src="../../static/jinbian/icon_batching.png" mode=""></image>
					<view class="text" style="line-height: 80rpx;">
						卷曲
					</view>
				</view>
			</view>
		</view>
		<view class="ebc-content">
			<view class="commons-title">
				贾卡
			</view>
			<view class="list-bc">
				<view class="bc-box">
					<image src="../../static/jinbian/icon_currentl.png" mode=""></image>
					<view class="text">
						<view class="list-label">工艺宽度</view>
						<view class="list-val">
							0
						</view>
					</view>
				</view>
				<view class="bc-box">
					<image src="../../static/jinbian/icon_currentl.png" mode=""></image>
					<view class="text">
						<view class="list-label">工艺高度</view>
						<view class="list-val">
							0
						</view>
					</view>
				</view>
			</view>
			
		</view>
		<view class="ebc-content">
			<view class="commons-title">
				横移
			</view>
			<view class="list-long">
				<view class="" style="display: flex;">
					<image src="../../static/jinbian/icon_density.png" mode=""></image>
					<view class="list-label" style="line-height: 80rpx;">总轴数</view>
				</view>
				<view class="list-val"  style="line-height: 80rpx;">
					0
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {
		getInfo
	} from "@/util/api.js";
	import Vue from 'vue'
	import commonsHeader from '../../components/commons-header/index.vue'
	export default {
		components: {
			commonsHeader
		},
		data() {
			return {
				userInfoData: [],
				notificationData: [],
				opts: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 10, 0, 15],
					legend: {},
					xAxis: {
						disableGrid: true
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2
					},
					extra: {
						line: {
							type: "curve",
							width: 2
						}
					}
				},
				chartData: {
					categories: ["2016", "2017", "2018", "2019", "2020", "2021"],
					series: [{
							name: "极限产量",
							data: [0,0,0,0,0,0,0,0]
						},
						{
							name: "实际产量", 
							data: [0, 0, 0, 0, 0, 0]
						},
						
					]
				},
				equData:{
					properties:{
						status:{
							main_speed:0,
							bu_len:0,
						},
						parameter:{
							max_bulen:0,
						},
					},
					
				},
				axisData:[],
				swichType:false,
			}
		},
		onLoad(option) {
			const v = this
			v.getData(option.id)
		},
		methods: {
			getData(_id){
				const v = this
				
				v.$post('/api/syringe-production/factoryProduct/getData',{equipmentNo:_id}).then(res => {
					console.log(res.data)
					this.axisData = []
					
					for (let key in res.data.properties.parameter) {
						if(key.substring(0,11) === 'axis_allnum'){
							this.axisData.push({
								axis:res.data.properties.parameter[key],
								index:key.substring(12,13),
								curr:res.data.properties.status['curr_num_' + key.substring(12,13)] || 0,
								time:res.data.properties.status['left_time_' + key.substring(12,13)] || 0,
							})
						}
					}
					function up(x,y){
						return x.index -y.index;
					} 
					this.axisData.sort(up)
					v.equData = res.data
					const time1 = new Date(res.data.eventTime).getTime()
					const time2 = new Date().getTime()
					if(time1 + 600000 > time2){
						this.swichType = true
					}else{
						this.swichType = false
					}
					console.log(time1,time2)
				})
				setTimeout(()=>{
					if(v.equData) v.getData(_id)
				},5000)
			},
			toRouter(j) {
				console.log(j)
				uni.navigateTo({
					url: '/pages/' + j.menuKey + '/' + j.menuKey
				})
			},
		},
	}
</script>

<style lang="less">
	.equipmentDtl {
		background-color: #f0f0f0;
		min-height: 100vh;
		margin-top: 128rpx;
		.ebc-content{
			background-color: #fff;
			margin: 24rpx 24rpx;
			border-radius: 10rpx;
			padding-bottom: 24rpx;
			.list-long{
				height: 112rpx;
				margin: 24rpx 24rpx 0;
				display: flex;
				justify-content: space-between;
				background-color: #F1F1F1;
				padding: 18rpx 24rpx;
				box-sizing: border-box; 
				border-radius: 10rpx;
				font-size: 24rpx;
				.list-val{
					font-size: 32rpx;
					font-weight: bold;
				}
				image{
					width: 80rpx;
					height: 80rpx;
					margin-right: 24rpx;
				}
			}
			.list-bc{
				display: flex;
				justify-content: space-between;
				padding: 0 24rpx;
				.bc-box{
					height: 112rpx;
					width: 48%;
					display: flex;
					background-color: #F1F1F1;
					padding: 18rpx 24rpx;
					box-sizing: border-box; 
					border-radius: 10rpx;
					font-size: 24rpx;
					.list-val{
						font-size: 32rpx;
						font-weight: bold;
					}
					image{
						width: 80rpx;
						height: 80rpx;
						margin-right: 24rpx;
					}
				}
			}
		}
		.action{
			display: flex;
			justify-content: space-between;
			margin: 24rpx 24rpx 0;
			
			li{
				width: 32%;
				text-align: center;
				background-color: #fff;
				font-size: 28rpx;
				border-radius: 10rpx;
				padding: 24rpx 0;
				image{
					width: 100rpx;
					height: 100rpx;
				}
				.state-text{
					text-align: center;
				}
			}
		}
		.rate-warp{ 
			margin-top: 20rpx;
			.sm-rate{
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				padding: 0 24rpx;
				li{
					
					background-color: #fff;
					border-radius: 10rpx;
					height: 120rpx;
					display: flex;
					justify-content: space-between;
					margin-top: 24rpx;
					align-items: center;
					padding: 0 24rpx;
					width: 296rpx;
					font-size: 28rpx;
					color: #666;
					.right-box{
						font-size: 32rpx;
						color: #333;
						.line{
							width: 70rpx;
							height: 8rpx;
							background: rgba(238,238,238,1);
							border-radius: 4rpx;
							margin-top: 6rpx;
							.box{
								width:50%;
								background-color: #BB99F6;
								height: 100%;
								border-radius: 12rpx;
							}
						}
					}
				}
			}
			.big-rate{
				li{
					margin-top: 24rpx;
					height: 128rpx;
					display: flex;
					align-items: center;
					background-color: #fff;
					margin: 0 24rpx;
					border-radius: 10rpx;
					padding: 0 24rpx;
					
					.text{
						font-weight: 500;
						font-size: 28rpx;
						color: #333;
					}
					.line{
						width: 240rpx;
						margin-left: 90rpx;
						height: 24rpx;
						background: rgba(238,238,238,1);
						margin-right: 40rpx;
						border-radius: 12rpx;
						
						.box{
							width:50%;
							background-color: rgba(255,175,83,1);
							height: 100%;
							border-radius: 12rpx;
						}
					}
				}
			}
			
		}
		.parts-list{
			padding: 0 24rpx;
			margin-top: 24rpx;
			ul{
				display: flex;
				justify-content: space-between;
			}
			li{
				width: 32%;
				padding: 30rpx 0;
				text-align: center;
				position: relative;
				background-color: #fff;
				image{
					width: 60rpx;
					height: 60rpx;
					display: block;
					margin: 0 auto 20rpx;
				}
			}
			.before{
				width: 30rpx;
				height: 30rpx;
				border-radius: 50%;
				background-color: rgba(204,204,204,0.2);
				
				display: block;
				position: absolute;
				right: 16rpx;
				top: 16rpx;
				
			}
			.before::before{
				position: absolute;
				display: block;
				top: 7rpx;
				left: 7rpx;
				width: 19rpx; 
				height: 19rpx;
				border-radius: 50%;
				content:" ";
				background: #cccccc;
				
			}
			.before.succes{
				background-color: rgba(63,191,49,0.2);
			}
			.before.succes::before{
				background: #3FBF31;
			}
		}
		.echarts {
			background: #fff;
			margin: 24rpx 24rpx 0;
			.content{
				
				.text{
					font-size: 28rpx;
					font-weight: 700;
					color: #333;
					text-align: center;
					margin-bottom: 40rpx;
				}
			}
			.title{
				font-size: 28rpx;
				height: 90rpx;
				line-height: 90rpx;
				display: flex;
				padding: 0 24rpx;
				font-weight: 500;
				image{
					width: 40rpx;
					height: 40rpx;
					margin-top: 25rpx;
					margin-right: 16rpx;
				}
			}
		}

		.parts-list {}

		.equ-img {
			padding: 24rpx;
			background-color: #ffffff;
			position: relative;
			image {
				width: 100%;
				height: 395rpx;
			}
			.err-modal{
				position: absolute;
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				background: rgba(0,0,0,0.60);
				text-align: center;
				display: flex;
				align-items: center;
				
				image{
					width: 160rpx;
					height: 160rpx;
					margin: 0 auto;
				}
			}
		}

		.state {
			display: flex;
			justify-content: space-between;
			margin: 24rpx 24rpx 0;

			.state-box {
				padding: 20rpx;
				width: 48%;
				background-color: #fff;
				display: flex;
				box-sizing: border-box;
				border-radius: 10rpx;
				.text{
					padding: 12rpx 0;
				}
				.state-text{
					font-size: 32rpx;
					font-weight: bold;
					margin-top: 5rpx;
				}
				.label{
					font-weight: 400;
					font-size: 28rpx;
				}
				image {
					width: 110rpx;
					height: 110rpx;
				}
			}
		}
	}
</style>
