Procházet zdrojové kódy

Modal组件关闭清空

XuZinan před 2 roky
rodič
revize
c79b762aab

+ 8 - 13
src/pages/PurchaseAdmin/PurchaseList/Approval/ApprovalModal.js

@@ -156,9 +156,10 @@ function AddModal(props) {
           rules={[
             { required: true, message: '请输入项目简称' },
             {
-              validator: (rule, value, callback) => {
-                if (value.match(/[^A-Za-z]/g)) callback('项目简称只能是英文字符');
-                else callback();
+              validator: (rule, value) => {
+                if (value && value.match(/[^A-Za-z]/g))
+                  return Promise.reject(new Error('项目简称只能是英文字符'));
+                else return Promise.resolve();
               },
             },
           ]}
@@ -185,16 +186,6 @@ function AddModal(props) {
     );
   };
 
-  // const renderCode = () => {
-  //   let project_full_code = '';
-  //   if (total < 10) {
-  //     project_full_code = '00' + total;
-  //   } else if (total < 100) project_full_code = '0' + total;
-  //   else project_full_code = total;
-  //   project_full_code = `RD${moment().format('YYYYMM')}${project_full_code}`;
-  //   return <Form.Item label="项目编号">{project_full_code}</Form.Item>;
-  // };
-
   useEffect(() => {
     if (data.id) {
       const type = typeList.find(item => item.id == data.type_id);
@@ -219,6 +210,10 @@ function AddModal(props) {
     }
   }, [data, visible]);
 
+  useEffect(() => {
+    form.resetFields();
+  }, [visible]);
+
   return (
     <Modal
       title="项目立项"

+ 9 - 3
src/pages/PurchaseAdmin/PurchaseList/Approval/BudgetModal.js

@@ -6,6 +6,8 @@ function BudgetModal(props) {
   const { visible, onCancel, onOk, loading, currentItem, dispatch, budget } = props;
   const [form] = Form.useForm();
 
+  useEffect(() => form.resetFields(), [visible]);
+
   const subTypeList = [
     { name: '建设期项目管理人员', code: '02-010', id: 12 },
     { name: '工程设计人日(含BIM设计)', code: '04-010', id: 13 },
@@ -35,13 +37,13 @@ function BudgetModal(props) {
         let elm = {
           project_id: Number(currentItem?.id),
           type_id: Number(item),
-          workload: Number(values[item])
+          workload: Number(values[item]),
         };
         if (isUpdate) {
           elm.id = budget?.find(child => child.type_id == item)?.id;
         }
         params.push(elm);
-      })
+      });
       console.log(params);
       dispatch({
         type: 'approval/setBudget',
@@ -62,7 +64,11 @@ function BudgetModal(props) {
     >
       <Form form={form} labelCol={{ span: 10 }} wrapperCol={{ span: 10 }}>
         {subTypeList.map(item => (
-          <Form.Item label={item.name} name={item.id} initialValue={Number(budget?.find(child => child.type_id === item.id)?.workload) || 0}>
+          <Form.Item
+            label={item.name}
+            name={item.id}
+            initialValue={Number(budget?.find(child => child.type_id === item.id)?.workload) || 0}
+          >
             <InputNumber min={0} style={{ width: '100%' }} />
           </Form.Item>
         ))}

+ 3 - 1
src/pages/PurchaseAdmin/PurchaseList/Approval/ExecutionModal.js

@@ -8,6 +8,8 @@ function ExecutionModal(props) {
   const { visible, onOk, onClose, currentItem, loading, depUserTree, dispatch } = props;
   const [form] = Form.useForm();
 
+  useEffect(() => form.resetFields(), [visible]);
+
   const handleOk = () => {
     form.validateFields().then(({ managerID, contractStatus }) => {
       const [exe_manager_id, dep_id] = managerID.split('||');
@@ -23,7 +25,7 @@ function ExecutionModal(props) {
       });
     });
   };
-  
+
   return (
     <Modal
       title="转执行"

+ 6 - 2
src/pages/PurchaseAdmin/PurchaseList/Approval/MemberModal.js

@@ -96,11 +96,15 @@ function MemberModal(props) {
       maskClosable={false}
       destroyOnClose
       visible={visible}
-      onCancel={onClose}
+      onCancel={() => {
+        form.resetFields();
+        setType('1');
+        onClose();
+      }}
       footer={null}
       width="70%"
     >
-      <Tabs activeKey={type} onChange={type => handleChange(type)}>
+      <Tabs defaultActiveKey="1" activeKey={type} onChange={type => handleChange(type)}>
         {STATUS.map(
           item =>
             currentItem.flow_id >= item.value && (

+ 5 - 3
src/pages/PurchaseAdmin/PurchaseList/Approval/ModifyManagerModal.js

@@ -6,9 +6,11 @@ const { TreeNode } = TreeSelect;
 function ModifyManagerModal(props) {
   const { visible, onClose, currentItem, loading, depUserTree, dataSource, dispatch, onOk } = props;
   const [form] = Form.useForm();
-  // useEffect(() => {
-  //   form.resetFields();
-  // }, []);
+
+  useEffect(() => {
+    form.resetFields();
+  }, [visible]);
+
   const handleOk = () => {
     form.validateFields().then(({ managerID }) => {
       const [user_id, dep_id] = managerID.split('||');

+ 2 - 0
src/pages/PurchaseAdmin/PurchaseList/Approval/QualityOperateModal.js

@@ -17,6 +17,8 @@ function QualityOperateModal(props) {
   } = props;
   const [form] = Form.useForm();
 
+  useEffect(() => form.resetFields(), [visible]);
+
   const handleOk = () => {
     form.validateFields().then(({ managerID }) => {
       const [manager_id, dep_id] = managerID.split('||');