|
@@ -31,6 +31,8 @@
|
|
|
size="small"
|
|
|
ref="windLifeTable"
|
|
|
v-loading="loading"
|
|
|
+ show-summary
|
|
|
+ :summary-method="getSummaries"
|
|
|
:max-height="tableHeight"
|
|
|
:style="{ width: '100%' }"
|
|
|
:row-class-name="rowstyle ? tableRowClassName : ''"
|
|
@@ -95,6 +97,12 @@ export default {
|
|
|
return false;
|
|
|
},
|
|
|
},
|
|
|
+ fromTableId: {
|
|
|
+ type: String,
|
|
|
+ default: () => {
|
|
|
+ return "";
|
|
|
+ },
|
|
|
+ },
|
|
|
tableId: {
|
|
|
type: String,
|
|
|
default: () => {
|
|
@@ -141,6 +149,87 @@ export default {
|
|
|
return "";
|
|
|
}
|
|
|
},
|
|
|
+ getSummaries(datas) {
|
|
|
+ const {columns, data} = datas
|
|
|
+ const sums = [];
|
|
|
+ columns.forEach((column, index) => {
|
|
|
+ const values = data.map(item => Number(item[column.property]));
|
|
|
+ if (index === 0) {
|
|
|
+ if (this.fromTableId === '2') {
|
|
|
+ this.getSunOrAvg(1, sums, index, values)
|
|
|
+ } else {
|
|
|
+ // if (this.fromTableId === '1' || this.fromTableId === '3' || this.fromTableId === '4' || this.fromTableId === '5' || this.fromTableId === '6')
|
|
|
+ sums[index] = '合计';
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!values.every(value => isNaN(value))) {
|
|
|
+ if (this.fromTableId === '1') {
|
|
|
+ if (index === 1 || index === 5 || index === 11 || index === 12 || index === 13) {
|
|
|
+ this.getSunOrAvg(2, sums, index, values)
|
|
|
+ } else {
|
|
|
+ this.getSunOrAvg(1, sums, index, values)
|
|
|
+ }
|
|
|
+ } else if (this.fromTableId === '2' || this.fromTableId === '5') {
|
|
|
+ if (index !== 0) {
|
|
|
+ this.getSunOrAvg(2, sums, index, values)
|
|
|
+ }
|
|
|
+ } else if (this.fromTableId === '3') {
|
|
|
+ if (index === 2) {
|
|
|
+ this.getSunOrAvg(2, sums, index, values)
|
|
|
+ } else {
|
|
|
+ this.getSunOrAvg(1, sums, index, values)
|
|
|
+ }
|
|
|
+ } else if (this.fromTableId === '4') {
|
|
|
+ if (index === 1) {
|
|
|
+ this.getSunOrAvg(2, sums, index, values)
|
|
|
+ } else {
|
|
|
+ this.getSunOrAvg(1, sums, index, values)
|
|
|
+ }
|
|
|
+ } else if (this.fromTableId === '6') {
|
|
|
+ if (index === 3 || index === 9) {
|
|
|
+ this.getSunOrAvg(1, sums, index, values)
|
|
|
+ } else {
|
|
|
+ this.getSunOrAvg(2, sums, index, values)
|
|
|
+ }
|
|
|
+ } else if (this.fromTableId === '7') {
|
|
|
+ if (index === 2 || index === 3) {
|
|
|
+ this.getSunOrAvg(2, sums, index, values)
|
|
|
+ } else {
|
|
|
+ this.getSunOrAvg(1, sums, index, values)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ sums[index] = '-';
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return sums;
|
|
|
+ },
|
|
|
+ getSunOrAvg(type, sums, index, values) {
|
|
|
+ if (type === 1) {
|
|
|
+ sums[index] = values.reduce((prev, curr) => {
|
|
|
+ const value = Number(curr);
|
|
|
+ if (!isNaN(value)) {
|
|
|
+ return prev + curr;
|
|
|
+ } else {
|
|
|
+ return prev;
|
|
|
+ }
|
|
|
+ }, 0) / values.length;
|
|
|
+ return sums[index] = sums[index].toFixed(2) + ' (avg)';
|
|
|
+ } else {
|
|
|
+ sums[index] = values.reduce((prev, curr) => {
|
|
|
+ const value = Number(curr);
|
|
|
+ if (!isNaN(value)) {
|
|
|
+ return prev + curr;
|
|
|
+ } else {
|
|
|
+ return prev;
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
+ return sums[index] = sums[index].toFixed(2)
|
|
|
+ }
|
|
|
+ },
|
|
|
handleExport() {
|
|
|
let $e = this.$refs.windLifeTable.$el;
|
|
|
try {
|