Эх сурвалжийг харах

修改【提交审批】表单必填项没有校验

Renxy 2 жил өмнө
parent
commit
91b4cba897

+ 29 - 25
src/pages/Flow/OaDetail.js

@@ -1,5 +1,5 @@
 import React, { useRef, useState } from 'react';
-import { Button, Col, Empty, Row, message } from 'antd';
+import { Button, Col, Empty, Form, Row, message } from 'antd';
 import ApprovalProcess from './components/ApprovalProcess';
 import AuditDetailed from './components/AuditDetailed';
 import PageContent from '@/components/PageContent';
@@ -14,6 +14,7 @@ import {
 import { useParams, useRequest, useNavigate } from 'umi';
 
 const OaDetail = () => {
+  const [form] = Form.useForm();
   const [approvalProcess, setApprovalProcess] = useState([]);
   const { oaId } = useParams();
   const formValueRef = useRef({
@@ -86,30 +87,32 @@ const OaDetail = () => {
   };
 
   const submit = () => {
-    const { form } = formValueRef.current;
-    let audit_list = [];
-    approvalProcess?.forEach((item) => {
-      if (item[0].type == 'role') audit_list.push(item[0].nowValue);
-      else if (item[0].type == 'leader')
-        audit_list.push(
-          ...leaderData.slice(0, item[0].value).map((leader) => leader.ID),
-        );
-      else audit_list.push(item[0].value);
-    });
-    let files = [],
-      formData = [];
-    form.forEach((item) => {
-      if (item.type == 'DDAttachment') {
-        files = files.concat(item.value);
-      } else {
-        formData.push(item);
-      }
-    });
-    createRun({
-      flow_id: Number(oaId),
-      form: JSON.stringify(formData),
-      audit_list,
-      files: files.join(','),
+    form.validateFields().then((values) => {
+      const { form: formCur } = formValueRef.current;
+      let audit_list = [];
+      approvalProcess?.forEach((item) => {
+        if (item[0].type == 'role') audit_list.push(item[0].nowValue);
+        else if (item[0].type == 'leader')
+          audit_list.push(
+            ...leaderData.slice(0, item[0].value).map((leader) => leader.ID),
+          );
+        else audit_list.push(item[0].value);
+      });
+      let files = [],
+        formData = [];
+      formCur.forEach((item) => {
+        if (item.type == 'DDAttachment') {
+          files = files.concat(item.value);
+        } else {
+          formData.push(item);
+        }
+      });
+      createRun({
+        flow_id: Number(oaId),
+        form: JSON.stringify(formData),
+        audit_list,
+        files: files.join(','),
+      });
     });
   };
   // const OnModelFileDone = (file) => {
@@ -138,6 +141,7 @@ const OaDetail = () => {
               />
             )} */}
           <AuditDetailed
+            form={form}
             items={data?.formData}
             onValuesChange={advanceSubmit}
           />

+ 2 - 2
src/pages/Flow/components/AuditDetailed.js

@@ -3,8 +3,8 @@ import React, { useMemo, useState } from 'react';
 import { Button, Form } from 'antd';
 
 const AuditDetailed = (props) => {
-  const [form] = Form.useForm();
-  const { items, onValuesChange } = props;
+  // const [form] = Form.useForm();
+  const { items, form, onValuesChange } = props;
 
   const behavior = useMemo(() => {
     let data = {};