// 合并表格的第一列,处理表格数据
flitterData(arr) {
let spanOneArr = [];
let concatOne = 0;
arr.forEach((item, index) => {
if (index === 0) {
spanOneArr.push(1);
} else {
//name 修改
// item.itemCode 是我第一列要渲染的值 这个你们改成自己的
if (item.itemCode === arr[index - 1].itemCode) {
//第一列需合并相同内容的判断条件
spanOneArr[concatOne] += 1;
spanOneArr.push(0);
} else {
spanOneArr.push(1);
concatOne = index;
}
}
});
return {
one: spanOneArr,
};
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
// 表格数据修改
const _row = this.flitterData(this.detailInfo.salesOrderManageLineVOS)
.one[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col,
};
}
},
然后在el-table上面绑定:span-method="objectSpanMethod" 效果立即出来