kukuasir@vip.qq.com 1 рік тому
батько
коміт
6bb3cd7123
3 змінених файлів з 209 додано та 187 видалено
  1. 13 0
      src/js/common.js
  2. 134 133
      src/js/export.js
  3. 62 54
      src/views/equip-management/report/list.vue

+ 13 - 0
src/js/common.js

@@ -268,6 +268,18 @@ function calcMaxStandaloneCnt(box) {
   return max;
 }
 
+function calcMaxStandaloneCntExt(box) {
+  // 需求:末端最多显示一行,其他类型设备最多两行。如果其他类型设备超过一行,末端需要合并
+  // 如果主机新风机换热站的单机数都是0,还需取一下末端的数量(最大为1)
+  let max = Math.max(box.hpCnt || 0, box.dhCnt || 0, box.hexCnt || 0);
+  max = Math.min(2, max);
+  if (max <= 0) {
+    let cbStandaloneCnt = box.end ? box.end.length : 0;
+    max = Math.min(cbStandaloneCnt, 1);
+  }
+  return max;
+}
+
 /**
  * 计算每个盒子下末端的最大值与最小值
  */
@@ -417,6 +429,7 @@ export default {
   heatExchangeCols,
   endCols,
   calcMaxStandaloneCnt,
+  calcMaxStandaloneCntExt,
   calcEndMinAndMaxValue,
   getArgsColor,
   formatData,

+ 134 - 133
src/js/export.js

@@ -58,7 +58,7 @@ export function exportToExcel(datas, fn) {
 
 	// 多级表头
 	const multiHeader = [[
-		'项目名称', '盒子名称', '在线状态', '运行模式',
+		'盒子名称', '在线状态', '运行模式',
 		'主机', '', '', '', '', '',
 		'新风机', '', '', '', '', '',
 		'换热站', '', '', '', '', '', '',
@@ -67,7 +67,7 @@ export function exportToExcel(datas, fn) {
 
 	// 二级表头
 	let header = [
-		'项目名称', '盒子名称', '在线状态', '运行模式',
+		'盒子名称', '在线状态', '运行模式',
 		'编号', '通讯状态', '故障', '供水水温(℃)', '回水水温(℃)', '温差',
 		'编号', '通讯状态', '故障', '送风温度(℃)', '送风湿度(%)', '露点(℃)',
 		'编号', '通讯状态', '故障', '供水水温(℃)', '回水水温(℃)', '温差', '水泵状态',
@@ -76,40 +76,42 @@ export function exportToExcel(datas, fn) {
 
 	// 数据
 	let expand = _transferDataToXlsx(datas)
+	console.log("expand: ", expand);
 
 	// 合并表头
-	const merges = ['A1:A2', 'B1:B2', 'C1:C2', 'D1:D2', 'E1:J1', 'K1:P1', 'Q1:W1', 'X1:AD1']
+	const merges = ['A1:A2', 'B1:B2', 'C1:C2', 'D1:I1', 'J1:O1', 'P1:V1', 'W1:AC1']
 
 	// 合并列
-	let projectSet = _calcProjectRowMap(expand)
+	// let projectSet = _calcProjectRowMap(expand)
 	let boxSet = _calcBoxRowMap(expand)
+	console.log("boxSet: ", boxSet);
 	// 计算项目合并列
-	if (projectSet.length > 0) {
-		let first = projectSet[0]
-		merges.push('A'+(3+first.s)+':A'+(3+first.l-1))
-		for (let i = 1; i < projectSet.length; i++) {
-			let pre = projectSet[i - 1]
-			let cur = projectSet[i]
-			let start = 3 + pre.s + pre.l
-			merges.push('A'+start+':A'+(start+cur.l-1))
-		}
-	}
+	// if (projectSet.length > 0) {
+	// 	let first = projectSet[0]
+	// 	merges.push('A'+(3+first.s)+':A'+(3+first.l-1))
+	// 	for (let i = 1; i < projectSet.length; i++) {
+	// 		let pre = projectSet[i - 1]
+	// 		let cur = projectSet[i]
+	// 		let start = 3 + pre.s + pre.l
+	// 		merges.push('A'+start+':A'+(start+cur.l-1))
+	// 	}
+	// }
 	// 计算盒子/盒子运行状态/盒子运行模式合并列
 	if (boxSet.length > 0) {
 		let first = boxSet[0]
-		merges.push('B'+(3+first.s)+':B'+(3+first.l-1))
-		merges.push('C'+(3+first.s)+':C'+(3+first.l-1))
-		merges.push('D'+(3+first.s)+':D'+(3+first.l-1))
+		merges.push('A'+(2+first.s)+':A'+(2+first.l-1))
+		merges.push('B'+(2+first.s)+':B'+(2+first.l-1))
+		merges.push('C'+(2+first.s)+':C'+(2+first.l-1))
 		for (let i = 1; i < boxSet.length; i++) {
 			let pre = boxSet[i - 1]
 			let cur = boxSet[i]
-			let start = 3 + pre.s + pre.l
+			let start = 2 + pre.s + pre.l
+			merges.push('A'+start+':A'+(start+cur.l-1))
 			merges.push('B'+start+':B'+(start+cur.l-1))
 			merges.push('C'+start+':C'+(start+cur.l-1))
-			merges.push('D'+start+':D'+(start+cur.l-1))
 		}
 	}
-	// console.log("merges: ", merges)
+	console.log("merges: ", merges);
 
 	// 导出
 	Export2ExcelMerge({
@@ -119,6 +121,7 @@ export function exportToExcel(datas, fn) {
 		filename: defaultFilename,
 		merges
 	})
+
 	fn()
 }
 
@@ -145,106 +148,104 @@ function _listAllProjects(fn) {
 	})
 }
 
-function _transferDataToXlsx(projects) {
+function _transferDataToXlsx(boxList) {
 	let tableData = []
-	projects.forEach(p => {
-		if (Array.isArray(p.boxList)) {
-			p.boxList.forEach(b => {
-				// 继续判断有多少单机,主机、新风机、换热站、末端单机数量取最大值
-				let maxCnt = define.calcMaxStandaloneCnt(b)
-				for (let i = 0; i < maxCnt; i++) {
-					let hpStandalone = b.hostCtrl && i < b.hostCtrl.length ? b.hostCtrl[i] : undefined
-					let dhStandalone = b.newTrendCtrl && i < b.newTrendCtrl.length ? b.newTrendCtrl[i] : undefined
-					let hexStandalone = b.hex && i < b.hex.length ? b.hex[i] : undefined
-					let cbStandalone = i > 0 ? undefined : define.calcEndMinAndMaxValue(b.end || [])
-					let row = [
-            p.projectName,
-            b.boxName,
-            define.runStatDict[b.runStatus]
-              ? define.runStatDict[b.runStatus].label
-              : "/",
-            define.runModeDict[b.runMode]
-              ? define.runModeDict[b.runMode].label
-              : "/",
-            hpStandalone ? hpStandalone.host_order : "/",
-            hpStandalone && b.runStatus == 1
-              ? _getConnectState(hpStandalone.host_connect_status)
-              : "/",
-            hpStandalone && b.runStatus == 1
-              ? _getFault(hpStandalone.host_fault)
-              : "/",
-            hpStandalone && b.runStatus == 1
-              ? _fixVal(hpStandalone.host_su_temp)
-              : "/",
-            hpStandalone && b.runStatus == 1
-              ? _fixVal(hpStandalone.host_re_temp)
-              : "/",
-            hpStandalone && b.runStatus == 1
-              ? _noneZero(hpStandalone, "host_temp_diff")
-              : "/",
-            dhStandalone ? dhStandalone.nt_order : "/",
-            dhStandalone && b.runStatus == 1
-              ? _getConnectState(dhStandalone.nt_connect_status)
-              : "/",
-            dhStandalone && b.runStatus == 1
-              ? _getFault(dhStandalone.nt_fault)
-              : "/",
-            dhStandalone && b.runStatus == 1
-              ? _fixVal(dhStandalone.nt_in_temp)
-              : "/",
-            dhStandalone && b.runStatus == 1
-              ? _fixVal(dhStandalone.nt_in_humidity)
-              : "/",
-            dhStandalone && b.runStatus == 1
-              ? _fixVal(dhStandalone.nt_dew_point)
-              : "/",
-            hexStandalone ? hexStandalone.hex_order : "/",
-            hexStandalone && b.runStatus == 1
-              ? _getConnectState(hexStandalone.hex_connect_status)
-              : "/",
-            hexStandalone && b.runStatus == 1
-              ? _getFault(hexStandalone.hex_fault)
-              : "/",
-            hexStandalone && b.runStatus == 1
-              ? _fixVal(hexStandalone.hex_su_temp)
-              : "/",
-            hexStandalone && b.runStatus == 1
-              ? _fixVal(hexStandalone.hex_re_temp)
-              : "/",
-            hexStandalone && b.runStatus == 1
-              ? _fixVal(hexStandalone.hex_temp_diff)
-              : "/",
-            hexStandalone && b.runStatus == 1
-              ? _getHexPumpState(hexStandalone.hex_pump_status)
-              : "/",
-            // cbStandalone ? cbStandalone.end_order : '/',
-            cbStandalone && b.runStatus == 1
-              ? cbStandalone.end_exception_num
-              : "/",
-            cbStandalone && b.runStatus == 1
-              ? _noneZero(cbStandalone, "end_min_temp")
-              : "/",
-            cbStandalone && b.runStatus == 1
-              ? _noneZero(cbStandalone, "end_min_humidity")
-              : "/",
-            cbStandalone && b.runStatus == 1
-              ? _noneZero(cbStandalone, "end_min_dew_point")
-              : "/",
-            cbStandalone && b.runStatus == 1
-              ? _noneZero(cbStandalone, "end_max_temp")
-              : "/",
-            cbStandalone && b.runStatus == 1
-              ? _noneZero(cbStandalone, "end_max_humidity")
-              : "/",
-            cbStandalone && b.runStatus == 1
-              ? _noneZero(cbStandalone, "end_max_dew_point")
-              : "/",
-          ];
-					tableData.push(row)
-				}
-			})
-		}
-	})
+	boxList.forEach((b) => {
+    // 继续判断有多少单机,主机、新风机、换热站、末端单机数量取最大值
+    let maxCnt = define.calcMaxStandaloneCntExt(b);
+    for (let i = 0; i < maxCnt; i++) {
+      let hpStandalone =
+        b.hostCtrl && i < b.hostCtrl.length ? b.hostCtrl[i] : undefined;
+      let dhStandalone =
+        b.newTrendCtrl && i < b.newTrendCtrl.length
+          ? b.newTrendCtrl[i]
+          : undefined;
+      let hexStandalone = b.hex && i < b.hex.length ? b.hex[i] : undefined;
+      let cbStandalone =
+        i > 0 ? undefined : define.calcEndMinAndMaxValue(b.end || []);
+      let row = [
+        b.boxName,
+        define.runStatDict[b.runStatus]
+          ? define.runStatDict[b.runStatus].label
+          : "/",
+        define.runModeDict[b.runMode]
+          ? define.runModeDict[b.runMode].label
+          : "/",
+        hpStandalone ? hpStandalone.host_order : "/",
+        hpStandalone && b.runStatus == 1
+          ? _getConnectState(hpStandalone.host_connect_status)
+          : "/",
+        hpStandalone && b.runStatus == 1
+          ? _getFault(hpStandalone.host_fault)
+          : "/",
+        hpStandalone && b.runStatus == 1
+          ? _fixVal(hpStandalone.host_su_temp)
+          : "/",
+        hpStandalone && b.runStatus == 1
+          ? _fixVal(hpStandalone.host_re_temp)
+          : "/",
+        hpStandalone && b.runStatus == 1
+          ? _noneZero(hpStandalone, "host_temp_diff")
+          : "/",
+        dhStandalone ? dhStandalone.nt_order : "/",
+        dhStandalone && b.runStatus == 1
+          ? _getConnectState(dhStandalone.nt_connect_status)
+          : "/",
+        dhStandalone && b.runStatus == 1
+          ? _getFault(dhStandalone.nt_fault)
+          : "/",
+        dhStandalone && b.runStatus == 1
+          ? _fixVal(dhStandalone.nt_in_temp)
+          : "/",
+        dhStandalone && b.runStatus == 1
+          ? _fixVal(dhStandalone.nt_in_humidity)
+          : "/",
+        dhStandalone && b.runStatus == 1
+          ? _fixVal(dhStandalone.nt_dew_point)
+          : "/",
+        hexStandalone ? hexStandalone.hex_order : "/",
+        hexStandalone && b.runStatus == 1
+          ? _getConnectState(hexStandalone.hex_connect_status)
+          : "/",
+        hexStandalone && b.runStatus == 1
+          ? _getFault(hexStandalone.hex_fault)
+          : "/",
+        hexStandalone && b.runStatus == 1
+          ? _fixVal(hexStandalone.hex_su_temp)
+          : "/",
+        hexStandalone && b.runStatus == 1
+          ? _fixVal(hexStandalone.hex_re_temp)
+          : "/",
+        hexStandalone && b.runStatus == 1
+          ? _fixVal(hexStandalone.hex_temp_diff)
+          : "/",
+        hexStandalone && b.runStatus == 1
+          ? _getHexPumpState(hexStandalone.hex_pump_status)
+          : "/",
+        // cbStandalone ? cbStandalone.end_order : '/',
+        cbStandalone && b.runStatus == 1 ? cbStandalone.end_exception_num : "/",
+        cbStandalone && b.runStatus == 1
+          ? _noneZero(cbStandalone, "end_min_temp")
+          : "/",
+        cbStandalone && b.runStatus == 1
+          ? _noneZero(cbStandalone, "end_min_humidity")
+          : "/",
+        cbStandalone && b.runStatus == 1
+          ? _noneZero(cbStandalone, "end_min_dew_point")
+          : "/",
+        cbStandalone && b.runStatus == 1
+          ? _noneZero(cbStandalone, "end_max_temp")
+          : "/",
+        cbStandalone && b.runStatus == 1
+          ? _noneZero(cbStandalone, "end_max_humidity")
+          : "/",
+        cbStandalone && b.runStatus == 1
+          ? _noneZero(cbStandalone, "end_max_dew_point")
+          : "/",
+      ];
+      tableData.push(row);
+    }
+  });
 	return tableData
 }
 
@@ -270,21 +271,21 @@ function _calcProjectRowMap(datas) {
 
 // 计算盒子的合并行(每个盒子的合并数)
 function _calcBoxRowMap(datas) {
-	let boxNames = datas.map(v => v[1])
-	let nameset = Array.from(new Set(boxNames))
+	let boxIds = datas.map(v => v[0])
+	let idset = Array.from(new Set(boxIds));
 	let rows = []
-	nameset.forEach(name => {
-		let row = { name: name }
-		for (let i = 0; i < datas.length; i++) {
-			if (datas[i][1] === name) {
-				row.s = i
-				break
-			}
-		}
-		let list = datas.filter(d => d[1] === name)
-		row.l = list.length || 1
-		rows.push(row)
-	})
+	idset.forEach((boxId) => {
+    let row = { boxId: boxId };
+    for (let i = 0; i < datas.length; i++) {
+      if (datas[i][1] === boxId) {
+        row.s = i;
+        break;
+      }
+    }
+    let list = datas.filter((d) => d[1] === boxId);
+    row.l = list.length || 1;
+    rows.push(row);
+  });
 	return rows
 }
 

+ 62 - 54
src/views/equip-management/report/list.vue

@@ -731,63 +731,75 @@ export default {
 		},
 		/** 本地数据先排序再过滤 */
 		sortAndFilterDataSource(data, sort) {
+			console.log("原始数据: ", data);
+
 			// 先排序
 			// this.sortDataSource(data, sort);
 			// console.log("排序后的数据: ", data);
-
-			const hpSuTempMin = this.extraParams.hpSuTempMin;
-			const hpSuTempMax = this.extraParams.hpSuTempMax;
-			const dhDewPointMin = this.extraParams.dhDewPointMin;
-			const dhDewPointMax = this.extraParams.dhDewPointMax;
-			const hexSuTempMin = this.extraParams.hexSuTempMin;
-			const hexSuTempMax = this.extraParams.hexSuTempMax;
+			
+			/**
+			 * 使用filter()方法过滤不满足条件的数据
+			 */
 			const filterHpSuTemp = (this.extraParams.hpSuTempMax > this.extraParams.hpSuTempMin);
 			const filterDhDewPoint = (this.extraParams.dhDewPointMax > this.extraParams.dhDewPointMin);
 			const filterHexSuTemp = (this.extraParams.hexSuTempMax > this.extraParams.hexSuTempMin);
-			// 凡是不满足条件的盒子,全都过滤掉
-			let newBoxList = deepClone(data);
-			for (let i = 0; i < data.length; i++) {
-				const box = data[i];
+			let filterData = data.filter(box => {
 				let hasFilter1 = false;  // 主机供水温度是否把盒子过滤掉了
 				let hasFilter2 = false;  // 新风送风露点是否把盒子过滤掉了
-				// 过滤主机
+				
+				// 根据主机供水温度过滤盒子
 				if (filterHpSuTemp) {
 					const hostCtrl = box.hostCtrl || [];
-					for (let j = 0; j < hostCtrl.length; j++) {
-						const hp = hostCtrl[j];
-						if (hp.host_su_temp < hpSuTempMin || hp.host_su_temp > hpSuTempMax) {
-							newBoxList.splice(i, 1);
-							hasFilter1 = true;
-							break;
+					if (!hostCtrl.length || box.runStatus == 2) {
+						hasFilter1 = true;
+						return false;
+					} else {
+						for (let j = 0; j < hostCtrl.length; j++) {
+							const hp = hostCtrl[j];
+							if (hp.host_su_temp < this.extraParams.hpSuTempMin || hp.host_su_temp > this.extraParams.hpSuTempMax) {
+								hasFilter1 = true;
+								return false;
+							}
 						}
 					}
 				}
+
 				// 过滤新风机
 				if (filterDhDewPoint && !hasFilter1) {
 					const newTrendCtrl = box.newTrendCtrl || [];
-					for (let j = 0; j < newTrendCtrl.length; j++) {
-						const dh = newTrendCtrl[j];
-						if (dh.nt_dew_point < dhDewPointMin || dh.nt_dew_point > dhDewPointMax) {
-							newBoxList.splice(i, 1);
-							hasFilter2 = true;
-							break;
+					if (!newTrendCtrl.length || box.runStatus == 2) {
+						hasFilter2 = true;
+						return true;
+					} else {
+						for (let j = 0; j < newTrendCtrl.length; j++) {
+							const dh = newTrendCtrl[j];
+							if (dh.nt_dew_point < this.extraParams.dhDewPointMin || dh.nt_dew_point > this.extraParams.dhDewPointMax) {
+								hasFilter2 = true;
+								return true;
+							}
 						}
 					}
 				}
+
 				// 过滤换热站
 				if (filterHexSuTemp && !hasFilter1 && hasFilter2) {
 					const heatExchangeCtrl = box.hex || [];
-					for (let j = 0; j < heatExchangeCtrl.length; j++) {
-						const hex = heatExchangeCtrl[j];
-						if (hex.hex_su_temp < hexSuTempMin || hex.hex_su_temp > hexSuTempMax) {
-							newBoxList.splice(i, 1);
-							break;
+					if (!heatExchangeCtrl.length || box.runStatus == 2) {
+						return true;
+					} else {
+						for (let j = 0; j < heatExchangeCtrl.length; j++) {
+							const hex = heatExchangeCtrl[j];
+							if (hex.hex_su_temp < this.extraParams.hexSuTempMin || hex.hex_su_temp > this.extraParams.hexSuTempMax) {
+								return true;
+							}
 						}
 					}
 				}
-			}
-			this.total = newBoxList.length;
-			this.dataSource = newBoxList;
+				return true;
+			});
+
+			this.total = filterData.length;
+			this.dataSource = filterData;
 		},
 		/** 数据排序 */
 		sortDataSource(data, sort) {
@@ -796,7 +808,7 @@ export default {
 			}
 			// 主机
 			if (sort.prop.indexOf('host_')) {
-				
+				return this.sortByHostData(data, sort);
 			}
 			// 新风机
 			else if (sort.prop.indexOf('nt_')) {
@@ -836,7 +848,6 @@ export default {
 					return 0;
 				}
 			});
-
 			return hostData;
 		},
 		/** 生成tableData */
@@ -862,19 +873,19 @@ export default {
 				if (row['boxName-span']) return row['boxName-span'];
 			}
 			// 主机合并
-			if (columnIndex >= 6 && columnIndex <= 11) {
+			if (columnIndex >= 5 && columnIndex <= 10) {
 				return { rowspan: row.hpSpanRows, colspan: 1 };
 			}
 			// 新风机
-			if (columnIndex >= 12 && columnIndex <= 17) {
+			if (columnIndex >= 11 && columnIndex <= 16) {
 				return { rowspan: row.dhSpanRows, colspan: 1 };
 			}
 			// 换热站
-			if (columnIndex >= 18 && columnIndex <= 24) {
+			if (columnIndex >= 17 && columnIndex <= 23) {
 				return { rowspan: row.hexSpanRows, colspan: 1 };
 			}
 			// 末端
-			if (columnIndex >= 25) {
+			if (columnIndex >= 24) {
 				return { rowspan: row.cbSpanRows, colspan: 1 };
 			}
 			const span = column['property'] + '-span';
@@ -884,14 +895,11 @@ export default {
 		},
 		/** 获取对应设备下的末端列表 */
 		getDatasByRow(row, prop) {
-			let project = this.pageData.find(p => p.projectName === row.projectName);
-			if (project) {
-				let box = project.boxList.find(b => b.box_id === row.boxId);
-				if (!box) {
-					return [];
-				}
-				return box[prop];
+			let box = this.pageData.find(b => b.box_id === row.boxId);
+			if (!box) {
+				return [];
 			}
+			return box[prop];
 		},
 		/** 获取Item背景颜色 */
 		getItemBgColor(scope) {
@@ -924,16 +932,16 @@ export default {
 		},
 		/** 多选 */
 		handleSelectionChange(val) {
-			// 根据源数据找到对应的项目列表
-			// 先合并选中的数据中的项目名称,再根据项目名称匹配项目数据
-			let projectNames = val.map(v => v.projectName);
-			this.nameset = Array.from(new Set(projectNames));
-			let projList = [];
+			// 根据源数据找到对应的盒子列表
+			// 先合并选中的数据中的盒子id,再根据项目名称匹配盒子数据
+			let boxIds = val.map(v => v.boxId);
+			this.nameset = Array.from(new Set(boxIds));
+			let boxList = [];
 			this.nameset.forEach(name => {
-				let project = this.pageData.find(d => d.projectName === name);
-				projList.push(project);
-			})
-			this.selection = projList;
+				let box = this.pageData.find(d => d.boxId === name);
+				boxList.push(box);
+			});
+			this.selection = boxList;
 		},
 		/** 分页切换 */
 		handleSizeChange(val) {