"Data": [
{
"PatientName": "导管室光盘刻录",
"sm": 5376.0,
"ct": 216.0,
"t": "微信",
"total": 7186.0
},
{
"PatientName": "导管室光盘刻录",
"sm": 405.0,
"ct": 16.0,
"t": "支付宝",
"total": 7186.0
},
{
"PatientName": "导管室光盘刻录",
"sm": 1405.0,
"ct": 119.0,
"t": "聚合付",
"total": 7186.0
},
{
"PatientName": "小儿内科(二)",
"sm": 561.1,
"ct": 133.0,
"t": "微信",
"total": 576.1
},
{
"PatientName": "小儿内科(二)",
"sm": 15.0,
"ct": 9.0,
"t": "支付宝",
"total": 576.1
},
{
"PatientName": "医疗服务(病历复印)",
"sm": 12040.0,
"ct": 888.0,
"t": "支付宝",
"total": 12040.0
},
{
"PatientName": "医疗服务(营养科)",
"sm": 4935.4,
"ct": 80.0,
"t": "支付宝",
"total": 4935.4
},
{
"PatientName": "医疗服务费(急诊))",
"sm": 3203.6,
"ct": 162.0,
"t": "微信",
"total": 3344.8
},
{
"PatientName": "医疗服务费(急诊))",
"sm": 141.2,
"ct": 5.0,
"t": "支付宝",
"total": 3344.8
},
{
"PatientName": "合计",
"sm": 28082.3,
"ct": 1628.0,
"t": "",
"total": 28082.3
}
],
<el-table :span-method="objectSpanMethod" :data="data.list" border stripe>
<el-table-column label="科室名称" prop="PatientName" align="center"></el-table-column>
<el-table-column prop="ct" align="center" label="收费人数">
</el-table-column>
<el-table-column prop="t" align="center" label="支付方式">
</el-table-column>
<el-table-column prop="sm" align="center" label="收入金额">
</el-table-column>
<el-table-column prop="total" align="center" label="合计">
</el-table-column>
</el-table>
我在objectSpanMethod中写逻辑,写了半天写不成,最关键的是需要合并的行个数不定,1,2,3,4,。。行合并都有可能。
const objectSpanMethod = ({row,column,rowIndex,columnIndex}) => {
let count=data.list.filter((item)=>item.PatientName===row.PatientName).length
if (columnIndex === 0 || columnIndex === 4) {
/*
if (rowIndex % count === 0) {
return {
rowspan: 2,
colspan: 1,
}
} else {
return {
rowspan: 0,
colspan: 0,
}
}
*/
}
}
objectSpanMethod里面判断在不在范围内就行了