Browse Source

psr提交

xjj 1 year ago
parent
commit
879efcf1ec
4 changed files with 265 additions and 123 deletions
  1. 103 52
      src/pages/Detail/CommitAuditModal.js
  2. 85 0
      src/pages/Psr/index.js
  3. 0 0
      src/pages/Temp/excel_json.json
  4. 77 71
      src/pages/Temp/index.js

+ 103 - 52
src/pages/Detail/CommitAuditModal.js

@@ -40,6 +40,8 @@ import ApprovalProcess from './ApprovalProcess';
 import { uuidv4 } from '@antv/xflow';
 import { uuidv4 } from '@antv/xflow';
 import AliyunOSSUpload from '@/components/OssUpload/AliyunOssUploader';
 import AliyunOSSUpload from '@/components/OssUpload/AliyunOssUploader';
 import AttachmentTable from '@/components/AttachmentTable';
 import AttachmentTable from '@/components/AttachmentTable';
+import { getToken } from '@/utils/utils';
+import LuckyExcel from 'luckyexcel';
 
 
 const { TextArea } = Input;
 const { TextArea } = Input;
 const { Option } = Select;
 const { Option } = Select;
@@ -52,7 +54,7 @@ function CommitAuditModal(props) {
     dispatch,
     dispatch,
     visible,
     visible,
     onClose,
     onClose,
-    loading,
+    // loading,
     version,
     version,
     versionList,
     versionList,
     flowDetail,
     flowDetail,
@@ -75,6 +77,7 @@ function CommitAuditModal(props) {
   const [curNodeIdx, setCurNodeIdx] = useState(-1);
   const [curNodeIdx, setCurNodeIdx] = useState(-1);
 
 
   const [dataSource, setDataSource] = useState([]);
   const [dataSource, setDataSource] = useState([]);
+  const [loading, setLoading] = useState(false);
   const uploadList = useRef([]);
   const uploadList = useRef([]);
 
 
   useEffect(() => {
   useEffect(() => {
@@ -484,63 +487,74 @@ function CommitAuditModal(props) {
     }
     }
 
 
     const flowPath = result.map(item => getFlowPath(item));
     const flowPath = result.map(item => getFlowPath(item));
-    const formList = await getFromData(result);
-    let params = {
-      desc: fieldsValue.desc,
-      // 审核流程id
-      // flow_id: approvalNode?.flow_id || 0,
-      // node_level_id: approvalNode?.flow_id ? 1 : 0,
-
-      id: version.id,
-      project_id: version.project_id,
-      cur_template_node_id: version.template_node_id * 1, // 当前节点
-      next_template_node_id: serviceNode.Id * 1, // 审核完成后的业务节点
-      // template_node_id: result[0][0], // 将要流转的节点审批节点
-      // flow_path:flow_path, //审批节点数组
-      // 模板id.一致就行
-      template_id: version.template_id,
-      cur_template_id: version.template_id,
-      next_template_id: version.template_id,
-    };
-    if (result.length <= 0) {
-      //直接走业务节点
-    } else if (result.length <= 1 && result[0]?.length <= 1) {
-      //单个审批节点
-      let approvalNode = flowDetail.nodes.find?.(item => item.Id == result[0][0]);
-      params.flow_id = approvalNode?.flow_id || 0;
-      params.node_level_id = approvalNode?.flow_id ? 1 : 0;
-      params.template_node_id = result[0][0]; // 将要流转的节点审批节点
-      params.form_list = formList; //创建钉钉表单所需数据
-      if (approvalNode?.Id) {
-        if (!approvalNode?.flow_id) {
-          hasFlowId = false;
+    setLoading(true);
+    try {
+      const formList = await getFromData(result);
+      let params = {
+        desc: fieldsValue.desc,
+        // 审核流程id
+        // flow_id: approvalNode?.flow_id || 0,
+        // node_level_id: approvalNode?.flow_id ? 1 : 0,
+
+        id: version.id,
+        project_id: version.project_id,
+        cur_template_node_id: version.template_node_id * 1, // 当前节点
+        next_template_node_id: serviceNode.Id * 1, // 审核完成后的业务节点
+        // template_node_id: result[0][0], // 将要流转的节点审批节点
+        // flow_path:flow_path, //审批节点数组
+        // 模板id.一致就行
+        template_id: version.template_id,
+        cur_template_id: version.template_id,
+        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);
+      // }
+      params.data = await uploadExcelByUrl(3, version.id);
+      console.log(params);
+
+      if (result.length <= 0) {
+        //直接走业务节点
+      } else if (result.length <= 1 && result[0]?.length <= 1) {
+        //单个审批节点
+        let approvalNode = flowDetail.nodes.find?.(item => item.Id == result[0][0]);
+        params.flow_id = approvalNode?.flow_id || 0;
+        params.node_level_id = approvalNode?.flow_id ? 1 : 0;
+        params.template_node_id = result[0][0]; // 将要流转的节点审批节点
+        params.form_list = formList; //创建钉钉表单所需数据
+        if (approvalNode?.Id) {
+          if (!approvalNode?.flow_id) {
+            hasFlowId = false;
+          }
         }
         }
+      } else {
+        //多节点审批
+        params.template_node_id = result[0][0]; // 将要流转的节点审批节点
+        params.flow_path = flowPath;
+        params.form_list = formList; //创建钉钉表单所需数据
       }
       }
-    } else {
-      //多节点审批
-      params.template_node_id = result[0][0]; // 将要流转的节点审批节点
-      params.flow_path = flowPath;
-      params.form_list = formList; //创建钉钉表单所需数据
-    }
-    if (!hasFlowId) {
-      message.error('当前存在审批节点未绑定审批流程!请联系管理员。');
-      return;
+      if (!hasFlowId) {
+        message.error('当前存在审批节点未绑定审批流程!请联系管理员。');
+        return;
+      }
+      await querySaveBomForm({
+        project_id: version.project_id,
+        node_id: version.template_node_id,
+        json: JSON.stringify({ approvalProcess }),
+      });
+      params.audit_series = uuidv4();
+      params.files = uploadList.current.join(',');
+      onSubmitNextNode(params);
+    } catch (error) {
+      console.error(error);
     }
     }
-    await querySaveBomForm({
-      project_id: version.project_id,
-      node_id: version.template_node_id,
-      json: JSON.stringify({ approvalProcess }),
-    });
-    params.audit_series = uuidv4();
-    params.files = uploadList.current.join(',');
-    console.log(params);
-    onSubmitNextNode(params);
   };
   };
   const onSubmitNextNode = values => {
   const onSubmitNextNode = values => {
     dispatch({
     dispatch({
       type: 'detail/submitNextNode',
       type: 'detail/submitNextNode',
       payload: values,
       payload: values,
       callback: newVersion => {
       callback: newVersion => {
+        setLoading(false);
         onClose();
         onClose();
         // 更新flow流程图
         // 更新flow流程图
         dispatch({
         dispatch({
@@ -609,7 +623,7 @@ function CommitAuditModal(props) {
 
 
   return (
   return (
     <Modal
     <Modal
-      confirmLoading={loading.global}
+      confirmLoading={loading}
       destroyOnClose
       destroyOnClose
       title="提交流转目标"
       title="提交流转目标"
       width={1000}
       width={1000}
@@ -680,12 +694,49 @@ function getDataValue(item) {
   }
   }
   return arr;
   return arr;
 }
 }
+const uploadExcelByUrl = (nodeType, versionId) => {
+  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';
+  const TEMPLATE_URL2 =
+    'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/psr.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;
+        record.order = len - 1;
+        record.index = String(len);
+        record.status = '0';
+        record.name = '投标成本';
+        var res = [...exportJson.sheets, 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, loading }) => ({
+export default connect(({ xflow, detail, user }) => ({
   flowDetail: xflow.flowDetail,
   flowDetail: xflow.flowDetail,
   versionList: detail.versionList,
   versionList: detail.versionList,
   currentUser: user.currentUser,
   currentUser: user.currentUser,
   userList: user.list,
   userList: user.list,
   OSSData: detail.OSSData,
   OSSData: detail.OSSData,
-  loading,
 }))(CommitAuditModal);
 }))(CommitAuditModal);

+ 85 - 0
src/pages/Psr/index.js

@@ -0,0 +1,85 @@
+import { queryRecordSheet } from '@/services/boom';
+import LuckySheet from '../Detail/LuckySheet';
+import react, { useRef } from 'react';
+import LuckyExcel from 'luckyexcel';
+import { Button, message } from 'antd';
+
+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';
+const TEMPLATE_URL2 = 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/psr.xlsx';
+
+function Index(props) {
+  const { versionId = 2418 } = props;
+
+  const sheetRef = useRef();
+  const luckysheetRef = useRef();
+
+  const uploadExcelByUrl = type => {
+    LuckyExcel.transformExcelToLuckyByUrl(
+      type == 1 ? TEMPLATE_URL : TEMPLATE_URL2,
+      '模板.xlsx',
+      async (exportJson, luckysheetfile) => {
+        let record = await getExcel(versionId);
+        console.log(record);
+
+        luckysheetRef.current.destroy();
+
+        luckysheetRef.current.create({
+          lang: 'zh',
+          showinfobar: false,
+          showstatisticBar: false,
+          data: [...exportJson.sheets, ...record],
+          hook: {
+            cellMousedown: (cell, position, sheet) => {
+              console.log(cell, position, sheet);
+            },
+            cellUpdated: () => {
+              luckysheetRef.current.refreshFormula();
+            },
+          },
+        });
+      }
+    );
+  };
+
+  const handleLoad = () => {
+    let contentWindow = sheetRef.current.contentWindow;
+    luckysheetRef.current = contentWindow.luckysheet;
+  };
+
+  return (
+    <div>
+      <Button type="primary" onClick={() => uploadExcelByUrl(1)}>
+        导入投标投标
+      </Button>
+      <Button type="primary" onClick={() => uploadExcelByUrl(2)}>
+        导入合同模板
+      </Button>
+
+      <iframe
+        style={{
+          width: '100%',
+          height: '80vh',
+        }}
+        ref={sheetRef}
+        onLoad={handleLoad}
+        src="/luckysheet.html"
+      ></iframe>
+    </div>
+  );
+}
+
+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;

File diff suppressed because it is too large
+ 0 - 0
src/pages/Temp/excel_json.json


+ 77 - 71
src/pages/Temp/index.js

@@ -1,58 +1,56 @@
+import { queryRecordSheet } from '@/services/boom';
+import LuckySheet from '../Detail/LuckySheet';
 import react, { useRef } from 'react';
 import react, { useRef } from 'react';
 import LuckyExcel from 'luckyexcel';
 import LuckyExcel from 'luckyexcel';
-import { message } from 'antd';
+import { Button, message } from 'antd';
+import { getToken } from '@/utils/utils';
+import moment from 'moment';
+
+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';
+
+const TEMPLATE_URL2 = 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/psr.xlsx';
+
+function Index(props) {
+  const { versionId = 2376 } = props;
 
 
-function Index() {
   const sheetRef = useRef();
   const sheetRef = useRef();
   const luckysheetRef = useRef();
   const luckysheetRef = useRef();
-  /**
-   * 导入excl
-   * @param {*} files input:file的evt.target.files
-   * @returns
-   */
-  const uploadExcel = files => {
-    if (files == null || files.length == 0) {
-      return;
-    }
 
 
-    let name = files[0].name;
-    let suffixArr = name.split('.'),
-      suffix = suffixArr[suffixArr.length - 1];
-    if (suffix != 'xlsx') {
-      message.error('只支持xlsx格式的文件!');
-      return;
-    }
-    LuckyExcel.transformExcelToLucky(files[0], (exportJson, luckysheetfile) => {
-      if (exportJson.sheets == null || exportJson.sheets.length == 0) {
-        message.error('读取xlsx文件失败!');
-        return;
-      }
-      // this.luckysheet.destroy();
-      // 同步当前文档内容
-      let cell = [];
-      exportJson.sheets.forEach(sheet => {
-        let titleCell = [];
-        sheet.celldata.forEach(item => {
-          if (item.r == 0) {
-            // 标题头
-            titleCell.push(item);
-          }
-          // 生成cid
-          item.v.cid = `${item.r}-${item.c}`;
-        });
-        let tempCell = titleCell.map(item => {
-          let value = '';
-          if (item.v?.v) {
-            value = item.v?.v;
-          } else if (item.v.ct?.s && item.v.ct?.s instanceof Array) {
-            value = item.v.ct.s.map(item => item?.v).join?.('');
-          }
-          return { sheet_name: sheet.name, col_idx: item.r, col_axis: item.c, col_value: value };
+  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();
+            },
+          },
         });
         });
-        cell = [...cell, ...tempCell];
-      });
-      renderSheet(exportJson.sheets);
-    });
+      }
+    );
   };
   };
 
 
   const handleLoad = () => {
   const handleLoad = () => {
@@ -60,33 +58,28 @@ function Index() {
     luckysheetRef.current = contentWindow.luckysheet;
     luckysheetRef.current = contentWindow.luckysheet;
   };
   };
 
 
-  const renderSheet = currentData => {
-    const data = currentData;
-    let option = {
-      lang: 'zh',
-      showinfobar: false,
-      showstatisticBar: false,
-      data: JSON.parse(JSON.stringify(data)),
-      hook: {
-        cellMousedown: (cell, position, sheet) => {
-          console.log(cell, position, sheet);
-        },
-        cellUpdated: () => {
-          luckysheetRef.current.refreshFormula();
-        },
-      },
-    };
-
-    luckysheetRef.current.destroy();
-    luckysheetRef.current.create(option);
-    setTimeout(() => {
-      luckysheetRef.current.setCellFormat(0, 0, 'bg', '#fff');
-    }, 500);
+  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 (
   return (
     <div>
     <div>
-      <input type="file" onChange={e => uploadExcel(e.target.files)} />
+      <Button type="primary" style={{ marginRight: 20 }} onClick={() => uploadExcelByUrl(1)}>
+        导入投标投标
+      </Button>
+      <Button type="primary" onClick={() => uploadExcelByUrl(2)}>
+        导入合同模板
+      </Button>
+
       <iframe
       <iframe
         style={{
         style={{
           width: '100%',
           width: '100%',
@@ -100,4 +93,17 @@ function Index() {
   );
   );
 }
 }
 
 
+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;
 export default Index;

Some files were not shown because too many files changed in this diff