1.模板中
<el-table :data="form.guestList1" show-summary :summary-method="getSummaries" :span-method="arraySpanMethod" ref="tableSumRef1">
<el-table-column label="姓名" prop="name" align="center">
</el-table-column>
<el-table-column label="国籍" align="center" prop="nationality">
</el-table-column>
<el-table-column label="总片酬(万元)" align="center" prop="totalRemuneration">
</el-table-column>
<el-table-column label="参与期数" align="center" prop="participation">
</el-table-column>
</el-table>
2.js中
2.1计算合计
/** 计算合计*/
getSummaries(param) {
const {
columns,
data
} = param;
const sums = [];
columns.forEach((column, index) => {
const values = data.map(item => Number(item[column.property]))
if (index === 2) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
sums[index] = "合计:" + sums[index] + " 万元"
}
})
return sums
},
2.2合并最后一行
arraySpanMethod() {
setTimeout(() => {
if (this.$refs.tableSumRef1) {
let current = this.$refs.tableSumRef1.$el
.querySelector(".el-table__footer-wrapper")
.querySelector(".el-table__footer");
let cell = current.rows[0].cells;
cell[0].style.display = "none";
cell[1].style.display = "none";
cell[2].colSpan = "4";
}
}, 50);
},