xujunjie 2 vuotta sitten
vanhempi
commit
7a2fabd573

+ 1 - 1
src/components/DDComponents/DDMultiSelectField/index.js

@@ -22,7 +22,7 @@ function DDSelectField(props) {
         }
 
         return (
-          <Option key={cur.key} value={cur.key}>
+          <Option key={cur.key} value={cur.value}>
             {cur.value}
           </Option>
         );

+ 1 - 1
src/components/DDComponents/index.js

@@ -62,7 +62,7 @@ export default function DDComponents(props) {
             }
 
             return (
-              <Option key={cur.key} value={cur.key}>
+              <Option key={cur.key} value={cur.value}>
                 {cur.value}
               </Option>
             );

+ 27 - 77
src/pages/PurchaseAdmin/PurchaseList/Detail/AuditFlow.js

@@ -1,5 +1,5 @@
-import React, { useMemo } from 'react';
-import { Steps } from 'antd';
+import React, { useMemo, useEffect, useState, useRef } from 'react';
+import { Steps, Popover } from 'antd';
 import styles from './Index.less';
 import { queryDDProcessesForecast } from '@/services/boom';
 
@@ -25,11 +25,6 @@ const ACTIVITY_TYPE = {
   target_approval: '指定审批人',
 };
 
-let timer = {
-  id: '',
-  status: false,
-};
-
 function AuditFlow(props) {
   const {
     processCode,
@@ -39,64 +34,11 @@ function AuditFlow(props) {
     activityId,
     direction,
   } = props;
-  const flow = {
-    workflowActivityRules: [
-      {
-        activityId: 'xi0m_sJzp',
-        prevActivityId: 'sid-startevent',
-        workflowActor: {
-          actorType: 'approver',
-          approvalType: 'MANUAL',
-          actorActivateType: 'ONE_BY_ONE',
-          approvalMethod: 'ONE_BY_ONE',
-          allowedMulti: true,
-          actorSelectionRange: {},
-          required: false,
-        },
-        isTargetSelect: false,
-        activityName: '连续多级主管',
-        activityType: 'target_approval',
-      },
-      {
-        activityId: 'a890_1358',
-        prevActivityId: 'xi0m_sJzp',
-        workflowActor: {
-          actorType: 'approver',
-          approvalType: 'MANUAL',
-          actorActivateType: 'ONE_BY_ONE',
-          approvalMethod: 'ONE_BY_ONE',
-          allowedMulti: true,
-          actorSelectionRange: {},
-          required: false,
-        },
-        isTargetSelect: false,
-        activityName: '审批人',
-        activityType: 'target_approval',
-      },
-    ],
-    workflowForecastNodes: [
-      {
-        activityId: 'sid-startevent',
-        outId: 'line-random-sid-startevent-xi0m_sJzp',
-      },
-      {
-        activityId: 'xi0m_sJzp',
-        outId: 'line-random-xi0m_sJzp-a890_1358',
-      },
-      {
-        activityId: 'a890_1358',
-        outId: 'line-random-a890_1358-endId',
-      },
-      {
-        activityId: 'endId',
-      },
-    ],
-    processId: 64338972901,
-    processCode: 'PROC-F2AD61A8-25CF-47AB-96EA-E0D0850BBE35',
-    isForecastSuccess: true,
-    userId: '16569001414345099',
-    isStaticWorkflow: true,
-  };
+  const [flow, setFlow] = useState({ workflowActivityRules: [] });
+  const timerRef = useRef({
+    id: '',
+    status: false,
+  });
   const current = useMemo(() => {
     if (!activityId) {
       return flow.workflowActivityRules.length;
@@ -132,27 +74,35 @@ function AuditFlow(props) {
   };
 
   const getDetail = async () => {
-    if (!timer.status) {
+    console.log(timerRef.current);
+    if (!timerRef.current.status) {
       // 上锁
-      timer.status = true;
-      let flow = await queryDDProcessesForecast({
-        processCode,
-        deptId,
-        userId,
-        formComponentValues,
-      });
-      // 解锁
-      timer.status = false;
+      timerRef.current.status = true;
+      try {
+        let flow = await queryDDProcessesForecast({
+          processCode,
+          deptId,
+          userId,
+          formComponentValues,
+        });
+        console.log(flow);
+        setFlow(flow);
+      } catch (error) {}
+      setTimeout(() => {
+        // 延时解锁
+        timerRef.current.status = false;
+      }, 2000);
     } else {
-      clearTimeout(timer.id);
+      clearTimeout(timerRef.current.id);
       // 延迟调用
-      timer.id = setTimeout(() => {
+      timerRef.current.id = setTimeout(() => {
         getDetail();
       }, 2000);
     }
   };
 
   useEffect(() => {
+    if (!processCode || !formComponentValues) return;
     getDetail();
   }, [processCode, formComponentValues]);
 

+ 62 - 18
src/pages/PurchaseAdmin/PurchaseList/Detail/CommitAuditModal.js

@@ -22,9 +22,8 @@ function CommitAuditModal(props) {
   const [length, setLength] = useState(1);
   const [formData, setFromData] = useState({});
   const [auditList, setAuditList] = useState([]); //用于创建Tabs表单
-  const [formComponentValues, setFormComponentValues] = useState([]); //用于创建Tabs表单
+  const [formComponentValues, setFormComponentValues] = useState({}); //用于创建Tabs表单
   const [form] = Form.useForm();
-  const formDataRef = useRef([]);
 
   useEffect(() => {
     if (!visible) return;
@@ -147,12 +146,12 @@ function CommitAuditModal(props) {
       }
     }
     console.log(addAuditList);
-    addAuditList = addAuditList.map((item, index) => {
-      let FormComponents = Form3x.create({
+    addAuditList.forEach((item, index) => {
+      let Components = Form3x.create({
         onValuesChange: (props, changedValues, allValues) => {
           const { items } = props;
           console.log(props, allValues);
-          formComponentValues[index] = items
+          formComponentValues[item.formCode] = items
             .map(item => {
               const itemProps = item.props;
               if (!itemProps.label) return;
@@ -166,21 +165,55 @@ function CommitAuditModal(props) {
               }
               return {
                 name: itemProps.label,
-                id: itemProps.id,
-                value: allValues[itemProps.id],
+                // id: itemProps.id,
+                value: allValues[itemProps.id] || '',
               };
             })
             .filter(item => item);
-          setFormComponentValues([...formComponentValues])
+          setFormComponentValues({ ...formComponentValues });
         },
       })(AuditDetailed);
+      item.FormComponents = <Components items={item.schemaContent.items} />;
+    });
+    setAuditList(addAuditList);
+  };
 
-      return {
-        ...item,
-        FormComponents: <FormComponents items={item.schemaContent.items} />,
+  const getFromData = idList => {
+    const data = formComponentValues;
+    const result = [];
+    //获取流转节点的层级关系
+    let len = 0;
+    let list = [];
+    idList.forEach(item => {
+      if (len < item.length) len = item.length;
+    });
+    for (let i = 0; i < len; i++) {
+      idList.forEach(item => {
+        if (item && item[i]) list.push(item[i]);
+      });
+    }
+    let firstList = [...new Set(list)];
+    // let firstList = idList[0];
+    // for (let i = 1; i < idList.length; i++) {
+    //   let item = idList[i];
+    //   item.forEach(itemId => {
+    //     let idx = firstList.findIndex(id => id == itemId);
+    //     if (idx > 0 && !firstList.find(cur => cur == item[idx - 1])) {
+    //       firstList.splice(idx, 0, item[i - 1]);
+    //     }
+    //   });
+    // }
+    firstList.forEach(id => {
+      let approvalNode = flowDetail.nodes.find?.(item => item.Id == id);
+      const formItem = {
+        processCode: approvalNode.process_code,
+        originatorUserId: '16569001414345099',
+        deptId: '14169890',
+        formComponentValues: data[approvalNode.process_code],
       };
+      result.push(JSON.stringify(formItem));
     });
-    setAuditList(addAuditList);
+    return result;
   };
   const onFinish = async () => {
     var fieldsValue = await form.validateFields();
@@ -222,6 +255,9 @@ function CommitAuditModal(props) {
       message.error('请选择需要流转的业务节点。');
       return;
     }
+
+    const flowPath = result.map(item => getFlowPath(item));
+    const formList = getFromData(result);
     let params = {
       desc: fieldsValue.desc,
       // 审核流程id
@@ -247,6 +283,7 @@ function CommitAuditModal(props) {
       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;
@@ -255,12 +292,16 @@ function CommitAuditModal(props) {
     } else {
       //多节点审批
       params.template_node_id = result[0][0]; // 将要流转的节点审批节点
-      params.flow_path = result.map(item => getFlowPath(item));
+      params.flow_path = flowPath;
+      params.form_list = formList; //创建钉钉表单所需数据
     }
-    // if (!hasFlowId) {
-    //   message.error('当前存在审批节点未绑定审批流程!请联系管理员。');
-    //   return;
-    // }
+    if (!hasFlowId) {
+      message.error('当前存在审批节点未绑定审批流程!请联系管理员。');
+      return;
+    }
+
+    console.log(JSON.stringify(params));
+    console.log(params);
     onOk(params);
   };
 
@@ -319,7 +360,10 @@ function CommitAuditModal(props) {
           // </TabPane>
           <TabPane tab={item.name} key={`${idx}_${item.title}`}>
             {item.FormComponents}
-            <AuditFlow processCode={item.formCode} formComponentValues={formComponentValues[idx]} />
+            <AuditFlow
+              processCode={item.formCode}
+              formComponentValues={formComponentValues[item.formCode]}
+            />
           </TabPane>
         ))}
       </Tabs>

+ 6 - 0
src/pages/PurchaseAdmin/PurchaseList/Detail/Index.js

@@ -770,6 +770,12 @@ function Detail(props) {
           version_id: version.version_id,
         },
       });
+      dispatch({
+        type: 'detail/queryDingInstanceDetail',
+        payload: {
+          process_instance_id: version.ding_instance_id, //创建表单成功返回的id
+        },
+      });
     }
   };
 

+ 7 - 0
src/pages/PurchaseAdmin/PurchaseList/Detail/models/detail.js

@@ -32,6 +32,7 @@ import {
   queryAuditExcel,
   queryAuditRecord,
   queryDingSchema,
+  queryDingInstanceDetail,
 } from '@/services/boom';
 import { queryRole } from '@/services/SysAdmin';
 import { setCurrentUser } from '@/utils/authority';
@@ -520,6 +521,12 @@ export default {
         callback && callback(response.data?.all);
       }
     },
+    *queryDingInstanceDetail({ payload, callback }, { call, put }) {
+      const response = yield call(queryDingInstanceDetail, payload);
+      if (response) {
+        callback && callback(response.data?.all);
+      }
+    },
   },
 
   reducers: {

+ 10 - 2
src/services/boom.js

@@ -1,3 +1,4 @@
+import { message } from 'antd';
 import request from '@/utils/request';
 import { async } from '@antv/x6/lib/registry/marker/async';
 import { stringify } from 'qs';
@@ -107,6 +108,9 @@ export async function queryAuditRecord(params) {
 export async function queryDingSchema(params) {
   return request(`/api/v1/purchase/bom/ding/schema?${stringify(params)}`);
 }
+export async function queryDingInstanceDetail(params) {
+  return request(`/api/v1/purchase/bom/ding/instance-detail?${stringify(params)}`);
+}
 /**
  * 查看项目流程列表
  * project_id
@@ -297,7 +301,7 @@ export async function queryDDdepList(data) {
     method: 'POST',
     body: data,
   });
-  return res.data.result
+  return res.data.result;
 }
 
 export async function queryDDProcessesForecast(data) {
@@ -305,5 +309,9 @@ export async function queryDDProcessesForecast(data) {
     method: 'POST',
     body: data,
   });
-  return res.data.result
+  if (res.data.message) {
+    // message.error(res.data.message);
+    throw new Error(res.data.message);
+  }
+  return res.data.result;
 }