| | |
| | | pageTotal : 0,//总页数 |
| | | dataTotal : 0,//数据总条数 |
| | | }) |
| | | |
| | | const isFirstLoad = ref(true); |
| | | const sumNum = (list, field) => { |
| | | let count = 0 |
| | | list.forEach(item => { |
| | |
| | | }) |
| | | return count.toFixed(2) |
| | | } |
| | | |
| | | //合并显示其他列 |
| | | const handleDynamicColumns = (data,title,orderOtherMoney) => { |
| | | // 1. 收集所有行的otherColumns字段(去重) |
| | | /*const allOtherFields = new Set(); |
| | | data.forEach(row => { |
| | | if (!row || !row.otherColumns) return; |
| | | |
| | | let parsedOtherColumns; |
| | | try { |
| | | // 核心:将字符串解析为JSON |
| | | parsedOtherColumns = JSON.parse(row.otherColumns); |
| | | } catch (e) { |
| | | console.error('解析otherColumns失败:', e, '原始数据:', row.otherColumns); |
| | | return; |
| | | } |
| | | |
| | | // 2. 从解析后的JSON中收集字段(支持数组或对象格式) |
| | | if (Array.isArray(parsedOtherColumns)) { |
| | | // 数组格式:[{ key: 'field1', label: '字段1', value: '值1' }, ...] |
| | | parsedOtherColumns.forEach(item => { |
| | | if (item.key) allOtherFields.add(item.key); |
| | | }); |
| | | } else if (typeof parsedOtherColumns === 'object' && parsedOtherColumns !== null) { |
| | | // 对象格式:{ field1: { label: '字段1', value: '值1' }, ... } |
| | | Object.keys(parsedOtherColumns).forEach(key => { |
| | | allOtherFields.add(key); |
| | | }); |
| | | } |
| | | });*/ |
| | | |
| | | // 2. 生成动态子列(作为processList的children) |
| | | /*const otherColumns = Array.from(allOtherFields).map(field => { |
| | | // 尝试获取字段对应的label(优先取第一个出现的label) |
| | | let label=field; |
| | | title.forEach(item=>{ |
| | | if(field==item.column){ |
| | | label=item.alias |
| | | } |
| | | }) |
| | | return { |
| | | title: label, |
| | | field: `otherColumnsJson.${field}`, |
| | | width: 120, |
| | | align: 'center', |
| | | // 处理字段值显示(兼容数组/对象类型的otherColumns) |
| | | formatter: ({ row }) => { |
| | | return row.otherColumnsJson?.[field] || ''; |
| | | |
| | | } |
| | | }; |
| | | });*/ |
| | | |
| | | 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 = { |
| | | title: t('basicData.otherColumns'), |
| | | field: 'process', |
| | | children: otherColumns // 将动态列作为子列 |
| | | }; |
| | | |
| | | // 4. 先移除已存在的process列(避免重复),再添加新列 |
| | | gridOptions.columns = gridOptions.columns.filter(col => col.field !== 'process'); |
| | | gridOptions.columns.push(processList); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | |
| | | basicProp.value.pageTotal = res.data.total.pageTotal |
| | | basicProp.value.dataTotal = res.data.total.total |
| | | orderInfo.reportFormDate = res.data.selectDate |
| | | |
| | | //订单明细报表 |
| | | if (isFirstLoad.value && props.childrenData.url === '/order/getOrderReport') { |
| | | const dataList = res.data.data || []; |
| | | const orderOtherMoney = res.data.orderOtherMoney[0] || []; |
| | | handleDynamicColumns(dataList,res.data.title,orderOtherMoney) |
| | | isFirstLoad.value = false; // 首次加载后置为false |
| | | } |
| | | } |
| | | }) |
| | | return |
| | |
| | | basicProp.value.pageTotal = res.data.total.pageTotal |
| | | basicProp.value.dataTotal = res.data.total.total |
| | | orderInfo.reportFormDate = res.data.selectDate |
| | | |
| | | |
| | | } |
| | | }) |
| | | } |