diff --git a/klp-ui/src/views/cost/comprehensive.vue b/klp-ui/src/views/cost/comprehensive.vue index 4afc366f3..845b899a0 100644 --- a/klp-ui/src/views/cost/comprehensive.vue +++ b/klp-ui/src/views/cost/comprehensive.vue @@ -30,9 +30,9 @@ - + - + - + @@ -82,7 +95,7 @@ - 删除 + 删除 @@ -494,6 +507,45 @@ export default { }) return col && col.color ? { background: col.color, color: '#fff' } : {} } + }, + summaryRows() { + const rows = this.gridRows.filter(r => r.detailDate) + if (!rows.length) return [] + const detailCols = this.allCols.filter(c => c.$type === 'detail') + const metricCols = this.allCols.filter(c => c.$type === 'metric') + const calc = (type) => { + const row = { detailDate: type === 'sum' ? '总和' : '平均', $isSummary: true, $summaryType: type } + const n = rows.length || 1 + detailCols.forEach(col => { + if (col.isShift) { + const s1 = rows.reduce((a, r) => a + (parseFloat(r['q' + col.itemId + '_1']) || 0), 0) + const s2 = rows.reduce((a, r) => a + (parseFloat(r['q' + col.itemId + '_2']) || 0), 0) + row['q' + col.itemId + '_1'] = type === 'sum' ? s1.toFixed(2) : (s1 / n).toFixed(2) + row['q' + col.itemId + '_2'] = type === 'sum' ? s2.toFixed(2) : (s2 / n).toFixed(2) + row['q' + col.itemId] = type === 'sum' ? (s1 + s2).toFixed(2) : ((s1 + s2) / n).toFixed(2) + } else { + const s = rows.reduce((a, r) => a + (parseFloat(r['q' + col.itemId]) || 0), 0) + row['q' + col.itemId] = type === 'sum' ? s.toFixed(2) : (s / n).toFixed(2) + } + }) + metricCols.forEach(col => { + if (col.isShift) { + const s1 = rows.reduce((a, r) => a + (parseFloat(r['mv' + col.mIdx + '_1']) || 0), 0) + const s2 = rows.reduce((a, r) => a + (parseFloat(r['mv' + col.mIdx + '_2']) || 0), 0) + row['mv' + col.mIdx + '_1'] = type === 'sum' ? s1.toFixed(2) : (s1 / n).toFixed(2) + row['mv' + col.mIdx + '_2'] = type === 'sum' ? s2.toFixed(2) : (s2 / n).toFixed(2) + row['mv' + col.mIdx] = type === 'sum' ? (s1 + s2).toFixed(2) : ((s1 + s2) / n).toFixed(2) + } else { + const s = rows.reduce((a, r) => a + (parseFloat(r['mv' + col.mIdx]) || 0), 0) + row['mv' + col.mIdx] = type === 'sum' ? s.toFixed(2) : (s / n).toFixed(2) + } + }) + return row + } + return [calc('sum'), calc('avg')] + }, + tableData() { + return [...this.summaryRows, ...this.gridRows] } }, watch: { configOpen(v) { if (!v) this.rpOpen = false } }, @@ -509,6 +561,10 @@ export default { } }, methods: { + rowClassName({ row }) { + if (row.$isSummary) return 'summary-row' + return '' + }, /* report */ getList() { this.loading = true @@ -1142,4 +1198,8 @@ export default { .ica-backfill { color: #67c23a; margin-right: 1px; } .ica:hover { opacity: 0.7; } /deep/ .anomaly-input .el-input__inner { background: #fef0f0 !important; border-color: #f56c6c !important; } +/deep/ .summary-row td { background: #f0f7ff !important; font-weight: bold; } +/deep/ .summary-row td .cell { color: #303133; } +.summary-label { font-weight: bold; color: #303133; padding: 0 5px; } +.summary-val { font-weight: bold; color: #303133; }