<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 style="text-align: center;">{{ item.title }}</text>
				<text style="text-align: center;">{{ 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: "电池",
						value: `${data?.b || ''}%(${data?.thingData?.adcProperty?.b || ''}V)`,
						unit: null
					});
					this.items.push({
						title: "433信号强度",
						value: data?.thingData?.ls.value,
						unit: null
					});
					this.items.push({
						title: "4G信号强度",
						value: data?.rssi,
						unit: null
					});
					this.items.push({
						title: "4G供电",
						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.deviceTypeId == 3 ? "(4G)" : ""}${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: "电池",
						value: `${data?.adc?.b || ''}%(${data?.thingData?.adcProperty?.b || ''}V)`,
						unit: null
					});
					this.items.push({
						title: "舱内温度",
						value: data?.adc?.t,
						unit: "℃"
					});
					this.items.push({
						title: "舱内湿度",
						value: data?.adc?.h,
						unit: "%"
					});
					let angel = "",
						angelAdc = "";
					switch (row.device.deviceTypeKey) {
						case "butterflyValve":
							break;
						case "valve":
							if (data.btnObj) {
								if (data.btnObj.close.switchOn) {
									angel = `全关(${data?.thingData?.va?.value})`;
								} else if (data.btnObj.open.switchOn) {
									angel = `全开(${data?.thingData?.va?.value})`;
								} else if (data.btnObj.open1.switchOn) {
									angel = `①开${data.btnObj.open1.openAngle}%`;
								} else if (data.btnObj.open2.switchOn) {
									angel = `②开${data.btnObj.open2.openAngle}%`;
								} else {
									angel = "-";
								}
								angelAdc = data?.thingData?.va?.value;
							} else {
								angel = "-";
								angelAdc = "";
							}
							break;
						case "fiveValve":
							if (data.btnObj) {
								let va = JSON.parse(data.thingData.va.value);
								if (data.btnObj.open1.switchOn) {
									angel = angel + `①开${data.btnObj.open1.openAngle}%`;
								}
								if (data.btnObj.open2.switchOn) {
									angel = angel + `,②开${data.btnObj.open2.openAngle}%`;
								}
								if (data.btnObj.open3.switchOn) {
									angel = angel + `,③开${data.btnObj.open3.openAngle}%`;
								}
								if (data.btnObj.open4.switchOn) {
									angel = angel + `,④开${data.btnObj.open4.openAngle}%`;
								}
								angelAdc = va.toString();
							} else {
								angel = "-";
								angelAdc = "";
							}
							break;
					}
					this.items.push({
						title: "角度",
						value: angel,
						unit: null
					});
					this.items.push({
						title: "原始角度",
						value: angelAdc,
						unit: null
					});
					this.items.push({
						title: "压力",
						value: data?.adc?.p.toString(),
						unit: null
					});
					this.items.push({
						title: "MCU",
						value: data?.thingData?.adcProperty?.mcu,
						unit: "V"
					});
					this.items.push({
						title: "充电电流",
						value: data?.thingData?.adcProperty?.cc,
						unit: "mA"
					});
					this.items.push({
						title: "充电电压",
						value: data?.thingData?.adcProperty?.ps,
						unit: "V"
					});
					if (row.device.deviceTypeKey == "valve") {
						this.items.push({
							title: "电机最大功率",
							value: data?.thingData?.adcProperty?.ma,
							unit: "W"
						});
					}
					this.items.push({
						title: "数据上报时间",
						value: data?.date,
						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>