<template>
	<u-popup :show="open" mode="center" @close="close" closeable>
		<view class="jz-info" style="width: 80vw;">
			<view style="font-size: 16px;font-weight: 600;margin-bottom: 10px;">{{title}}</view>
			<view v-for="item in items">
				<text>{{ item.title }}</text>
				<text>{{ item.value }}{{ item.unit }}</text>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import {
		timestampFormat
	} from '@/utils/common.js'

	export default {
		name: "ADC",
		components: {},
		props: {},
		data() {
			return {
				title: "设备ADC",
				open: false,
				items: [],
			}
		},
		created() {},
		mounted() {},
		methods: {
			/**
			 * 显示方法
			 * @param type 1基站 2阀门
			 * @param row
			 * @param data 
			 */
			async show(type, row, data = {}) {
				this.items = [];
				if (type == 1) {
					this.title = `基站ADC【${row.deviceCode}】`;
					this.items.push({
						title: "软/硬件版本",
						value: `${row?.softVer} / ${row?.deviceVersion}`,
						unit: null
					});
					this.items.push({
						title: "充电状态",
						value: data?.adc?.charging ? '充电中' : '未充电',
						unit: null
					});
					this.items.push({
						title: "电池ADC",
						value: data?.thingData?.adcProperty?.b,
						unit: "V"
					});
					this.items.push({
						title: "电池",
						value: data?.b,
						unit: "%"
					});
					this.items.push({
						title: "433信号强度",
						value: data?.thingData?.ls.value,
						unit: null
					});
					this.items.push({
						title: "433ADC",
						value: data?.thingData?.adcProperty?.l,
						unit: "V"
					});
					this.items.push({
						title: "4G信号强度",
						value: data?.rssi,
						unit: null
					});
					this.items.push({
						title: "4G供电ADC",
						value: data?.thingData?.adcProperty?.g,
						unit: "V"
					});
					this.items.push({
						title: "MCU",
						value: data?.thingData?.adcProperty?.mcu,
						unit: "V"
					});
					this.items.push({
						title: "充电电流ADC",
						value: data?.thingData?.adcProperty?.cc,
						unit: "mA"
					});
					this.items.push({
						title: "充电电压ADC",
						value: data?.thingData?.adcProperty?.ps,
						unit: "V"
					});
					this.items.push({
						title: "数据上报时间",
						value: data?.date,
						unit: null
					});
				}
				if (type == 2) {
					this.title = `阀门ADC【${row.showName}】`;
					this.items.push({
						title: "阀门",
						value: row.device?.deviceCode,
						unit: null
					});
					this.items.push({
						title: "软/硬件版本",
						value: `${row.device?.softVer} / ${row.device?.deviceVersion}`,
						unit: null
					});
					this.items.push({
						title: "充电状态",
						value: data?.adc?.charging ? '充电中' : '未充电',
						unit: null
					});
					this.items.push({
						title: "电池ADC",
						value: data?.thingData?.adcProperty?.b,
						unit: "V"
					});
					this.items.push({
						title: "电池",
						value: data?.adc?.b,
						unit: "%"
					});
					this.items.push({
						title: "温度ADC",
						value: data?.adc?.t,
						unit: "℃"
					});
					this.items.push({
						title: "压力ADC",
						value: data?.adc?.p.toString(),
						unit: null
					});
					let angel = "";
					switch (row.device.deviceTypeKey) {
						case "butterflyValve":
							break;
						case "valve":
						case "fiveValve":
							angel = data?.thingData?.va?.value;
							break;
					}
					this.items.push({
						title: "角度",
						value: angel,
						unit: null
					});
					this.items.push({
						title: "MCU",
						value: data?.thingData?.adcProperty?.mcu,
						unit: null
					});
					this.items.push({
						title: "充电电流ADC",
						value: data?.thingData?.adcProperty?.cc,
						unit: "mA"
					});
					this.items.push({
						title: "充电电压ADC",
						value: data?.thingData?.adcProperty?.ps,
						unit: "V"
					});
					this.items.push({
						title: "数据上报时间",
						value: data?.date,
						unit: null
					});
					// if (data?.latestOperation && data?.latestOperation.length) {
					// 	this.items.push({
					// 		title: "最近操作",
					// 		value: data.latestOperation[0].operContent,
					// 		unit: data.latestOperation[0].operResult ? '【成功】' : '【失败】',
					// 	});
					// 	this.items.push({
					// 		title: "最近操作人",
					// 		value: data.latestOperation[0].userName,
					// 		unit: null,
					// 	});
					// 	this.items.push({
					// 		title: "最近操作时间",
					// 		value: timestampFormat(data.latestOperation[0].time),
					// 		unit: null,
					// 	});
					// }
				}
				this.open = true;
			},
			close() {
				this.open = false;
				this.$emit('close');
			}
		}
	}
</script>
<style lang="scss" scoped>
	.jz-info {
		padding: 15px;

		view {
			display: flex;

			uni-text {
				line-height: 48rpx;
			}

			uni-text:nth-child(odd) {
				width: 100px;
				margin-right: 10px;
				color: #666;
				background: #f3f3f3;
			}

			uni-text:nth-child(even) {
				width: calc(100% - 100px);
				color: #000;
				word-wrap: break-word;
				/* 支持旧版浏览器 */
				overflow-wrap: break-word;
				/* 推荐 */
				white-space: normal;
				/* 可选：如果需要连字符 */
				hyphens: auto;
			}

		}
	}
</style>