outaozhen преди 3 години
родител
ревизия
61f662e9a0
променени са 3 файла, в които са добавени 33 реда и са изтрити 22 реда
  1. 18 7
      src/pages/Institutions/Staff/components/StaffDetail.tsx
  2. 13 13
      src/pages/Institutions/Staff/index.tsx
  3. 2 2
      src/services/api/institution.ts

+ 18 - 7
src/pages/Institutions/Staff/components/StaffDetail.tsx

@@ -1,4 +1,4 @@
-import React, { useEffect } from 'react'
+import React, { useEffect, useState } from 'react'
 import { message, Button, Form } from 'antd'
 import { connect, useRequest } from 'umi'
 import consts from '@/utils/consts'
@@ -53,6 +53,9 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
 }) => {
   const form = useForm()
 
+  const [state, setState] = useState({
+    accountDetail: {}
+  })
   const { run: tryUpdateAccount } = useRequest(updateAccount, {
     manual: true,
     onSuccess: () => {
@@ -67,17 +70,14 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
     }
   })
 
-  const { run: tryGetAccountDetail } = useRequest(queryAccountDetail, {
+  const { run: tryGetAccountDetail } = useRequest((ID: string) => queryAccountDetail(ID), {
     manual: true,
-    onSuccess: () => {
+    onSuccess: result => {
       setState({ ...state, accountDetail: result })
     }
   })
 
   useEffect(() => {
-    if (type === ModalType.PREVIEW) {
-      tryGetAccountDetail({ ID: dataId })
-    }
     if (visible) {
       if (!schema) {
         dispatch({
@@ -138,7 +138,9 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
 
   const onMount = () => {
     if (!defaultFormData?.dataID) {
-      form.setValues(type === ModalType.ADD ? {} : { ...defaultFormData })
+      if (type === ModalType.UPDATE) {
+        form.setValues({ ...defaultFormData })
+      }
     } else {
       form.setValues(
         type === ModalType.ADD
@@ -174,6 +176,15 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
         })
       }
     })
+    if (dataId) {
+      queryAccountDetail({ ID: dataId }).then(accountDetail => {
+        if (accountDetail) {
+          if (type === ModalType.PREVIEW) {
+            form.setValues({ ...accountDetail.data })
+          }
+        }
+      })
+    }
     if (defaultFormData?.institutionID) {
       queryOrganizationalStructureList({
         dataID: defaultFormData?.institutionID,

+ 13 - 13
src/pages/Institutions/Staff/index.tsx

@@ -82,18 +82,18 @@ const CompanyList: React.FC<ListProps> = ({ schema, dispatch, accountTypeList })
               ...state,
               visible: true,
               currentModalType: ModalType.PREVIEW,
-              dataId: record.ID,
-              defaultFormData: {
-                // ...record,
-                institution: null,
-                ID: record.ID,
-                account: record.account,
-                name: record.name,
-                gender: record.gender,
-                phone: record.phone,
-                institutionID: record.institution.ID,
-                accountType: record.accountType
-              }
+              dataId: record.ID
+              // defaultFormData: {
+              //   // ...record,
+              //   institution: null,
+              //   ID: record.ID,
+              //   account: record.account,
+              //   name: record.name,
+              //   gender: record.gender,
+              //   phone: record.phone,
+              //   institutionID: record.institution.ID,
+              //   accountType: record.accountType
+              // }
             })
           }}>
           {name}
@@ -171,7 +171,7 @@ const CompanyList: React.FC<ListProps> = ({ schema, dispatch, accountTypeList })
                 currentModalType: ModalType.UPDATE,
                 defaultFormData: {
                   // ...record,
-                  institution: null,
+                  institution: record.institutionID,
                   ID: record.ID,
                   account: record.account,
                   name: record.name,

+ 2 - 2
src/services/api/institution.ts

@@ -57,9 +57,9 @@ export async function addAccount(params: API.AcountAddParams) {
 }
 
 /** 账号详情 */
-export async function queryAccountDetail() {
+export async function queryAccountDetail(params: { ID: string }) {
   return request('/account/detail', {
-    method: 'GET'
+    params
   })
 }