<template>
	<view class="stack-warp">

		<view class="all-con-item-box" style="margin-top: 0!important;">
			<Section title="排气/回风温度" />
			<view class="chart-box">
					<zero-loading v-if="chartLoading" position="absolute"></zero-loading>
				<charts :id="'pcsChart'" :options="curve_option"></charts>

			</view>
		</view>

		<view class="all-con-item-box">
			<Section title="运行数据" />
			<zero-loading v-if="runLoading" position="absolute"></zero-loading>
			<view class="group-box ">
				<view class="group-item "
					@click="showHistory('空调设定温度', 'airconditionSetTemperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionSetTemperature | isNull}}

						</view>
						<view class="item-title">空调设定温度(℃)</view>
					</view>
				</view>

				<view class="group-item "
					@click="showHistory('空调当前回风温度', 'airconditionAirTemperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionAirTemperature | isNull}}

						</view>
						<view class="item-title">空调当前回风温度(℃)</view>
					</view>
				</view>

				<view class="group-item "
					@click="showHistory('空调当前回风湿度', 'airconditionAirHumidity', 'air_condition','%','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionAirHumidity | isNull}}

						</view>
						<view class="item-title">空调当前回风湿度(%)</view>
					</view>
				</view>

				<view class="group-item "
					@click="showHistory('空调设定湿度', 'airconditionSetHumidity', 'air_condition','%','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionSetHumidity | isNull}}

						</view>
						<view class="item-title">空调设定湿度(%)</view>
					</view>
				</view>

				<view class="group-item"
					@click="showHistory('空调内盘1温度', 'airconditionInner1Temperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionInner1Temperature | isNull}}

						</view>
						<view class="item-title">空调内盘1温度(℃)</view>
					</view>
				</view>

				<view class="group-item"
					@click="showHistory('空调内盘2温度', 'airconditionInner2Temperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionInner2Temperature | isNull}}

						</view>
						<view class="item-title">空调内盘2温度(℃)</view>
					</view>
				</view>

				<view class="group-item "
					@click="showHistory('空调回气温度', 'airconditionInnerGasTemperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionInnerGasTemperature | isNull}}

						</view>
						<view class="item-title">空调回气温度(℃)</view>
					</view>
				</view>

				<view class="group-item t"
					@click="showHistory('空调外盘温度', 'airconditionOuterTemperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionOuterTemperature | isNull}}

						</view>
						<view class="item-title">空调外盘温度(℃)</view>
					</view>
				</view>

				<view class="group-item "
					@click="showHistory('空调排气温度', 'airconditionOuterGasTemperature', 'air_condition','℃','')">
					 <view class="history-icon">
        	 <image src="/static/aidex/images/history-icon.png"></image>
        </view>
					<view class="item-icon">
						<image src="/static/aidex/images/rcdl.png"></image>
					</view>
					<view class="item-con">
						<view class="item-num">{{panelData.airconditionOuterGasTemperature | isNull}}

						</view>
						<view class="item-title">空调排气温度(℃)</view>
					</view>
				</view>
			</view>



		</view>
		<historyModal :is-show.sync="histroyShow" :title="chartTitle" :params="hisParams" />
	</view>
</template>

