需求:总计行合并多列,单位、子公司、生产产线、产品大类四列中相同行动态合并
// 合并单元格
getSpanArr (data) {
this.spanArr1 = []
this.spanArr2 = []
this.spanArr3 = []
this.spanArr4 = []
for (var i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr1.push(1)
this.spanArr2.push(1)
this.spanArr3.push(1)
this.spanArr4.push(1)
this.pos1 = 0
this.pos2 = 0
this.pos3 = 0
this.pos4 = 0
} else {
// 判断第二列
if (data[i].productSaleDept === data[i - 1].productSaleDept) {
this.spanArr1[this.pos1] += 1
this.spanArr1.push(0)
} else {
this.spanArr1.push(1)
this.pos1 = i
}
// 判断第三列
if (data[i].productSaleDept === data[i - 1].productSaleDept && data[i].subCode === data[i - 1].subCode) {
this.spanArr2[this.pos2] += 1
this.spanArr2.push(0)
} else {
this.spanArr2.push(1)
this.pos2 = i
}
// 判断第四列
if (data[i].productSaleDept === data[i - 1].productSaleDept && data[i].subCode === data[i - 1].subCode && data[i].productLineNumber === data[i - 1].productLineNumber) {
this.spanArr3[this.pos3] += 1
this.spanArr3.push(0)
} else {
this.spanArr3.push(1)
this.pos3 = i
}
// 判断第五列
if (data[i].productSaleDept === data[i - 1].productSaleDept && data[i].subCode === data[i - 1].subCode && data[i].productLineNumber === data[i - 1].productLineNumber && data[i].hbisProductTypeNumber === data[i - 1].hbisProductTypeNumber) {
this.spanArr4[this.pos4] += 1
this.spanArr4.push(0)
} else {
this.spanArr4.push(1)
this.pos4 = i
}
}
}
},
objectSpanMethod ({ row, rowIndex, columnIndex }) {
// 合并小计
if (columnIndex === 4 && row.hbisProductTypeNumber === "小计") {
return [1, 2]
} else if (columnIndex === 5 && row.hbisProductTypeNumber === "小计") {
return [0, 0]
}
// 合并合计
if (columnIndex === 3 && row.productLineNumber === "合计") {
return [1, 3]
} else if (columnIndex === 4 && row.productLineNumber === "合计") {
return [0, 0]
} else if (columnIndex === 5 && row.productLineNumber === "合计") {
return [0, 0]
}
// 合并总计
if (columnIndex === 2 && row.subCode === "总计") {
return [1, 4]
} else if (columnIndex === 3 && row.subCode === "总计") {
return [0, 0]
} else if (columnIndex === 4 && row.subCode === "总计") {
return [0, 0]
} else if (columnIndex === 5 && row.subCode === "总计") {
return [0, 0]
}
if (columnIndex === 1) {
const _row = this.spanArr1[rowIndex]
const _col = _row > 0 ? 1 : 0
// console.log(`rowspan:${_row} colspan:${_col}`)
return { // [0,0] 表示这一行不显示, [2,1]表示行的合并数
rowspan: _row,
colspan: _col
}
}
if (columnIndex === 2) {
const _row = this.spanArr2[rowIndex]
const _col = _row > 0 ? 1 : 0
// console.log(`rowspan:${_row} colspan:${_col}`)
return { // [0,0] 表示这一行不显示, [2,1]表示行的合并数
rowspan: _row,
colspan: _col
}
}
if (columnIndex === 3) {
const _row = this.spanArr3[rowIndex]
const _col = _row > 0 ? 1 : 0
// console.log(`rowspan:${_row} colspan:${_col}`)
return { // [0,0] 表示这一行不显示, [2,1]表示行的合并数
rowspan: _row,
colspan: _col
}
}
if (columnIndex === 4) {
const _row = this.spanArr4[rowIndex]
const _col = _row > 0 ? 1 : 0
// console.log(`rowspan:${_row} colspan:${_col}`)
return { // [0,0] 表示这一行不显示, [2,1]表示行的合并数
rowspan: _row,
colspan: _col
}
}
},