ZhaoJun 1 anno fa
parent
commit
34c34630b2

+ 15 - 8
src/pages/Detail/CommitAuditModal.js

@@ -159,7 +159,7 @@ function CommitAuditModal(props) {
       const formList = JSON.parse(res.data.json);
       setApprovalProcess(formList.approvalProcess || {});
       const temp = formList.formList;
-      const prevFormData = JSON.parse(temp && temp.length ? temp : '{}');
+      const prevFormData = (temp && temp.length) ? temp.map(tempItem => JSON.parse(tempItem)) : [];
       setFormComponentValues(prevFormData);
       return formList;
     }
@@ -260,11 +260,12 @@ function CommitAuditModal(props) {
     // 加载之前提交的form数据
     const resFormData = await initFormList();
     const resData = resFormData?.formList;
-    const prevFormData = resData && resData.length ? JSON.parse(resData[0]) : null;
+
+    const prevFormData = resData && resData.length ? resData.map(resItem => JSON.parse(resItem)) : null;
     if (value) {
       changeAudit(value[value.length - 1]);
-      if (prevFormData !== null && prevFormData?.formComponentValues?.length && value[0] === prevFormData?.template_node_id) {
-        setAuditListFun(approvalProcess, prevFormData.formComponentValues);
+      if (prevFormData !== null) {
+        setAuditListFun(approvalProcess, prevFormData);
       } else {
         setAuditListFun(approvalProcess);
       }
@@ -356,9 +357,12 @@ function CommitAuditModal(props) {
     addAuditList.forEach((item, index) => {
       // 回填历史数据
       if (prevFormData.length) {
-        item.items.forEach(DDComponent => {
-          const prevValue = prevFormData.find(pItem => pItem.id === DDComponent.props.id)
-          DDComponent.props.defaultValue = prevValue.value
+        const currentForm = prevFormData.find(pItem=>pItem.template_node_id===item.nodeId);
+        item.items.forEach((DDComponent) => {
+          console.log(currentForm, DDComponent)
+          const prevValue = currentForm?.formComponentValues?.find(cItem => cItem.id === DDComponent.props.id)
+          // console.log(prevValue)
+          DDComponent.props.defaultValue = prevValue?.value || prevValue?.defaultValue
         })
       }
       let Components = Form3x.create({
@@ -414,7 +418,8 @@ function CommitAuditModal(props) {
     firstList.forEach(id => {
       let approvalNode = flowDetail.nodes.find?.(item => item.Id == id);
       if (!approvalNode) return;
-      let values = data[approvalNode.Id] || [];
+      const prevValues = data.length ? data.find((item)=>item.template_node_id === approvalNode.Id).formComponentValues : []
+      let values = data[approvalNode.Id] || prevValues ||  [];
       let audit_list = [],
         cc_list = [];
       approvalProcess[approvalNode.Id]?.forEach(item => {
@@ -422,6 +427,7 @@ function CommitAuditModal(props) {
         if (item[0].type == 'role') return arr.push(item[0].nowValue);
         return arr.push(item[0].value);
       });
+      console.log(values)
       const formItem = {
         flow_id: approvalNode.flow_id,
         template_node_id: approvalNode.Id,
@@ -563,6 +569,7 @@ function CommitAuditModal(props) {
         message.error('当前存在审批节点未绑定审批流程!请联系管理员。');
         return;
       }
+      debugger
       await querySaveBomForm({
         project_id: version.project_id,
         node_id: version.template_node_id,

+ 41 - 18
src/pages/Detail/FlowModal.js

@@ -319,25 +319,43 @@ function FlowModal(props) {
     setInputValue(null);
   };
 
-  const getDescription = node => {
+  function calculateHoursDifference(date1, date2) {
+    const timestamp1 = date1.getTime(); // 获取第一个Date对象的时间戳(以毫秒为单位)
+    const timestamp2 = date2.getTime(); // 获取第二个Date对象的时间戳(以毫秒为单位)
+
+    const timeDifferenceInMillis = Math.abs(timestamp2 - timestamp1); // 计算时间戳之间的差值(毫秒数)
+    const hoursDifference = timeDifferenceInMillis / (1000 * 60 * 60); // 将差值转换为小时数
+
+    return hoursDifference.toFixed(2);
+  }
+
+  const getDescription = (node, prevNode) => {
     let str = `审批人:${node.AuditorUser?.CName || '-'}`;
     const date = new Date(node.audit_time)
-    const auditTime = date.toLocaleDateString('zh-CN', {
+    const auditTime = node.audit_time === '0001-01-01T00:00:00Z' ? '-' : date.toLocaleDateString('zh-CN', {
       format: 'YYYY-MM-DD hh:mm:ss'
     })
-    return (<div>
-      审批人:{node.AuditorUser?.CName || '-'}
+    const residenceTime = auditTime === '-' ? '-' : calculateHoursDifference(date, new Date(prevNode.audit_time))
+    return (
       <div>
-        <span style={{color: '#1A73E8', textDecoration: 'undeline'}}>
+        审批人:{node.AuditorUser?.CName || '-'}
+        <div>
+          <span style={{color: '#1A73E8', textDecoration: 'unerline'}}>
             审批意见:{node.desc || '-'}
-        </span>
-      </div>
-      <div>
-        <span>
-          审批时间:{auditTime || '-'}
-        </span>
+          </span>
+        </div>
+        <div>
+          <span>
+            审批时间:{auditTime || '-'}
+          </span>
+        </div>
+        <div>
+          <span>
+            滞留时间:{`${residenceTime}小时`}
+          </span>
+        </div>
       </div>
-    </div>);
+    );
   };
 
   const filterState = () => {
@@ -500,7 +518,7 @@ function FlowModal(props) {
               display: 'flex', justifyContent: 'space-around', maxHeight: '300px', overflow: 'auto',
             }}
           >
-            {stepsData.map((item, idx) => (
+            {stepsData.length && stepsData.map((item, idx) => (
               <div key={`${item.name}_${idx}`} style={{marginTop: '20px', display: 'inline'}}>
                 <div style={{marginBottom: '4px'}}>{item.name}</div>
                 <Steps
@@ -509,11 +527,16 @@ function FlowModal(props) {
                   current={item.current}
                   status={item.status}
                 >
-                  {item.list.map(node => (<Step
-                    key={`${node.id}_${node.node}`}
-                    title={node.node}
-                    description={getDescription(node)}
-                  />))}
+                  {item.list.reduce((prev, node) =>
+                    (
+                      <Step
+                        key={`${node.id}_${node.node}`}
+                        title={node.node}
+                        description={getDescription(node, prev)}
+                      />
+                    )
+                  )
+                  }
                 </Steps>
               </div>))}
           </div>

+ 3 - 2
src/pages/Detail/Index.js

@@ -91,7 +91,8 @@ function Detail(props) {
   const cellPosition = useRef({});
 
   useEffect(() => {
-    //不请求excelFileList 时清空excelFileList,否则会出现清单切换后如果attachment_id不存在,附件信息没有更新
+    // if (!version.id) return
+    // 不请求excelFileList 时清空excelFileList,否则会出现清单切换后如果attachment_id不存在,附件信息没有更新
     if (!version.attachment_id) {
       dispatch({
         type: 'detail/save',
@@ -644,7 +645,7 @@ function Detail(props) {
             display: 'inline',
             marginLeft: '20px',
           }}
-        ></TimeNode>
+        />
       </div>
 
       <CommentContent

+ 24 - 6
src/pages/Detail/TimeNode.js

@@ -25,15 +25,28 @@ function TimeNode(props) {
     currentUser,
   } = props;
   const {current, list, active} = flow;
+  console.log(list.FlowNodes)
 
-  const getDescription = node => {
+
+  function calculateHoursDifference(date1, date2) {
+    const timestamp1 = date1.getTime(); // 获取第一个Date对象的时间戳(以毫秒为单位)
+    const timestamp2 = date2.getTime(); // 获取第二个Date对象的时间戳(以毫秒为单位)
+
+    const timeDifferenceInMillis = Math.abs(timestamp2 - timestamp1); // 计算时间戳之间的差值(毫秒数)
+    const hoursDifference = timeDifferenceInMillis / (1000 * 60 * 60); // 将差值转换为小时数
+
+    return hoursDifference.toFixed(2);
+  }
+
+  const getDescription = (node, prevNode) => {
     let str = node?.AuditRoleInfo
       ? `审批人:${node?.AuditRoleInfo.Name || '-'}`
       : `审批人:${node?.AuditorUser.CName || '-'}`;
     const date = new Date(node.audit_time)
-    const auditTime = date.toLocaleDateString('zh-CN', {
+    const auditTime = node.audit_time === '0001-01-01T00:00:00Z' ? '-' : date.toLocaleDateString('zh-CN', {
       format: 'YYYY-MM-DD hh:mm:ss'
     })
+    // const residenceTime = auditTime === '-' ? '-' : calculateHoursDifference(date, new Date(prevNode.audit_time))
     return (
       <div>
         {str}
@@ -44,9 +57,14 @@ function TimeNode(props) {
         </div>
         <div>
           <span>
-            审批时间:{auditTime || '-'}
+            审批时间:{auditTime}
           </span>
         </div>
+        {/* <div> */}
+        {/*   <span> */}
+        {/*     滞留时间:{`${residenceTime}小时`} */}
+        {/*   </span> */}
+        {/* </div> */}
       </div>
     );
 
@@ -61,9 +79,9 @@ function TimeNode(props) {
           current={current}
           status={active == 0 ? 'error' : 'process'}
         >
-          {list.FlowNodes.map(item => (
-            <Step key={item.id} title={item.node} description={getDescription(item)}/>
-          ))}
+          {list.FlowNodes.map(( item) => {
+            return <Step key={item.id} title={item.node} description={getDescription(item)} />
+          })}
         </Steps>
         {isAuditor && active != 0 && (
           <div className={styles.btns} style={{margin: '40px 0'}}>

+ 13 - 9
src/pages/List/List.js

@@ -44,9 +44,12 @@ function List(props) {
     {
       title: '所属项目',
       dataIndex: 'project_id',
-      render: project_id => {
-        let p = project.list.find(p => p.id == project_id);
-        if (p) return `${p.project_name}(${p.project_full_code})`;
+      render: projectID => {
+        const p = project.list.find(pItem => pItem.id === projectID);
+        if (p) {
+          return `${p.project_name}(${p.project_full_code})`;
+        }
+        return ''
       },
     },
     {
@@ -105,6 +108,7 @@ function List(props) {
       ),
     },
   ];
+
   const queryList = filter => {
     filter = {...filterRes.current, ...filter};
     dispatch({
@@ -142,16 +146,16 @@ function List(props) {
   }, []);
 
   const changeVersion = item => {
-    if (typeof item == 'object') {
+    if (typeof item === 'object') {
       localStorage.excelItem = JSON.stringify(item);
     }
     router.push(`/home/detail/${item.project_id}/${item.template_id}?version_id=${item.version_id}`);
   };
 
-  const getLoading = () => {
-    let effects = loadingVersion.effects;
-    return !loadingVersion.effects['detail/queryComment'] && loadingVersion.models.detail;
-  };
+  // const getLoading = () => {
+  //   let effects = loadingVersion.effects;
+  //   return !loadingVersion.effects['detail/queryComment'] && loadingVersion.models.detail;
+  // };
 
   const onCommit = async (values, callback) => {
     setCommitLoading(true);
@@ -167,7 +171,7 @@ function List(props) {
       callback: async newVersion => {
         // 更新flow流程图
         const data = await queryBoomFlowDetail({id: newVersion.template_id});
-        console.log(data);
+        // console.log(data);
         setFlowDetail(data);
         setCommitLoading(false);
         callback && callback();