| | |
| | | } |
| | | |
| | | //合并显示其他列 |
| | | const handleDynamicColumns = (data,title) => { |
| | | const handleDynamicColumns = (data,title,orderOtherMoney) => { |
| | | // 1. 收集所有行的otherColumns字段(去重) |
| | | const allOtherFields = new Set(); |
| | | /*const allOtherFields = new Set(); |
| | | data.forEach(row => { |
| | | if (!row || !row.otherColumns) return; |
| | | |
| | |
| | | allOtherFields.add(key); |
| | | }); |
| | | } |
| | | }); |
| | | });*/ |
| | | |
| | | // 2. 生成动态子列(作为processList的children) |
| | | const otherColumns = Array.from(allOtherFields).map(field => { |
| | | /*const otherColumns = Array.from(allOtherFields).map(field => { |
| | | // 尝试获取字段对应的label(优先取第一个出现的label) |
| | | let label=field; |
| | | title.forEach(item=>{ |
| | |
| | | |
| | | } |
| | | }; |
| | | }); |
| | | });*/ |
| | | |
| | | const otherColumns = []; |
| | | // 容错:确保orderOtherMoney是有效数组 |
| | | if (Array.isArray(orderOtherMoney) && orderOtherMoney.length > 0) { |
| | | orderOtherMoney.forEach(item => { |
| | | // 跳过空数据,避免无效列 |
| | | if (!item || !item.column) return; |
| | | otherColumns.push({ |
| | | title: item.alias || item.column, // 优先用别名,无则用字段名 |
| | | field: `otherColumnsJson.${item.column}`, |
| | | width: 120, |
| | | align: 'center', |
| | | // 格式化取值:兼容解析后的JSON结构 |
| | | formatter: ({ row }) => { |
| | | return row.otherColumnsJson?.[item.column] || ''; |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | // 3. 定义父级列processList,包含动态子列 |
| | | const processList = { |
| | |
| | | //订单明细报表 |
| | | if (isFirstLoad.value && props.childrenData.url === '/order/getOrderReport') { |
| | | const dataList = res.data.data || []; |
| | | handleDynamicColumns(dataList,res.data.title) |
| | | const orderOtherMoney = res.data.orderOtherMoney[0] || []; |
| | | handleDynamicColumns(dataList,res.data.title,orderOtherMoney) |
| | | isFirstLoad.value = false; // 首次加载后置为false |
| | | } |
| | | } |