|
|
@@ -7,6 +7,7 @@
|
|
|
:columns="columns"
|
|
|
:tools="false"
|
|
|
show-summary
|
|
|
+ :summary-method="getSummaries"
|
|
|
:flex-table="false"
|
|
|
>
|
|
|
<template #toolbar="{ row }">
|
|
|
@@ -54,6 +55,74 @@
|
|
|
cacheKey: 'recycleOrderStatisticTable'
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ * 自定义表格汇总计算方法
|
|
|
+ * @param {Object} param0 - 表格数据和列信息
|
|
|
+ * @returns {Array} - 汇总行显示的数据
|
|
|
+ */
|
|
|
+ function getSummaries({ columns, data }) {
|
|
|
+ const sums = [];
|
|
|
+ columns.forEach((column, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ sums[index] = '合计';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const values = data.map((item) => Number(item[column.property]));
|
|
|
+
|
|
|
+ if (!values.length) {
|
|
|
+ sums[index] = 'N/A';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (column.property) {
|
|
|
+ case 'recycleAveragePrice': {
|
|
|
+ // 只计算有值的数据的平均值
|
|
|
+ const validValues = values.filter((value) => value && !isNaN(value));
|
|
|
+ if (validValues.length > 0) {
|
|
|
+ const sum = validValues.reduce((prev, curr) => prev + curr, 0);
|
|
|
+ sums[index] = (sum / validValues.length).toFixed(2);
|
|
|
+ } else {
|
|
|
+ sums[index] = '';
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'orderNum':
|
|
|
+ case 'bookNum':
|
|
|
+ case 'auditNum': {
|
|
|
+ // 求和
|
|
|
+ const sum = values.reduce((prev, curr) => {
|
|
|
+ const value = Number(curr);
|
|
|
+ if (!isNaN(value)) {
|
|
|
+ return prev + value;
|
|
|
+ } else {
|
|
|
+ return prev;
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
+ sums[index] = sum;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'auditMoney': {
|
|
|
+ // 求和,保留两位小数
|
|
|
+ const sum = values.reduce((prev, curr) => {
|
|
|
+ const value = Number(curr);
|
|
|
+ if (!isNaN(value)) {
|
|
|
+ return prev + value;
|
|
|
+ } else {
|
|
|
+ return prev;
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
+ sums[index] = sum.toFixed(2);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ sums[index] = '';
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return sums;
|
|
|
+ }
|
|
|
+
|
|
|
//刷新表格
|
|
|
function reload(where) {
|
|
|
pageRef.value?.reload(where);
|