el-table 扁平化数据后合并单元格

原始数据:

javascript 复制代码
<script setup>

 // 原始数据: 
const preOrderProInfoList ref([
        {
            "PRO_NO": "154685",
            "PRE_PRO_NO": 2303,
            "orders": [
                {
                    "ORDER_NO": "25B00190",
                    "SEND_CENTER_SEQ": 1,
                    "REQ_DVS_CD": "2",
                    "DLVR_WAY_CD": "001",
                    "WARE_STATE_CD": "001",
                    "order_type": "1",
                    "request_type": "0"
                },
                {
                    "ORDER_NO": "25B00189",
                    "SEND_CENTER_SEQ": 1,
                    "REQ_DVS_CD": "2",
                    "DLVR_WAY_CD": "001",
                    "WARE_STATE_CD": "001",
                    "order_type": "1",
                    "request_type": "0"
                }
            ]
        }])



// 扁平化 
// 扁平化后的组合数据
const processedTableData = computed(() =>
    preOrderProInfoList.value.flatMap(combo =>
        combo.orders.map(product => ({
            ...product,
            PRO_NO: combo.PRO_NO,
            PRE_PRO_NO: combo.PRE_PRO_NO,
            PRO_IMG: combo.PRO_IMG || 'https://q7.itc.cn/q_70/images03/20241204/9442f197bdc94c05a32e7ed8b719dd59.jpeg'

        }))
    )
)


const arraySpanMethod = ({ row, rowIndex, columnIndex }) => {
    if ([0, 1].includes(columnIndex)) {
        const list = processedTableData.value
        if (
            rowIndex === 0 ||
            list[rowIndex].PRO_NO !== list[rowIndex - 1].PRO_NO
        ) {
            let rowspan = 1
            for (
                let i = rowIndex + 1;
                i < list.length && list[i].PRO_NO === row.PRO_NO;
                i++
            ) {
                rowspan++
            }
            return { rowspan, colspan: 1 }
        }
        // 合并到上面
        return { rowspan: 0, colspan: 0 }
    }
    // 其他列正常显示
    return { rowspan: 1, colspan: 1 }
}

< /script>
javascript 复制代码
<template>   
<el-table :data="processedTableData" border :span-method="arraySpanMethod" style="width: 100%"
                :cell-style="{ 'text-align': 'center' }" :header-cell-style="{
                    background: '#5f697d',
                    color: '#fff',
                    height: '10px',
                    width: '90%',
                    'text-align': 'center'
                }">
                <!-- 商品图片/编号 -->
                <el-table-column prop="PRO_NO" width="100">
                    <template #header>
                        <div class="label-flex">
                            <div>{{ t('product.商品图片') }}</div>
                            <div>{{ t('order_list.商品编号') }}</div>
                        </div>
                    </template>
                    <template #default="{ row }">
                        <div class="product-cell">
                            <el-image :src="row.PRO_IMG" class="product-img" />
                            <div class="product-info">
                                {{ row.PRO_NO }}
                            </div>
                        </div>
                    </template>
                </el-table-column>

                <!-- 代买商品编号 -->
                <el-table-column prop="PRE_PRO_NO" :label="t('errorInStock.代买商品编号')" width="150">
                    <template #default="{ row }">
                        <div v-if="row.showProductInfo">
                            {{ row.PRE_PRO_NO }}
                        </div>
                    </template>
                </el-table-column>

                <!-- 订单编号 -->
                <el-table-column :label="t('order_list.订单号')" width="180">
                    <template #default="{ row }">
                        <div class="order-item">
                            <el-radio v-model="selectedOrders[row.PRO_NO]" :label="row.ORDER_NO"
                                @change="handleOrderChange(row)">
                                {{ row.ORDER_NO }}
                            </el-radio>
                        </div>
                    </template>
                </el-table-column>
  </el-table>
相关推荐
精英的英2 小时前
【嵌入式Linux开发】如何在Windows上开发Linux ARM版本QT程序
linux·arm开发·windows
睡觉然后上课2 小时前
如何让虚拟机运行速度翻倍
linux·arm开发·windows
ITHAOGE152 小时前
下载| Windows 11 ARM版11月官方ISO系统映像 (适合部分笔记本、苹果M系列芯片电脑、树莓派和部分安卓手机平板)
windows·科技·microsoft·微软·电脑
低调波7 小时前
springboot实现批量下载
windows·spring boot·后端
至天1 天前
Windows 10/11 终端(Windows Terminal)右键菜单缺失恢复方法
windows·终端·windows 11·windows 10·terminal·右键菜单·windowsterminal
光年像素1 天前
WMIC(Windows Management Instrumentation Command-line)命令大全
windows
q***57501 天前
Redis服务安装自启动(Windows版)
数据库·windows·redis
A-刘晨阳1 天前
【Windows压力测试工具】 - 使用微软官方工具进行压测 cpu、内存
运维·windows·测试工具·压力测试·cpustres·testlimit
EQ-雪梨蛋花汤1 天前
【工具】如何使用 Windows BAT 批处理脚本递归删除指定后缀文件(附:完整代码,复制可用)
windows