xujunjie 2 vuotta sitten
vanhempi
commit
6b07a1fe60

+ 115 - 30
src/pages/PurchaseAdmin/PurchaseList/Detail/AuditFlow.js

@@ -2,38 +2,22 @@ import React, { useMemo, useEffect, useState, useRef } from 'react';
 import { Steps, Popover, Alert } from 'antd';
 import styles from './Index.less';
 import { queryDDProcessesForecast } from '@/services/boom';
+import { connect } from 'dva';
 
 const { Step } = Steps;
 
-const ACTOR_TYPE = {
-  approver: '审批人',
-  notifier: '抄送人',
-  audit: '办理人',
-};
-const APPROVAL_TYPE = {
-  MANUAL: '人工审批',
-  AUTO_AGREE: '自动通过',
-  AUTO_REFUSE: '自动拒绝',
-};
-const APPROVAL_METHOD = {
-  ONE_BY_ONE: '依次审批',
-  AND: '会签审批',
-  OR: '或签审批',
-};
-const ACTIVITY_TYPE = {
-  target_select: '自选审批人',
-  target_approval: '指定审批人',
-};
-
 function AuditFlow(props) {
   const {
     processCode,
-    deptId = '14169890',
-    userId = '16569001414345099',
+    deptId,
+    userId,
     formComponentValues,
-    activityId,
+    // activityId,
     direction,
     status,
+    tasks,
+    userList,
+    cc_userids = [],
   } = props;
   const [flow, setFlow] = useState({ workflowActivityRules: [] });
   const timerRef = useRef({
@@ -41,15 +25,56 @@ function AuditFlow(props) {
     status: false,
   });
   const current = useMemo(() => {
-    if (!activityId) {
+    if (!tasks || tasks.length == 0) {
       return flow.workflowActivityRules.length;
     } else {
-      return flow.workflowActivityRules.findIndex(item => item.activityId == activityId);
+      // 查询最后一个task的activityId
+      let current = 0;
+      const activityId = tasks[tasks.length - 1].activity_id;
+      flow.workflowActivityRules.forEach((item, index) => {
+        if (tasks.find(task => task.activity_id == item.activityId)) {
+          current = index;
+        }
+        // 判断是否只剩抄送节点未被选中
+        if (item.activityName == '抄送人' && current == index - 1) {
+          current = index;
+        }
+      });
+      return current;
     }
-  }, [activityId, flow]);
+  }, [tasks, flow]);
 
-  const renderDesc = item => {
-    return <></>;
+  const getDesc = item => {
+    const { activityId } = item;
+    if (!tasks || tasks.length == 0) return;
+    if (item.activityName == '抄送人') {
+      let names = cc_userids
+        .map(userId => {
+          let user = userList.find(u => u.DingUserId == userId);
+          return user?.CName;
+        })
+        .filter(item => item);
+      return names.join(',');
+    } else {
+      const task = tasks.find(task => task.activity_id == activityId);
+      if (!task) return;
+      const user = userList.find(user => task.userid == user.DingUserId);
+      let result = null;
+      if (task.task_result !== 'NONE') {
+        result = (
+          <>
+            <br />
+            结果: {TASK_RESULT[task.task_result]}
+            <br />
+          </>
+        );
+      }
+      return (
+        <>
+          {user?.CName || '未知操作人'}({TASK_STATUS[task.task_status]}){result}
+        </>
+      );
+    }
   };
   const renderAlert = () => {
     // const audit_comment = history.list[0]?.audit_comment;
@@ -95,6 +120,10 @@ function AuditFlow(props) {
   };
 
   const getDetail = async () => {
+    if (!deptId || !userId) {
+      console.error('depId或userId不存在!');
+      return;
+    }
     if (!timerRef.current.status) {
       // 上锁
       timerRef.current.status = true;
@@ -130,7 +159,7 @@ function AuditFlow(props) {
       <div className={styles.top}>
         <Steps current={current} progressDot={customDot} direction={direction}>
           {flow.workflowActivityRules.map(item => (
-            <Step key={item.activityId} title={item?.activityName} />
+            <Step key={item.activityId} title={item?.activityName} description={getDesc(item)} />
           ))}
           {/* <Step key={item.activityId} title={item?.activityName} description={renderDesc(item)} /> */}
         </Steps>
@@ -140,4 +169,60 @@ function AuditFlow(props) {
   );
 }
 
-export default AuditFlow;
+const ACTOR_TYPE = {
+  approver: '审批人',
+  notifier: '抄送人',
+  audit: '办理人',
+};
+const APPROVAL_TYPE = {
+  MANUAL: '人工审批',
+  AUTO_AGREE: '自动通过',
+  AUTO_REFUSE: '自动拒绝',
+};
+const APPROVAL_METHOD = {
+  ONE_BY_ONE: '依次审批',
+  AND: '会签审批',
+  OR: '或签审批',
+};
+const ACTIVITY_TYPE = {
+  target_select: '自选审批人',
+  target_approval: '指定审批人',
+};
+const OPERATION_RESULT = {
+  AGREE: '同意',
+  REFUSE: '拒绝',
+  NONE: '未处理',
+};
+const OPERATION_TYPE = {
+  EXECUTE_TASK_NORMAL: '正常执行任务',
+  EXECUTE_TASK_AGENT: '代理人执行任务',
+  APPEND_TASK_BEFORE: '前加签任务',
+  APPEND_TASK_AFTER: '后加签任务',
+  REDIRECT_TASK: '转交任务',
+  START_PROCESS_INSTANCE: '发起流程实例',
+  TERMINATE_PROCESS_INSTANCE: '终止(撤销)流程实例',
+  FINISH_PROCESS_INSTANCE: '结束流程实例',
+  ADD_REMARK: '添加评论',
+  REDIRECT_PROCESS: '审批退回',
+  PROCESS_CC: '抄送',
+};
+
+const TASK_STATUS = {
+  NEW: '未启动',
+  RUNNING: '处理中',
+  PAUSED: '暂停',
+  CANCELED: '取消',
+  COMPLETED: '完成',
+  TERMINATED: '终止',
+};
+
+const TASK_RESULT = {
+  AGREE: '同意',
+  REFUSE: '拒绝',
+  REDIRECTED: '转交',
+  NONE: '未处理',
+};
+
+export default connect(({ user }) => ({
+  userList: user.list,
+}))(AuditFlow);

+ 14 - 7
src/pages/PurchaseAdmin/PurchaseList/Detail/Index.js

@@ -85,19 +85,24 @@ function Detail(props) {
     let data = {
       processCode: '',
       deptId: '14169890',
+      tasks: [],
       // userId: '16569001414345099',
       // deptId: currentUser.DingDepId || getCurrentUser()?.DingDepId,
       userId: currentUser.DingUserId || getCurrentUser()?.DingUserId,
       formComponentValues: [],
       activityId: '',
+      cc_userids: [],
       status: version.audit_status,
     };
     if (version?.flow_id && instanceDetail?.tasks && instanceDetail.tasks?.length > 0) {
       let item = flowDetail.nodes.find(item => item.Id == version.template_node_id);
       if (!item) return data;
-      const { tasks, form_component_values } = instanceDetail;
+      const { tasks, form_component_values, cc_userids } = instanceDetail;
       data.processCode = item.process_code;
       data.activityId = tasks[tasks.length - 1]?.activity_id;
+      data.tasks = tasks || [];
+      debugger;
+      data.cc_userids = cc_userids;
       data.formComponentValues = form_component_values?.filter(item => item.name);
     }
     return data;
@@ -953,12 +958,14 @@ function Detail(props) {
       {/* <TimeNode flow={flow} isAuditor={isAuditor} onApprove={onApprove}></TimeNode> */}
       {version.flow_id ? (
         <AuditFlow
-          status={auditDetail.status}
-          processCode={auditDetail.processCode}
-          deptId={auditDetail.deptId}
-          userId={auditDetail.userId}
-          activityId={auditDetail.activityId}
-          formComponentValues={auditDetail.formComponentValues}
+          {...auditDetail}
+          // status={auditDetail.status}
+          // processCode={auditDetail.processCode}
+          // deptId={auditDetail.deptId}
+          // userId={auditDetail.userId}
+          // tasks={auditDetail.tasks}
+          // cc_userids={auditDetail.cc_userids}
+          // formComponentValues={auditDetail.formComponentValues}
         />
       ) : null}
       {/* {renderAlert()} */}