guoyujie
1 天以前 748e47eb02e874e521500b24f5444d6dbaeda3b8
north-glass-erp/northglass-erp/src/components/BasicTable.vue
@@ -122,6 +122,8 @@
  pageTotal : 0,//总页数
  dataTotal : 0,//数据总条数
})
const isFirstLoad = ref(true);
const sumNum = (list, field) => {
  let count = 0
  list.forEach(item => {
@@ -131,9 +133,9 @@
}
//合并显示其他列
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;
@@ -158,10 +160,10 @@
        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=>{
@@ -180,7 +182,26 @@
      }
    };
  });
  });*/
  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 = {
@@ -247,9 +268,11 @@
        orderInfo.reportFormDate = res.data.selectDate
        //订单明细报表
        if (props.childrenData.url === '/order/getOrderReport') {
        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
        }
      }
    })