feat(ems): 添加产线选择和总表功能,增强表格配置选项
- 在电表管理页面添加产线选择下拉框和总表开关 - 在能耗表格页面添加配置选项:显示求和行、分表求和、误差计算 - 实现表格汇总行计算功能 - 添加误差和误差率计算功能
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
<div v-else>
|
||||
<!-- 增加日期筛选,默认选中当前月份,用户可以切换月份 -->
|
||||
<div style="margin-bottom: 16px; display: flex; align-items: center;">
|
||||
<div style="margin-bottom: 16px; display: flex; align-items: center; flex-wrap: wrap; gap: 10px;">
|
||||
<el-date-picker
|
||||
v-model="selectedMonth"
|
||||
type="month"
|
||||
@@ -29,10 +29,17 @@
|
||||
style="width: 150px;"
|
||||
/>
|
||||
|
||||
<el-button style="margin-left: 10px;" icon="el-icon-refresh" @click="handleRefresh">刷新</el-button>
|
||||
<el-button icon="el-icon-refresh" @click="handleRefresh">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 配置选项 -->
|
||||
<div style="margin-bottom: 16px; padding: 10px; background: #f5f7fa; border-radius: 4px;">
|
||||
<el-checkbox v-model="configOptions.showSumRow">显示求和行</el-checkbox>
|
||||
<el-checkbox v-model="configOptions.sumSubMeters" style="margin-left: 20px;">对分表求和(排除总表)</el-checkbox>
|
||||
<el-checkbox v-model="configOptions.showError" style="margin-left: 20px;" :disabled="!canShowError">显示误差计算</el-checkbox>
|
||||
</div>
|
||||
|
||||
<el-table :data="tableData" style="width: 100%" border>
|
||||
<el-table :data="tableData" style="width: 100%" border :show-summary="configOptions.showSumRow" :summary-method="getSummaries">
|
||||
<el-table-column prop="date" label="日期" width="120" />
|
||||
<el-table-column v-for="meter in meters" :key="meter.meterId" :prop="`meter_${meter.meterId}`"
|
||||
:label="meter.meterCode">
|
||||
@@ -41,6 +48,24 @@
|
||||
@change="(e) => handleCellChange(scope.row, meter.meterId, e)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 分表求和列 -->
|
||||
<el-table-column v-if="configOptions.sumSubMeters" label="分表合计" width="120">
|
||||
<template slot-scope="scope">
|
||||
{{ getSubMetersSum(scope.row).toFixed(2) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 误差列 -->
|
||||
<el-table-column v-if="configOptions.showError && canShowError" label="误差" width="120">
|
||||
<template slot-scope="scope">
|
||||
{{ getRowError(scope.row).toFixed(2) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 误差率列 -->
|
||||
<el-table-column v-if="configOptions.showError && canShowError" label="误差率" width="120">
|
||||
<template slot-scope="scope">
|
||||
{{ getRowErrorPercent(scope.row).toFixed(2) }}%
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -72,8 +97,21 @@ export default {
|
||||
rightLoading: false,
|
||||
selectedMonth: currentMonth,
|
||||
originalData: [], // 用于存储原始数据
|
||||
configOptions: {
|
||||
showSumRow: false,
|
||||
sumSubMeters: false,
|
||||
showError: false
|
||||
},
|
||||
sumRowData: {} // 存储求和行数据
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 判断是否可以显示误差计算(需要有且仅有一个总表)
|
||||
canShowError() {
|
||||
const totalMeters = this.meters.filter(m => m.isTotalMeter === 1);
|
||||
return totalMeters.length === 1;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadEnergyTypes();
|
||||
},
|
||||
@@ -277,6 +315,86 @@ export default {
|
||||
handleAddMeter() {
|
||||
this.$router.push({ path: '/ems/meter/manage' });
|
||||
},
|
||||
|
||||
// 计算一行中所有分表的和
|
||||
getSubMetersSum(row) {
|
||||
const subMeters = this.meters.filter(m => m.isTotalMeter !== 1);
|
||||
return subMeters.reduce((sum, meter) => {
|
||||
const value = Number(row[`meter_${meter.meterId}`]) || 0;
|
||||
return sum + value;
|
||||
}, 0);
|
||||
},
|
||||
|
||||
// 计算一行的误差(总表 - 分表合计)
|
||||
getRowError(row) {
|
||||
if (!this.canShowError) return 0;
|
||||
const totalMeter = this.meters.find(m => m.isTotalMeter === 1);
|
||||
const totalValue = Number(row[`meter_${totalMeter.meterId}`]) || 0;
|
||||
const subMetersSum = this.getSubMetersSum(row);
|
||||
return totalValue - subMetersSum;
|
||||
},
|
||||
|
||||
// 计算一行的误差百分比
|
||||
getRowErrorPercent(row) {
|
||||
if (!this.canShowError) return 0;
|
||||
const totalMeter = this.meters.find(m => m.isTotalMeter === 1);
|
||||
const totalValue = Number(row[`meter_${totalMeter.meterId}`]) || 0;
|
||||
if (totalValue === 0) return 0;
|
||||
const error = this.getRowError(row);
|
||||
return (error / totalValue) * 100;
|
||||
},
|
||||
|
||||
// 计算表格汇总行
|
||||
getSummaries(param) {
|
||||
const { columns, data } = param;
|
||||
const sums = [];
|
||||
|
||||
// 如果不显示求和行,返回空数组
|
||||
if (!this.configOptions.showSumRow) {
|
||||
return sums;
|
||||
}
|
||||
|
||||
columns.forEach((column, index) => {
|
||||
if (index === 0) {
|
||||
sums[index] = '合计';
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取当前列对应的表计
|
||||
const prop = column.property;
|
||||
if (prop && prop.startsWith('meter_')) {
|
||||
// 计算该列的和
|
||||
const values = data.map(item => Number(item[prop]) || 0);
|
||||
const sum = values.reduce((prev, curr) => prev + curr, 0);
|
||||
sums[index] = sum.toFixed(2);
|
||||
return;
|
||||
}
|
||||
|
||||
// 分表合计列的汇总
|
||||
if (column.label === '分表合计' && this.configOptions.sumSubMeters) {
|
||||
const sum = data.reduce((total, row) => total + this.getSubMetersSum(row), 0);
|
||||
sums[index] = sum.toFixed(2);
|
||||
return;
|
||||
}
|
||||
|
||||
// 误差列的汇总
|
||||
if (column.label === '误差' && this.configOptions.showError && this.canShowError) {
|
||||
const sum = data.reduce((total, row) => total + this.getRowError(row), 0);
|
||||
sums[index] = sum.toFixed(2);
|
||||
return;
|
||||
}
|
||||
|
||||
// 误差率列不进行汇总
|
||||
if (column.label === '误差率') {
|
||||
sums[index] = '-';
|
||||
return;
|
||||
}
|
||||
|
||||
sums[index] = '';
|
||||
});
|
||||
|
||||
return sums;
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user