element ui 复杂表格,表格合并
效果图:
<template>
<div style="">
<el-table
:data="tableData"
:span-method="objectSpanMethod"
border
:header-cell-style="head"
:header-row-style ='headrow'
style="width: 100%; margin-top: 20px">
<el-table-column
label="抽验渠道"
width="100">
<template slot="header" slot-scope="scope">
<div class="first-head">
<div class="yplx">类别</div>
<div class="line"></div>
<div class="cyqd">渠道</div>
</div>
</template>
<el-table-column
prop="id"
width="100"
>
</el-table-column>
<el-table-column
prop="name"
width="100"
>
</el-table-column>
<el-table-column
prop="amount1"
width="100"
>
</el-table-column>
</el-table-column>
<el-table-column
prop="amount2"
label="数值 2(元)">
</el-table-column>
<el-table-column
prop="amount3"
label="数值 3(元)">
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
name: "ceshi",
data() {
return {
tableData: [{
id: '生产单位',
name: '单位数',
amount1: '总数'
}, {
id: '生产单位',
name: '单位数',
amount1: '不合格数'
}, {
id: '生产单位',
name: '品种数',
amount1: '总数'
}, {
id: '生产单位',
name: '品种数',
amount1: '不合格数'
}, {
id: '生产单位',
name: '批数',
amount1: '总数',
},
{
id: '生产单位',
name: '单位数',
amount1: '不合格数',
},
{
id: '经营单位',
name: '单位数',
amount1: '总数',
},
{
id: '经营单位',
name: '单位数',
amount1: '不合格数',
},
{
id: '经营单位',
name: '品种数',
amount1: '总数',
},
{
id: '经营单位',
name: '单位数',
amount1: '不合格数',
},
{
id: '经营单位',
name: '批数',
amount1: '总数',
},
{
id: '经营单位',
name: '单位数',
amount1: '不合格数',
}]
}
},
mounted() {
},
methods:{
head({ row, column, rowIndex, columnIndex }) {
if (rowIndex === 0) {
//这里为了是将第二列的表头隐藏,就形成了合并表头的效果
return { padding: 0 }
}
if (rowIndex === 1) {
//这里为了是将第二列的表头隐藏,就形成了合并表头的效果
return {display: 'none', padding: 0}
}
return "background:#f5f7fa"
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
if (rowIndex % 6 === 0) {
return {
rowspan: 6,
colspan: 1
};
} else {
return {
rowspan: 0,
colspan: 0
};
}
}
if (columnIndex === 1) {
if (rowIndex % 2 === 0) {
return {
rowspan: 2,
colspan: 1
};
} else {
return {
rowspan: 0,
colspan: 0
};
}
}
}
}
}
</script>
<style scoped lang="less">
.fa {
padding: 10px;
border: 1px solid #ccc;
}
li {
padding: 10px;
border: 1px solid #ccc;
}
.line {
background-color: #ccc;
height: 1px;
transform: rotate(6deg);
}
.first-head{
.yplx{
margin-left: 200px;
}
.cyqd{
}
}
</style>