<el-table border id="multipleTable" ref="multipleTable" :span-method="objectSpanMethod" :data="tempData" style=""
default-expand-all
:key="randomKey"
row-key="dataId"
empty-text="暂无数据"
v-loading="isLoading"
element-loading-background = "rgba(0, 0, 0, 0.5)"
:cell-style="{padding:'10px',textAlign:'center',borderColor:'#508bf8'}"
:header-cell-style="{padding:'0px',textAlign:'center',borderColor:'#508bf8'}" >
// 获取合并行
getSpanArr(data) {
this.spanArr = []; //第一列合并
let pos1 = 0;
for (let i = 0; i < data.length; i++) {
// debugger
data[i].dataId = i
if(data[i].qhmc){ //特化处理,非必要
if(data[i].shimc && this.levRadio == '4' && this.selectCode.length < 4){
data[i].cgcj = data[i].shimc + data[i].qhmc //非市级选县层级时显示上级市
}else{
data[i].cgcj = data[i].qhmc
}
}
if(data[i].children){//特化处理,非必要
data[i].children.forEach((ele,index) => {
ele.dataId = `${i}-${index}`
ele.cgcj = ele.sjdxmc
});
}
if (i === 0 ) {
// 如果是第一条记录(即索引是0的时候),向数组中加入1
this.spanArr.push(1); //第一列合并
}else {
if ((data[i].cgcj == data[i - 1].cgcj) ) { //(data[i].cgcj == data[i - 1].cgcj) ||
// 如果相同的单元格数据cgcj相等就累加,并且push 0
this.spanArr[pos1] += 1;
this.spanArr.push(0);
} else {
// 不相等push 1
this.spanArr.push(1);
pos1 = i;
}
}
}
console.log(data,this.spanArr,'data');
},
// 合并行
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
// debugger
if (columnIndex === 0&& !this.fxCheckList.includes('3') ) { //动态合并
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
// debugger
return {
rowspan: _row,
colspan: _col
};
}
if(row.sjdxmc){ //子级表的名称,把第一列名称合并到第二列
if (columnIndex === 0) { //从第一列开始
return {
rowspan: 1,
colspan: 2
};
}
if (columnIndex === 1) { //从第二列开始,隐藏
return {
rowspan: 0,
colspan: 0
};
}
}
},