|
@@ -49,12 +49,13 @@
|
|
v-bind="options"
|
|
v-bind="options"
|
|
:show-summary="useSum"
|
|
:show-summary="useSum"
|
|
@row-click="rowClick"
|
|
@row-click="rowClick"
|
|
|
|
+ :summary-method="computedSum"
|
|
>
|
|
>
|
|
<el-table-column type="selection" width="55" v-if="select" prop="id" :reserve-selection="true"> </el-table-column>
|
|
<el-table-column type="selection" width="55" v-if="select" prop="id" :reserve-selection="true"> </el-table-column>
|
|
<template v-for="(item, index) in fields">
|
|
<template v-for="(item, index) in fields">
|
|
<template v-if="!item.notable">
|
|
<template v-if="!item.notable">
|
|
<template v-if="item.custom">
|
|
<template v-if="item.custom">
|
|
- <el-table-column :key="index" align="center" :label="item.label" v-bind="item.options">
|
|
|
|
|
|
+ <el-table-column :key="index" align="center" :label="item.label" v-bind="item.options" :show-overflow-tooltip="item.showTip || true">
|
|
<template v-slot="{ row }">
|
|
<template v-slot="{ row }">
|
|
<slot name="custom" v-bind="{ item, row }"></slot>
|
|
<slot name="custom" v-bind="{ item, row }"></slot>
|
|
</template>
|
|
</template>
|
|
@@ -145,6 +146,8 @@ export default {
|
|
total: { type: Number, default: 0 },
|
|
total: { type: Number, default: 0 },
|
|
options: null,
|
|
options: null,
|
|
useSum: { type: Boolean, default: false },
|
|
useSum: { type: Boolean, default: false },
|
|
|
|
+ sumcol: { type: Array, default: () => [] },
|
|
|
|
+ sumres: { type: String, default: 'total' },
|
|
filter: { type: Array, default: () => [] },
|
|
filter: { type: Array, default: () => [] },
|
|
operaWidth: { type: Number, default: 200 },
|
|
operaWidth: { type: Number, default: 200 },
|
|
limit: { type: Number, default: _.get(this, `$limit`, undefined) !== undefined ? this.$limit : process.env.VUE_APP_LIMIT * 1 || 10 },
|
|
limit: { type: Number, default: _.get(this, `$limit`, undefined) !== undefined ? this.$limit : process.env.VUE_APP_LIMIT * 1 || 10 },
|
|
@@ -281,6 +284,64 @@ export default {
|
|
let { prop, filterReturn } = item;
|
|
let { prop, filterReturn } = item;
|
|
if (filterReturn) this.$emit('filterReturn', { data, prop });
|
|
if (filterReturn) this.$emit('filterReturn', { data, prop });
|
|
},
|
|
},
|
|
|
|
+ // 计算合计
|
|
|
|
+ computedSum({ columns, data }) {
|
|
|
|
+ if (columns.length <= 0 || data.length <= 0) return '';
|
|
|
|
+ const result = [];
|
|
|
|
+ const reg = new RegExp(/^\d+$/);
|
|
|
|
+ for (const column of columns) {
|
|
|
|
+ // 判断有没有prop属性
|
|
|
|
+ const prop = _.get(column, 'property');
|
|
|
|
+ if (!prop) {
|
|
|
|
+ result.push('');
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 判断是否需要计算
|
|
|
|
+ const inlist = this.sumcol.find(f => f == prop);
|
|
|
|
+ if (!inlist) {
|
|
|
|
+ result.push('');
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ let res = 0;
|
|
|
|
+ // 整理出要计算的属性(只取出数字或者可以为数字的值)
|
|
|
|
+ const resetList = data.map(i => {
|
|
|
|
+ const d = _.get(i, prop);
|
|
|
|
+ const res = reg.test(d);
|
|
|
|
+ if (res) return d * 1;
|
|
|
|
+ else return 0;
|
|
|
|
+ });
|
|
|
|
+ if (this.sumres === 'total') {
|
|
|
|
+ res = this.totalComputed(resetList);
|
|
|
|
+ } else if (this.sumres === 'avg') {
|
|
|
|
+ res = this.avgComputed(resetList);
|
|
|
|
+ } else if (this.sumres === 'max') {
|
|
|
|
+ res = this.maxComputed(resetList);
|
|
|
|
+ } else if (this.sumres === 'min') {
|
|
|
|
+ res = this.minComputed(resetList);
|
|
|
|
+ }
|
|
|
|
+ result.push(res);
|
|
|
|
+ }
|
|
|
|
+ result[0] = '合计';
|
|
|
|
+ return result;
|
|
|
|
+ },
|
|
|
|
+ // 合计计算
|
|
|
|
+ totalComputed(data) {
|
|
|
|
+ const total = data.reduce((p, n) => p + n, 0);
|
|
|
|
+ return total;
|
|
|
|
+ },
|
|
|
|
+ // 平均值计算
|
|
|
|
+ avgComputed(data) {
|
|
|
|
+ const total = this.totalComputed(data);
|
|
|
|
+ return _.round(_.divide(total, data.length), 2);
|
|
|
|
+ },
|
|
|
|
+ // 最大值计算
|
|
|
|
+ maxComputed(data) {
|
|
|
|
+ return _.max(data);
|
|
|
|
+ },
|
|
|
|
+ // 最小值计算
|
|
|
|
+ minComputed(data) {
|
|
|
|
+ return _.min(data);
|
|
|
|
+ },
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
selected: {
|
|
selected: {
|