zck 11 months ago
parent
commit
940592e73d

+ 44 - 17
src/view/DecisionSupport/outputsum/index.vue

@@ -148,15 +148,16 @@ onMounted(()=>{
  		})
 //导出到EXCEL(明细)
 const exportToExcel3 = () => {
-  //获取数据
+  console.log(datelist.value);
+  // 获取数据
   const el = document.getElementById('tab');
   const filename = '导出到EXCEL(汇总).xlsx';
-  
+
   // 获取工作表对象
   const wb = XLSX.utils.table_to_book(el, { raw: true });
   const ws = wb.Sheets[wb.SheetNames[0]];
-  //固定列加动态列转化成数字
-  // 确定数字列的位置
+
+  // 固定列加动态列转化成数字
   const numberCols = {
     // 固定列:产量合计是第3列(C列)
     'C': 'total_cl',
@@ -168,33 +169,48 @@ const exportToExcel3 = () => {
       ])
     )
   };
-  
-  // 设置数字格式
+
+  // 遍历工作表中的单元格,设置日期和数字格式
   Object.keys(ws).forEach(address => {
-    if(!address.startsWith('!')) {
+    if (!address.startsWith('!')) {
       const col = address.replace(/[0-9]/g, ''); // 获取列字母
-      if(numberCols[col]) {
-        const cell = ws[address];
-        // 尝试转换为数字
+      const cell = ws[address];
+
+      // 如果是日期列
+      if (numberCols[col] && datelist.value.includes(numberCols[col])) {
+        const rawValue = cell.v; // 原始值
+        if (typeof rawValue === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(rawValue)) {
+          // 如果是日期格式字符串(如 2025-04-01),转换为 Excel 日期格式
+          const date = new Date(rawValue);
+          if (!isNaN(date.getTime())) {
+            cell.t = 'd'; // 设置为日期类型
+            cell.v = date; // 更新值为日期对象
+          }
+        }
+      }
+
+      // 如果是数字列
+      if (numberCols[col] === 'total_cl' || (col !== 'C' && !datelist.value.includes(numberCols[col]))) {
         const num = parseFloat(cell.v);
-        if(!isNaN(num)) {
+        if (!isNaN(num)) {
           cell.t = 'n'; // 设置为数字类型
           cell.v = num; // 更新值
-          cell.z = '0.0'; // 设置数字格式(千分位,保留2位小数)
+          cell.z = '0.00'; // 设置数字格式(千分位,保留2位小数)
         }
       }
     }
   });
 
+  // 导出 Excel 文件
   const wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
-  
+
   try {
     FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), filename);
   } catch (e) {
     console.error('导出失败:', e);
   }
   return wbout;
-}
+};
 
 //导出到EXCEL(明细)
 const exportToExcel2 = () => {
@@ -294,9 +310,20 @@ const handleNodeClick = async (node) => {
     jqtabledata.value = []
     tabledate2.value = []
     params.value.mouth= node.label
-    params2.value.mouth= node.label
-    ProductList(params.value)
-    const Machineoutput = await MachineProductDetail ({mouth:params2.value.mouth})
+    // params2.value.mouth= node.label
+    const ProductListData = await MachineProduction({mouth:params.value.mouth});
+    datelist.value = ProductListData.data.head;
+
+    // 优化后的数据处理
+    tabledate2.value = ProductListData.data.total
+      .flatMap(item => Array.isArray(item) ? item : [item]) // 确保处理所有元素
+      .map(item => {
+        const { day_total, ...rest } = item; // 解构分离day_total和其他属性
+        return { ...rest, ...day_total }; // 合并属性
+      });
+    
+    console.log('处理后的数据:', tabledate2.value);
+    const Machineoutput = await MachineProductDetail ({mouth:params.value.mouth})
     jqtabledata.value = Machineoutput.data
   }
  if (node.children === undefined){

+ 1 - 1
src/view/DecisionSupport/productioncents/index.vue

@@ -385,7 +385,7 @@ const ExportDetailsToExcel = async () => {
       { key: '联数', label: '联数', width: 100, type: 'number' },
       { key: '印刷方式', label: '印刷方式', width: 100 },
       { key: '版距', label: '版距', width: 100 },
-      { key: '工序类型', label: '工序类型', width: 100 },
+      { key: 'type_name', label: '工序类型', width: 100 },
       { key: '完工年月', label: '完工年月', width: 100 }
     ];