Selaa lähdekoodia

fix: 人员管理添加和编辑默认值修改问题

outaozhen 3 vuotta sitten
vanhempi
commit
4eed0870c4

+ 4 - 0
src/pages/Institutions/Company/Detail/components/Staff.tsx

@@ -42,6 +42,7 @@ const Staff: React.FC<ListProps> = ({ schema, dataID, dispatch, accountTypeList
       dataID: dataID
     },
     visible: false,
+    institutionDisable: false,
     currentModalType: ModalType.ADD,
     defaultFormData: null
   })
@@ -121,6 +122,7 @@ const Staff: React.FC<ListProps> = ({ schema, dataID, dispatch, accountTypeList
                 ...state,
                 visible: true,
                 currentModalType: ModalType.UPDATE,
+                institutionDisable: true,
                 defaultFormData: {
                   institution: null,
                   ID: record.ID,
@@ -172,6 +174,7 @@ const Staff: React.FC<ListProps> = ({ schema, dataID, dispatch, accountTypeList
                   ...state,
                   visible: true,
                   currentModalType: ModalType.ADD,
+                  institutionDisable: true,
                   defaultFormData: { ...state.params, structureType: '1', institutionID: dataID }
                 })
               }}>
@@ -186,6 +189,7 @@ const Staff: React.FC<ListProps> = ({ schema, dataID, dispatch, accountTypeList
         <StaffDetail
           visible={state.visible}
           setVisible={(visible: boolean) => setState({ ...state, visible })}
+          institutionDisable={state.institutionDisable}
           type={state.currentModalType}
           defaultFormData={{ ...state.defaultFormData, dataID }}
           accountTypeList={accountTypeList}

+ 14 - 12
src/pages/Institutions/Company/List/components/CompanyDrawer.tsx

@@ -1,7 +1,7 @@
 import { connect, useRequest } from 'umi'
 import { useEffect } from 'react'
 import FormRender, { useForm } from 'form-render'
-import { Drawer, message, Button } from 'antd'
+import { Form, message, Button } from 'antd'
 import { addInstitution, updateInstitution } from '@/services/api/institution'
 import { BaseMenuEnum } from '@/pages/Schema/Base'
 import { ModalType } from '@/utils/enum'
@@ -78,18 +78,20 @@ const CompanyDrawer: React.FC<CompanyModalProps> = ({
     // })
   }
   return (
-    <Drawer
-      width="50vw"
-      visible={visible}
-      onClose={() => {
-        setVisible(false)
-      }}
-      title={type === ModalType.ADD ? '新增企事业单位' : '编辑企事业单位'}>
-      {schema && <FormRender form={form} schema={schema} onFinish={onFinish} onMount={onMount} />}
-      <div className="ml-120px">
-        <Button onClick={form.submit}>提交</Button>
+    <div>
+      <div className="text-xl mb-6">
+        {type === ModalType.ADD ? '新增企事业单位' : null}
+        {type === ModalType.UPDATE ? '编辑企事业单位' : null}
       </div>
-    </Drawer>
+      <Form>
+        {schema && <FormRender form={form} schema={schema} onFinish={onFinish} onMount={onMount} />}
+        <div className="ml-120px">
+          <Button type="primary" onClick={form.submit}>
+            提交
+          </Button>
+        </div>
+      </Form>
+    </div>
   )
 }
 

+ 12 - 7
src/pages/Institutions/Company/List/index.tsx

@@ -14,6 +14,7 @@ import { PageContainer } from '@ant-design/pro-layout'
 import CompanyDrawer from './components/CompanyDrawer'
 import { ModalType } from '@/utils/enum'
 import { generateColumns } from '@/utils/util'
+import AnimateContent from '@/components/AnimateContent'
 
 type ListProps = ConnectProps & {
   pTypeList: { label: string; value: string }[]
@@ -170,14 +171,18 @@ const CompanyList: React.FC<ListProps> = ({ base, dispatch, pTypeList }) => {
         }}
         search={false}
       />
-      <CompanyDrawer
-        type={state.currentModalType}
-        defaultFormData={state.defaultFormData}
-        pTypeList={pTypeList}
+      <AnimateContent
         visible={state.visible}
-        reload={() => tRef.current?.reload()}
-        setVisible={(visible: boolean) => setState({ ...state, visible })}
-      />
+        onVisibleChange={visible => setState({ ...state, visible })}>
+        <CompanyDrawer
+          type={state.currentModalType}
+          defaultFormData={state.defaultFormData}
+          pTypeList={pTypeList}
+          visible={state.visible}
+          reload={() => tRef.current?.reload()}
+          setVisible={(visible: boolean) => setState({ ...state, visible })}
+        />
+      </AnimateContent>
     </PageContainer>
   )
 }

+ 28 - 5
src/pages/Institutions/Staff/components/StaffDetail.tsx

@@ -22,6 +22,7 @@ import { ModalType } from '@/utils/enum'
 type StaffModalProps = ConnectProps & {
   visible: boolean
   onVisibleChange: (visible: boolean) => void
+  institutionDisable: boolean
   type: ModalType
   defaultFormData?: {
     ID: string
@@ -37,6 +38,7 @@ type StaffModalProps = ConnectProps & {
 
 const StaffDrawer: React.FC<StaffModalProps> = ({
   visible,
+  institutionDisable,
   onVisibleChange,
   schema,
   dispatch,
@@ -120,7 +122,15 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
   }
 
   const onMount = () => {
-    form.setValues(type === ModalType.ADD ? {} : { ...defaultFormData })
+    if (!defaultFormData?.dataID) {
+      form.setValues(type === ModalType.ADD ? {} : { ...defaultFormData })
+    } else {
+      form.setValues(
+        type === ModalType.ADD
+          ? { institutionID: defaultFormData?.institutionID }
+          : { ...defaultFormData }
+      )
+    }
     delay(80).then(() => {
       form.setSchemaByPath('accountType', {
         type: 'string',
@@ -131,10 +141,23 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
         enum: accountTypeList.map(item => item.value),
         enumNames: accountTypeList.map(item => item.label)
       })
-      form.setSchemaByPath('institutionID', {
-        type: 'string',
-        widget: 'site'
-      })
+      if (institutionDisable) {
+        form.setSchemaByPath('institutionID', {
+          type: 'string',
+          widget: 'site',
+          disabled: true
+        })
+      } else {
+        form.setSchemaByPath('institutionID', {
+          type: 'string',
+          widget: 'site'
+        })
+      }
+      if (type === ModalType.UPDATE) {
+        form.setSchemaByPath('account', {
+          disabled: true
+        })
+      }
     })
     if (defaultFormData?.institutionID) {
       queryOrganizationalStructureList({

+ 9 - 3
src/pages/Institutions/Staff/index.tsx

@@ -46,10 +46,11 @@ const CompanyList: React.FC<ListProps> = ({ schema, dispatch, accountTypeList })
   }, [])
   const [state, setState] = useState({
     params: {
-      search: null
+      search: null,
+      institutionID: null
     },
     visible: false,
-    readOnly: true,
+    institutionDisable: false,
     staffDetail: [],
     ID: '',
     currentModalType: ModalType.ADD,
@@ -222,7 +223,11 @@ const CompanyList: React.FC<ListProps> = ({ schema, dispatch, accountTypeList })
             <Button
               type="primary"
               onClick={() =>
-                setState({ ...state, visible: true, currentModalType: ModalType.ADD })
+                setState({
+                  ...state,
+                  visible: true,
+                  currentModalType: ModalType.ADD
+                })
               }>
               新建账号
             </Button>
@@ -237,6 +242,7 @@ const CompanyList: React.FC<ListProps> = ({ schema, dispatch, accountTypeList })
           type={state.currentModalType}
           defaultFormData={state.defaultFormData}
           visible={state.visible}
+          institutionDisable={state.institutionDisable}
           reload={() => tRef.current?.reload()}
           onVisibleChange={(visible: boolean) => setState({ ...state, visible })}
         />