element 复杂表格,表格合并

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>

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值