getSpanArr (data) {
console.log(data)//從后台獲取的數據
this.spanArr = []
this.spanCodeArr = []
for (var i = 0; i < data.length; i++) {
if (i === 0) {
//如果是第一條記錄(即索引是0的時候),向數組中加入1
this.spanArr.push(1)
this.spanCodeArr.push(1);
this.pos = 0
this.codePos = 0
} else {
if (data[i].areaName === data[i-1].areaName) {
//如果areaName相等就累加,並且push 0
this.spanArr[this.pos] += 1
this.spanArr.push(0)
} else {
//不相等push 1
this.spanArr.push(1)
this.pos = i
}
if (data[i].deptCode === data[i-1].deptCode) {
//如果deptCode相等就累加,並且push 0
this.spanCodeArr[this.codePos] += 1
this.spanCodeArr.push(0)
} else {
//不相等push 1
this.spanCodeArr.push(1)
this.codePos = i
}
}
}
console.log(this.spanArr)
console.log(this.spanCodeArr)
},
objectSpanMethod({ row, column, rowIndex, columnIndex }){
if(columnIndex==1){
const _row = this.spanArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
if(columnIndex==2){
const _row = this.spanCodeArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
}