<script>
	import Section from '@/components/section/index.vue'
	import charts from "@/components/charts/index";
	import historyModal from '@/components/history-modal/index.vue'
	export default {
		data() {
			return {
				curve_option: {},
				stationId: null,
				panelData: {},
				deviceType: 'air_condition',
				histroyShow: false,
				chartTitle: null,
				hisParams: {},
				chartLoading:false,
				runLoading:false
				
			}
		},
		components: {
			Section,
			charts,
			historyModal
		},
		computed: {
			currentStation() {
				return this.vuex_currentStation
			}
		},
		watch: {
			currentStation: {
				handler(val) {
					this.stationId = val.id;

				},
				deep: true,
				immediate: true
			},
		},
		methods: {

			getData(srcId) {
				this.loading = true
				this.srcId = srcId
				const api = [
					this.getSocChart(),
					this.getTotalData()
				]
				Promise.all(api).then(result => {
					this.err = result
					this.loading = false
				})

			},
			getTotalData() {
				this.runLoading = true
				const self = this
				return new Promise((resolve, reject) => {
					self.$u.api.deviceList
						.GetNewValue({
							colList: [
								'airconditionSetTemperature', 'airconditionAirTemperature',
								'airconditionAirHumidity',
								'airconditionSetHumidity', 'airconditionInner1Temperature',
								'airconditionInner2Temperature',
								'airconditionInnerGasTemperature', 'airconditionOuterTemperature',
								'airconditionOuterGasTemperature'
							],
							stationId: this.stationId,
							srcId: this.srcId
						})
						.then((res) => {
							this.panelData = {
								airconditionSetTemperature: res.data.airconditionSetTemperature?.value,
								airconditionAirTemperature: res.data.airconditionAirTemperature?.value,
								airconditionAirHumidity: res.data.airconditionAirHumidity?.value,
								airconditionSetHumidity: res.data.airconditionSetHumidity?.value,
								airconditionInner1Temperature: res.data.airconditionInner1Temperature
									?.value,
								airconditionInner2Temperature: res.data.airconditionInner2Temperature
									?.value,
								airconditionInnerGasTemperature: res.data.airconditionInnerGasTemperature
									?.value,
								airconditionOuterTemperature: res.data.airconditionOuterTemperature?.value,
								airconditionOuterGasTemperature: res.data.airconditionOuterGasTemperature
									?.value
							}
							resolve(res);
						})
						.finally((err) => {
							this.runLoading = false
						})
				});
			},


			showHistory(name, modelCol, modelType, unit) {
				this.hisParams = {
					modelCol: modelCol,
					modelType: modelType,
					unit: unit,
					srcId:this.srcId
				}
				this.chartTitle = name
				this.histroyShow = true
			},


			getSocChart() {
				this.chartLoading = true
				const self = this
				return new Promise((resolve, reject) => {
					self.$u.api.homePageData
						.GetSocCurve({
							colName: ["airconditionOuterGasTemperature", "airconditionAirTemperature"],
							stationId: this.stationId,
							type: 'day',
							srcId: this.srcId
						})
						.then((res) => {
							self.initChargeChart(res.data);
							resolve(res);
						})
						.finally(() => {
							this.chartLoading = false
						})
				});
			},
			initChargeChart(val) {
				const gonglv = []
				const soc = []
				const xAxis = []
				val[0].staticCurveList.forEach(v => {
					xAxis.push(v.date)
					gonglv.push(v.digital)
				})
				val[1].staticCurveList.forEach(v => {
					soc.push(v.digital)
				})
				this.curve_option = {
					animationDuration: 500,
					animationEasing: "cubicInOut",
					tooltip: {
						trigger: "axis",
						textStyle: {
							textShadowBlur: 10, // 重点
							textShadowColor: 'transparent', // 重点
						},
						axisPointer: {},
						confine: true,
						position: function(point, params, dom, rect, size) {
							// 鼠标坐标和提示框位置的参考坐标系是：以外层div的左上角那一点为原点，x轴向右，y轴向下
							// 提示框位置
							var x = 0; // x坐标位置
							var y = 0; // y坐标位置

							// 当前鼠标位置
							var pointX = point[0];
							var pointY = point[1];

							// 外层div大小
							// var viewWidth = size.viewSize[0];
							// var viewHeight = size.viewSize[1];

							// 提示框大小
							var boxWidth = size.contentSize[0];
							var boxHeight = size.contentSize[1];

							// boxWidth > pointX 说明鼠标左边放不下提示框
							if (boxWidth > pointX) {
								x = 5; // 自己定个x坐标值，以防出屏
								y -= 15; // 防止点被覆盖住，可根据情况自行调节
							} else {
								// 左边放的下
								x = pointX - boxWidth - 15;
							}

							// boxHeight > pointY 说明鼠标上边放不下提示框
							if (boxHeight + 20 > pointY) {
								y = pointY + 15;
							} else if (boxHeight > pointY) {
								y = 5;
							} else {
								// 上边放得下
								y += pointY - boxHeight;
							}
							return [x, y];
						},
					},
					color: ['#009C77', '#BFE49F'],
					grid: {
						top: '15%',
						left: '10%',
						right: '3%',
						bottom: '5%',
						containLabel: true
					},
					xAxis: {
						type: 'category',
						data: xAxis,
						splitLine: {
							show: false
						},
						axisLabel: {
							show: true,
							color: "#A3A3A3",
							formatter: function(params) {
								let newParamsName = '';
								const paramsNameNumber = params.length; // 文字总长度
								const provideNumber = 11; //一行显示几个字
								const rowNumber = Math.ceil(paramsNameNumber / provideNumber);
								if (paramsNameNumber > provideNumber) {
									for (let p = 0; p < rowNumber; p++) {
										const start = p * provideNumber;
										const end = start + provideNumber;
										const tempStr = p === rowNumber - 1 ? params.substring(start,
											paramsNameNumber) : params.substring(start, end) + '\n';
										newParamsName += tempStr;
									}
								} else {
									newParamsName = params;
								}
								return newParamsName;
							},
						},

					},
					yAxis: [{
						type: 'value',
						name: '温度(℃)',
						axisLabel: {
							color: '#A3A3A3'
						},
						nameTextStyle: {
							color: '#A3A3A3'
						}
					}],
					dataZoom: [{
							type: 'inside',
							start: 0,
							end: 100
						},
						{
							start: 0,
							height: 20,
							bottom: 10,
							end: 100
						}
					],
					series: [{
							name: '空调排气温度',
							type: 'line',
							smooth: true,
							symbol: 'none',
							areaStyle: {
								opacity: 0
							},
							data: gonglv
						},
						{
							name: '空调当前回风温度',
							type: 'line',
							smooth: true,
							symbol: 'none',
							areaStyle: {
								opacity: 0
							},
							data: soc
						}

					]
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.stack-warp {
		background-color: #f5f5f5;


		.all-con-item-box {
			background: #ffffff;
			border-radius: 16rpx;
			padding: 30rpx;
			width: 710rpx;
			border: 16rpx;
			position: relative;
			margin-top: 30rpx;
			box-shadow: 0px 4rpx 16rpx rgba(0, 0, 0, 0.08);

			.top-right-box {
				display: flex;
				flex-direction: row;
				align-items: center;
				flex: 1;
				justify-content: flex-end;

				.top-right-item {
					padding: 5rpx 10rpx;
					border: 1rpx solid #4c9ee6;
					font-size: 24rpx;
					color: #4c9ee6;
					cursor: pointer;
					margin-right: 10rpx;
					border-radius: 8rpx;

					&.active {
						background: #4c9ee6;
						color: #ffffff;
					}
				}
			}

			.ring-data-box {
				padding: 30rpx;

				.ring-data-item {
					.ring-title {
						font-size: 28rpx;
						color: #4c9ee6;
					}
				}
			}


			.group-box {
				width: 100%;
				display: flex;
				flex-wrap: wrap;
				position: relative;


				.other-value {
					display: flex;
					flex-direction: column;
					width: 100%;

					.top-value {
						display: flex;
						justify-content: space-between;
						position: relative;

						.title {
							font-size: 24rpx;
							color: rgba(40, 40, 40, 1);
						}

						.zhexian-icon {
							position: absolute;
							right: 70%;

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

						.value {
							font-size: 32rpx;
							color: rgba(0, 156, 119, 1);
							font-weight: 400;
						}
					}

					.bottom-value {
						width: 100%;
						display: flex;
						justify-content: space-between;
						font-size: 24rpx;
						color: rgba(153, 153, 153, 1);
					}
				}
			}



			.group-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				width: 199rpx;

				justify-content: center;
				background: #d7e9e548;
				border-radius: 10rpx;
				margin: 10rpx 10rpx;
				position: relative;
				padding: 10rpx 0;

				.history-icon {
					position: absolute;
					right: 0rpx;
					top: 0rpx;
				}

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

				.item-con {
					display: flex;
					flex-direction: column;
					align-items: center;
					// margin-left: 15rpx;
					width: 100%;

					.item-title {
						width: 100%;
						font-size: 24rpx;
						color: #2a2a2a;
						margin-top: 10rpx;
						text-align: center;
						white-space: nowrap;
						overflow: hidden; //文本超出隐藏
						text-overflow: ellipsis; //文本超出省略号替
					}

					.item-num {
						font-size: 36rpx;
						color: #282828;
						font-weight: bold;
						max-width: 90%;
						text-align: center;

					}

					.item-unit {
						color: #cccccc;
						font-size: 16rpx;
						padding-left: 10rpx;
					}
				}
			}



			.chart-box {
				width: 650rpx;
				height: 500rpx;
				margin-top: 20rpx;
			}

			.border-bottom {
				border-bottom: 4rpx dotted #e5e5e5;
			}

			.border-right {
				border-right: 4rpx dotted #e5e5e5;
			}

			.padding-top-30 {
				padding-top: 30rpx;
			}

			.padding-bottom-30 {
				padding-bottom: 30rpx;
			}
		}

		.chart-box {
			width: 650rpx;
			height: 460rpx;
			margin-top: 20rpx;
		}

		.time-box {
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: 28rpx;
			margin-top: 20rpx;
			// border: 1px solid #a3a3a3;
			background-color: #f5f5f5;
			border-radius: 8rpx;
			padding: 10rpx;

			.time {

				font-size: 28rpx;
				white-space: nowrap;
			}
		}

		.slot-content {
			padding: 20rpx;
		}

	}
</style>