xjj 1 yıl önce
ebeveyn
işleme
e2521c1ec8

+ 9 - 47
src/pages/Detail/CommitAuditModal.js

@@ -40,8 +40,7 @@ import ApprovalProcess from './ApprovalProcess';
 import { uuidv4 } from '@antv/xflow';
 import AliyunOSSUpload from '@/components/OssUpload/AliyunOssUploader';
 import AttachmentTable from '@/components/AttachmentTable';
-import { getToken } from '@/utils/utils';
-import LuckyExcel from 'luckyexcel';
+import uploadExcelByUrl from '@/utils/uploadExcelByUrl';
 
 const { TextArea } = Input;
 const { Option } = Select;
@@ -251,7 +250,7 @@ function CommitAuditModal(props) {
     setAuditId(node?.node_id);
   };
 
-  const onChange = (value) => {
+  const onChange = value => {
     if (value) {
       changeAudit(value[value.length - 1]);
       setAuditListFun(approvalProcess);
@@ -513,7 +512,10 @@ function CommitAuditModal(props) {
         next_template_id: version.template_id,
       };
       if (serviceNode.node_type_psr == 3 || serviceNode.node_type_psr == 4) {
-        params.data = await uploadExcelByUrl(serviceNode.node_type_psr, version.id);
+        let project = projectList.find(item => item.id == version?.project_id);
+        let projectName = project?.project_name || '';
+        let sheetData = await uploadExcelByUrl(serviceNode.node_type_psr, version.id, projectName);
+        params.data = JSON.parse(sheetData);
       }
       // params.data = await uploadExcelByUrl(3, version.id);
       console.log(params);
@@ -699,53 +701,13 @@ function getDataValue(item) {
   }
   return arr;
 }
-const uploadExcelByUrl = (nodeType, versionId) => {
-  const TEMPLATE_URL =
-    'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/doc/contract/2023-06-29/ed0d5dcd-6ce0-40df-9d17-a1f69245dbb9.xlsx';
-  const TEMPLATE_URL2 =
-    'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/doc/contract/2023-06-29/431733cd-0abc-4a68-a439-d24c466e9845.xlsx';
-
-  return new Promise((reslove, reject) => {
-    LuckyExcel.transformExcelToLuckyByUrl(
-      nodeType == 3 ? TEMPLATE_URL : TEMPLATE_URL2,
-      '模板.xlsx',
-      async (exportJson, luckysheetfile) => {
-        let [record] = await getExcel(versionId);
-
-        let len = exportJson.sheets.length;
-        const excelData = exportJson.sheets?.map(item => {
-          return { ...item, order: Number(item.order) };
-        });
-        delete record.id;
-        record.order = len;
-        record.index = String(len);
-        record.status = '0';
-        record.name = '投标成本';
-        var res = [...excelData, record];
-        console.log(res);
-        reslove(JSON.stringify(res));
-      }
-    );
-  });
-};
-
-async function getExcel(gridKey) {
-  var formData = new FormData();
-  formData.append('gridKey', gridKey);
-  let res = await fetch(
-    `/api/v1/purchase/record/sheet?gridKey=${gridKey}&JWT-TOKEN=${getToken()}`,
-    {
-      method: 'POST',
-      body: formData,
-    }
-  ).then(response => response.text());
-  return JSON.parse(JSON.parse(res));
-}
 
-export default connect(({ xflow, detail, user }) => ({
+export default connect(({ xflow, detail, user, list }) => ({
   flowDetail: xflow.flowDetail,
   versionList: detail.versionList,
   currentUser: user.currentUser,
   userList: user.list,
   OSSData: detail.OSSData,
+  // 隐患:刷新页面后将会丢失projectList
+  projectList: list?.project?.list || [],
 }))(CommitAuditModal);

+ 24 - 65
src/pages/Temp/index.js

@@ -5,52 +5,37 @@ import LuckyExcel from 'luckyexcel';
 import { Button, message } from 'antd';
 import { getToken } from '@/utils/utils';
 import moment from 'moment';
+import uploadExcelByUrl from '@/utils/uploadExcelByUrl';
 
 const TEMPLATE_URL =
-  'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/bom/635/%E5%90%88%E5%90%8C%E6%96%87%E4%BB%B6/%E6%8A%95%E6%A0%87%E6%A8%A1%E6%9D%BF.xlsx';
+  'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/doc/contract/2023-06-29/ed0d5dcd-6ce0-40df-9d17-a1f69245dbb9.xlsx';
 
-const TEMPLATE_URL2 = 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/psr.xlsx';
+const TEMPLATE_URL2 =
+  'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/ContractTemplate.xlsx';
 
 function Index(props) {
-  const { versionId = 2376 } = props;
+  const { versionId = 2554 } = props;
 
   const sheetRef = useRef();
   const luckysheetRef = useRef();
 
-  const uploadExcelByUrl = type => {
-    LuckyExcel.transformExcelToLuckyByUrl(
-      type == 1 ? TEMPLATE_URL : TEMPLATE_URL2,
-      '模板.xlsx',
-      async (exportJson, luckysheetfile) => {
-        // if (type == 2) initData(exportJson.sheets);
-        let [record] = await getExcel(versionId);
-
-        let len = exportJson.sheets.length;
-        record.order = len - 1;
-        record.index = len;
-        record.status = '0';
-
-        const data = [...exportJson.sheets, record];
-        console.log(data);
-
-        luckysheetRef.current.destroy();
-
-        luckysheetRef.current.create({
-          data,
-          lang: 'zh',
-          showinfobar: false,
-          showstatisticBar: false,
-          hook: {
-            cellMousedown: (cell, position, sheet) => {
-              console.log(cell, position, sheet);
-            },
-            cellUpdated: () => {
-              luckysheetRef.current.refreshFormula();
-            },
-          },
-        });
-      }
-    );
+  const onClick = async type => {
+    let data = await uploadExcelByUrl(type, versionId, 'test水厂');
+    luckysheetRef.current.destroy();
+    luckysheetRef.current.create({
+      data,
+      lang: 'zh',
+      showinfobar: false,
+      showstatisticBar: false,
+      hook: {
+        cellMousedown: (cell, position, sheet) => {
+          console.log(cell, position, sheet);
+        },
+        cellUpdated: () => {
+          luckysheetRef.current.refreshFormula();
+        },
+      },
+    });
   };
 
   const handleLoad = () => {
@@ -58,25 +43,12 @@ function Index(props) {
     luckysheetRef.current = contentWindow.luckysheet;
   };
 
-  const initData = sheets => {
-    let r = 5,
-      c = 12;
-    // let dateCell = sheets[3].celldata.find(item => item.r == 1 && item.c == 3);
-    let timer = sheets[3].celldata.filter(item => item.r == r && item.c >= c);
-    timer.forEach((item, index) => {
-      const cell = item.v;
-      
-      cell.f = `=EDATE(D2,${index})`;
-    });
-    console.log(timer);
-  };
-
   return (
     <div>
-      <Button type="primary" style={{ marginRight: 20 }} onClick={() => uploadExcelByUrl(1)}>
+      <Button type="primary" style={{ marginRight: 20 }} onClick={() => onClick(3)}>
         导入投标投标
       </Button>
-      <Button type="primary" onClick={() => uploadExcelByUrl(2)}>
+      <Button type="primary" onClick={() => onClick(4)}>
         导入合同模板
       </Button>
 
@@ -93,17 +65,4 @@ function Index(props) {
   );
 }
 
-async function getExcel(gridKey) {
-  var formData = new FormData();
-  formData.append('gridKey', gridKey);
-  let res = await fetch(
-    `/api/v1/purchase/record/sheet?gridKey=${gridKey}&JWT-TOKEN=${getToken()}`,
-    {
-      method: 'POST',
-      body: formData,
-    }
-  ).then(response => response.text());
-  return JSON.parse(JSON.parse(res));
-}
-
 export default Index;

+ 212 - 0
src/utils/uploadExcelByUrl.js

@@ -0,0 +1,212 @@
+import LuckyExcel from 'luckyexcel';
+import { getToken } from '@/utils/utils';
+
+const uploadExcelByUrl = (nodeType, versionId, projectName) => {
+  const TEMPLATE_URL =
+    'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/doc/contract/2023-06-29/ed0d5dcd-6ce0-40df-9d17-a1f69245dbb9.xlsx';
+  const TEMPLATE_URL2 =
+    'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/ContractTemplate.xlsx';
+
+  return new Promise((reslove, reject) => {
+    LuckyExcel.transformExcelToLuckyByUrl(
+      nodeType == 3 ? TEMPLATE_URL : TEMPLATE_URL2,
+      '模板.xlsx',
+      async (exportJson, luckysheetfile) => {
+        let [record] = await getExcel(versionId);
+
+        let len = exportJson.sheets.length;
+        const excelData = exportJson.sheets?.map(item => {
+          return { ...item, order: Number(item.order) };
+        });
+        delete record.id;
+        record.order = len;
+        record.index = len + '_' + Math.floor(Math.random() * 100);
+        record.status = '0';
+        record.name = '投标成本';
+        var sheets = [...excelData, record];
+        const category = getCategoryData(record);
+        // 处理Estimate表
+        initEstimate(sheets[0], category);
+
+        // 处理psr预算
+        // initPSR(sheets[1], category);
+
+        if (nodeType == 4) {
+          // 处理psr预算
+          // initPSR(sheets[2], category);
+          // 处理毛利概算表
+          initActual(sheets[3], category, projectName);
+        }
+        reslove(sheets);
+      }
+    );
+  });
+};
+
+async function getExcel(gridKey) {
+  var formData = new FormData();
+  formData.append('gridKey', gridKey);
+  let res = await fetch(
+    `/api/v1/purchase/record/sheet?gridKey=${gridKey}&JWT-TOKEN=${getToken()}`,
+    {
+      method: 'POST',
+      body: formData,
+    }
+  ).then(response => response.text());
+  return JSON.parse(JSON.parse(res));
+}
+
+function getCellValue(cell) {
+  let v = '';
+  if (cell.v) {
+    v = cell.v;
+  } else if (cell?.ct?.s) {
+    v = cell.ct.s.map(item => item.v).join('');
+  }
+  return v;
+}
+
+function formatNumber(str) {
+  const number = parseFloat(str);
+  if (!isNaN(number) && number % 1 !== 0) {
+    return number.toFixed(1);
+  }
+  return str;
+}
+// 根据清单获取表分类总价
+function getCategoryData(bom) {
+  let bomData = [],
+    bomTitle = {};
+  bom.celldata.forEach(item => {
+    let v = getCellValue(item.v);
+    if (item.r == 0) {
+      // 设置表头
+      bomTitle[item.c] = v;
+    } else {
+      let key = bomTitle[item.c];
+      if (!bomData[item.r - 1]) {
+        bomData[item.r - 1] = {};
+      }
+      bomData[item.r - 1][key] = v;
+    }
+  });
+  let category = {
+    'GT-UF膜': 0,
+    原平制造: 0,
+    其它膜: 0,
+    水泵: 0,
+    阀门: 0,
+    加药系统: 0,
+    过滤器: 0,
+    空压机: 0,
+    非标: 0,
+    仪表: 0,
+    电气自控: 0,
+    双胞胎硬件: 0,
+    材料: 0,
+    安装: 0,
+    土建: 0,
+    运输: 0,
+    其它: 0,
+  };
+  bomData.forEach(item => {
+    if (category.hasOwnProperty(item['类别'])) {
+      let price = parseFloat(item['总价(元)']);
+      if (isNaN(price)) return;
+      category[item['类别']] += price;
+    }
+  });
+  return category;
+}
+
+// 处理现金流表
+function initActual(actual, category, projectName) {
+  let actualCategory = [];
+  actual.celldata.forEach((item, i, celldata) => {
+    if (item.c == 0 && item.v?.v) {
+      // 处理序号转float出现多余小数的情况
+      item.v.v = formatNumber(item.v?.v);
+    }
+    if (item.c == 1 && item.r == 0) item.v.v = projectName;
+    // 清单分类的总价填入对应预算列
+    if (item.c == 2) {
+      // c=2 为名称列
+      let value = getCellValue(item.v);
+      // 判断该行是否为类型总列
+      if (category.hasOwnProperty('value')) {
+        // 名称后第三列为预算列
+        celldata[i + 3].v.v = category[value];
+      }
+    }
+  });
+}
+
+// 处理毛利概算表
+function initEstimate(estimate, category) {
+  estimate.celldata.forEach(item => {
+    if (item.r == 15 && item.c == 2) {
+      // 金科制造中心-UF膜
+      item.v.v = category['GT-UF膜'];
+    } else if (item.r == 14 && item.c == 2) {
+      // 金科制造中心设备制造费
+      item.v.v = category['原平制造'];
+    } else if (item.r == 16 && item.c == 2) {
+      // 设备购置费
+      item.v.v =
+        category['其它膜'] +
+        category['水泵'] +
+        category['阀门'] +
+        category['加药系统'] +
+        category['过滤器'] +
+        category['空压机'] +
+        category['非标'] +
+        category['仪表'] +
+        category['电气自控'] +
+        category['材料'] +
+        category['运输'] +
+        category['其它'];
+    } else if (item.r == 18 && item.c == 2) {
+      // 数字双胞胎
+      item.v.v = category['双胞胎硬件'];
+    } else if (item.r == 19 && item.c == 2) {
+      // 安装
+      item.v.v = category['安装'];
+    } else if (item.r == 20 && item.c == 2) {
+      // 土建
+      item.v.v = category['土建'];
+    }
+  });
+}
+
+// 处理PSR表预算
+function initPSR(psr, category) {
+  psr.celldata.forEach(item => {
+    if (item.r == 39 && item.c == 3) {
+      item.v.v = category['GT-UF膜'];
+    } else if (item.r == 38 && item.c == 3) {
+      item.v.v = category['原平制造'];
+    } else if (item.r == 37 && item.c == 3) {
+      item.v.v =
+        category['其它膜'] +
+        category['水泵'] +
+        category['阀门'] +
+        category['加药系统'] +
+        category['过滤器'] +
+        category['空压机'] +
+        category['非标'] +
+        category['仪表'] +
+        category['电气自控'] +
+        category['材料'] +
+        category['运输'] +
+        category['其它'];
+    } else if (item.r == 40 && item.c == 3) {
+      item.v.v = category['双胞胎硬件'];
+    } else if (item.r == 41 && item.c == 3) {
+      item.v.v = category['安装'];
+    } else if (item.r == 42 && item.c == 3) {
+      item.v.v = category['土建'];
+    }
+  });
+}
+
+export default uploadExcelByUrl;