Browse Source

智能报表,面板弹窗数据优化

kukuasir@vip.qq.com 1 year ago
parent
commit
45a1adcaec
2 changed files with 55 additions and 11 deletions
  1. 2 0
      src/js/common.js
  2. 53 11
      src/views/equip-management/report/PopEndInfo.vue

+ 2 - 0
src/js/common.js

@@ -273,6 +273,7 @@ function calcMaxStandaloneCnt(box) {
  */
 export function calcEndMinAndMaxValue(standalone) {
   let tmp = {
+    end_order: 0,
     end_exception_num: 0,
     end_min_temp: 10000,
     end_min_humidity: 10000,
@@ -282,6 +283,7 @@ export function calcEndMinAndMaxValue(standalone) {
     end_max_dew_point: 0,
   };
   standalone.forEach((s) => {
+    tmp.end_order = s.end_order;
     tmp.end_exception_num += s.end_exception_num;
     if (s.end_min_temp != 0) {
       tmp.end_min_temp = Math.min(tmp.end_min_temp, s.end_min_temp);

+ 53 - 11
src/views/equip-management/report/PopEndInfo.vue

@@ -22,7 +22,7 @@
 				class="end-prop-title" 
 				v-if="selection.cbOrder && selection.cbName"
 			>
-				{{ selection.cbName + '(' + selection.cbOrder + ')' }}
+				{{ selection.area + ' - ' + selection.cbName + '(' + selection.cbOrder + ')' }}
 			</div>
 			<div v-if="universal">
 				<div class="end-prop-item" v-for="(item, index) in universal" :key="index" v-if="item.name">
@@ -35,7 +35,7 @@
 </template>
 
 <script>
-import { getBoxDetailById } from "@/api/box";
+import { getBoxDetailById, detailAppratusDevice } from "@/api/box";
 import { getRunState } from "@/api/box-debug";
 import { currentUserName } from "@/utils/trace";
 export default {
@@ -63,7 +63,9 @@ export default {
 			selection: {
 				id: undefined,
 				cbOrder: undefined,
-				cbName: undefined
+				cbName: undefined,
+				area: undefined,
+				cbDeviceSeries: undefined
 			},
 			// 属性
 			universal: [],
@@ -92,15 +94,25 @@ export default {
 				const data = JSON.parse(res.result);
 				const end = data.end || {};
 				const standalone = end.standalone || [];
+				let selIndex = 0;
+				
 				// 房间分组排序
+				const cbOrder = this.data.end_order || 0;
 				standalone.forEach((item, index) => {
-					// 默认选中第一个
-					item.selection = (index == 0);
+					// 计算默认选中的位置
+					if (item.cbOrder == cbOrder) {
+						item.selection = true;
+						selIndex = index;
+					} else {
+						item.selection = false;
+					}
+
 					// 房间名称放入数组,保证顺序
 					const areaIndex = this.areaList.findIndex((a) => a === item.area);
 					if (areaIndex < 0) {
 						this.areaList.push(item.area);
 					}
+
 					// 放入字典方便存取
 					let devices = this.areaMap[item.area];
 					if (!Array.isArray(devices) || !devices.length) {
@@ -110,12 +122,28 @@ export default {
 					this.areaMap[item.area] = devices;
 				});
 
-				// 获取实时数据
-				if (standalone.length > 0) {
-					const first = standalone[0];
-					this.selection.id = first.id;
-					this.selection.cbOrder = first.cbOrder;
-					this.selection.cbName = first.cbName;
+				// 计算已经选中的indexPath
+				for (let i = 0; i < this.areaList.length; i++) {
+					const area = this.areaList[i];
+					const deviceList = this.areaMap[area];
+					for (let j = 0; j < deviceList.length; j++) {
+						const device = deviceList[j];
+						if (device.cbOrder === cbOrder) {
+							this.lastIndexPath.section = i;
+							this.lastIndexPath.row = j;
+							break;
+						}
+					}
+				}
+
+				// 获取实时数据与设备详情
+				if (selIndex < standalone.length) {
+					const defSelection = standalone[selIndex];
+					this.selection.id = defSelection.id;
+					this.selection.cbOrder = defSelection.cbOrder;
+					this.selection.cbName = defSelection.cbName;
+					this.selection.area = defSelection.area;
+					this.selection.cbDeviceSeries = defSelection.cbDeviceSeries;
 					this.getRunState();
 				}
 			}
@@ -136,6 +164,18 @@ export default {
 						this.universal.push(element.read_io.universal || []);
 					}
 				}
+				this.getDeviceDetail(this.selection.cbDeviceSeries);
+			}
+		},
+		// 获取设备详情接口
+		async getDeviceDetail(deviceId) {
+			const res = await detailAppratusDevice({
+				device_id: deviceId
+			});
+			if (res.code === 200) {
+				const result = res.result || {};
+				const deviceName = result.device_name || '';
+				this.universal.splice(0, 0, { name: '设备型号', value: deviceName });
 			}
 		},
 		// 点击
@@ -156,6 +196,8 @@ export default {
 			this.selection.id = device.id;
 			this.selection.cbOrder = device.cbOrder;
 			this.selection.cbName = device.cbName;
+			this.selection.area = device.area;
+			this.selection.cbDeviceSeries = device.cbDeviceSeries;
 			this.getRunState();
 
 			this.lastIndexPath.section = section;