diff --git a/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml b/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml index 6fcf0f6..d4ecd3e 100644 --- a/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml +++ b/RuoYi-Vue-Oracle/src/main/resources/mybatis/oil/ThDeviceReportMonthMapper.xml @@ -48,15 +48,16 @@ - - + + + + + + + + + - + -
+
@@ -102,6 +134,9 @@ export default { tableHeight() { return window.innerHeight - 300; }, + pppList() { + return Array.from(new Set(this.tableData.map((item) => item.ppp))); + }, }, mounted() { // 获取当前年份 2024 @@ -109,6 +144,68 @@ export default { this.queryDebounce = debounce(this.query, 100); }, methods: { + tableRowClassName({ row, rowIndex }) { + const classNames = ["default-row", "success-row", "error-row", "warning-row", "info-row"]; + const index = this.pppList.findIndex((item) => item === row.ppp); + if (index === -1) return "info-row"; + return index > classNames.length - 1 ? classNames[index % classNames.length] : classNames[index]; + }, + getChildCount(row, key, childKey) { + const childSet = new Set(); + for (let i = 0; i < this.tableData.length; i++) { + if (row[key] === this.tableData[i][key]) { + childSet.add(this.tableData[i][childKey]); + } + } + return childSet.size; + }, + calculateChildAvg(row, key) { + const childList = []; + for (let i = 0; i < this.tableData.length; i++) { + if (row[key] === this.tableData[i][key]) { + childList.push(this.tableData[i].avgValue); + } + } + // 计算平均值, 保留两位小数 + return (childList.reduce((a, b) => a + b, 0) / childList.length).toFixed( + 2 + ); + }, + objectSpanMethod({ row, column, rowIndex, columnIndex }) { + const calculateRowSpan = (key) => { + const value = row[key]; + let rowSpan = 1; + if (rowIndex === 0) { + while ( + this.tableData[rowIndex + rowSpan] && + this.tableData[rowIndex + rowSpan][key] === value + ) { + rowSpan++; + } + return { rowspan: rowSpan, colspan: 1 }; + } else { + if (this.tableData[rowIndex - 1][key] === value) { + return { rowspan: 0, colspan: 0 }; + } else { + while ( + this.tableData[rowIndex + rowSpan] && + this.tableData[rowIndex + rowSpan][key] === value + ) { + rowSpan++; + } + return { rowspan: rowSpan, colspan: 1 }; + } + } + }; + + if (columnIndex === 0) { + return calculateRowSpan("ppp"); + } else if (columnIndex === 1) { + return calculateRowSpan("pp"); + } else if (columnIndex === 2) { + return calculateRowSpan("p"); + } + }, handleYearChange() { this.queryDebounce(); }, @@ -130,16 +227,16 @@ export default { } this.loading = true; - getDeviceReportYearList({ + getDeviceReportYearListAll({ deptId: this.dept.deptId, year: this.year, - pageNum: this.pageNum, - pageSize: this.pageSize, + // pageNum: this.pageNum, + // pageSize: this.pageSize, }) .then((res) => { if (res.code === 200) { - this.tableData = res.rows; - this.total = res.total; + this.tableData = res.data; + // this.total = res.total; } }) .finally(() => { @@ -161,10 +258,11 @@ export default { dataToExcel({ data: [ [fileName], - ["归属港区", "归属企业", "设备编码", "年份", "平均值"], + ["归属港口", "归属港区", "归属企业", "设备编码", "年份", "平均值"], ...data.map((row) => [ - row.gangqu, - row.deptName, + row.ppp, + row.pp, + row.p, row.sn, row.year, row.avgValue,