|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useEffect, useState } from 'react'
|
|
|
+import React, { useEffect } from 'react'
|
|
|
import { message, Button, Form } from 'antd'
|
|
|
import { connect, useRequest } from 'umi'
|
|
|
import consts from '@/utils/consts'
|
|
@@ -26,12 +26,10 @@ type StaffModalProps = ConnectProps & {
|
|
|
onVisibleChange: (visible: boolean) => void
|
|
|
institutionDisable: boolean
|
|
|
type: ModalType
|
|
|
- dataId: string
|
|
|
defaultFormData?: {
|
|
|
- ID: string
|
|
|
- name: string
|
|
|
- accountType: string
|
|
|
- dataID: string
|
|
|
+ dataID?: string
|
|
|
+ institutionID?: string
|
|
|
+ institutionDisable?: boolean
|
|
|
}
|
|
|
accountTypeList: API.AccountType
|
|
|
organizationList: API.OrganizationalStructureListItem[]
|
|
@@ -41,21 +39,15 @@ type StaffModalProps = ConnectProps & {
|
|
|
|
|
|
const StaffDrawer: React.FC<StaffModalProps> = ({
|
|
|
visible,
|
|
|
- institutionDisable,
|
|
|
onVisibleChange,
|
|
|
schema,
|
|
|
dispatch,
|
|
|
type,
|
|
|
- dataId,
|
|
|
defaultFormData,
|
|
|
accountTypeList,
|
|
|
reload
|
|
|
}) => {
|
|
|
const form = useForm()
|
|
|
-
|
|
|
- const [state, setState] = useState({
|
|
|
- accountDetail: {}
|
|
|
- })
|
|
|
const { run: tryUpdateAccount } = useRequest(updateAccount, {
|
|
|
manual: true,
|
|
|
onSuccess: () => {
|
|
@@ -70,13 +62,6 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- const { run: tryGetAccountDetail } = useRequest((ID: string) => queryAccountDetail(ID), {
|
|
|
- manual: true,
|
|
|
- onSuccess: result => {
|
|
|
- setState({ ...state, accountDetail: result })
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
if (visible) {
|
|
|
if (!schema) {
|
|
@@ -88,29 +73,7 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- // if (defaultFormData?.institutionID && !organizationList?.length) {
|
|
|
- // dispatch({
|
|
|
- // type: 'institutions/queryOrganizationList',
|
|
|
- // payload: {
|
|
|
- // dataID: defaultFormData?.institutionID,
|
|
|
- // structureType: '1'
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // }, [defaultFormData?.institutionID, visible])
|
|
|
}, [visible])
|
|
|
- // useEffect(() => {
|
|
|
- // if (organizationList?.length) {
|
|
|
- // form.setSchemaByPath('organizationalStructureID', {
|
|
|
- // type: 'string',
|
|
|
- // widget: 'treeSelect',
|
|
|
- // props: {
|
|
|
- // treeDefaultExpandAll: true,
|
|
|
- // treeData: organizationList
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // }, [organizationList?.length])
|
|
|
|
|
|
const queryInstitutionOptions = async params => {
|
|
|
const { code = -1, data = {} } = await queryInstitutionList({
|
|
@@ -136,78 +99,65 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- const onMount = () => {
|
|
|
- if (!defaultFormData?.dataID) {
|
|
|
- if (type === ModalType.UPDATE) {
|
|
|
- form.setValues({ ...defaultFormData })
|
|
|
+ const onMount = async () => {
|
|
|
+ const { dataID, institutionID, institutionDisable = false } = defaultFormData
|
|
|
+ !institutionID &&
|
|
|
+ form.setSchemaByPath('organizationalStructureID', {
|
|
|
+ type: 'string',
|
|
|
+ widget: 'treeSelect',
|
|
|
+ hidden: true
|
|
|
+ })
|
|
|
+ if (institutionID && type !== ModalType.PREVIEW) {
|
|
|
+ const { code = -1, data: list = [] } = await queryOrganizationalStructureList({
|
|
|
+ dataID: institutionID,
|
|
|
+ structureType: '1'
|
|
|
+ })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ form.setSchemaByPath('organizationalStructureID', {
|
|
|
+ type: 'string',
|
|
|
+ widget: 'treeSelect',
|
|
|
+ props: {
|
|
|
+ treeDefaultExpandAll: true,
|
|
|
+ treeData: list
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (dataID) {
|
|
|
+ const { code = -1, data = {} } = await queryAccountDetail({ ID: dataID })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ const account = { ...data, institution: null, organizationalStructure: null }
|
|
|
+ if (type === ModalType.PREVIEW) {
|
|
|
+ account.institutionID = data.institution.name
|
|
|
+ account.organizationalStructureID = data.organizationalStructure.name
|
|
|
+ }
|
|
|
+ form.setValues({
|
|
|
+ ...account
|
|
|
+ })
|
|
|
}
|
|
|
} else {
|
|
|
- form.setValues(
|
|
|
- type === ModalType.ADD
|
|
|
- ? { institutionID: defaultFormData?.institutionID }
|
|
|
- : { ...defaultFormData }
|
|
|
- )
|
|
|
+ if (type === ModalType.ADD && institutionID) {
|
|
|
+ form.setValues({ institutionID })
|
|
|
+ }
|
|
|
}
|
|
|
delay(80).then(() => {
|
|
|
form.setSchemaByPath('accountType', {
|
|
|
type: 'string',
|
|
|
widget: 'select',
|
|
|
- // props: {
|
|
|
- // options: accountTypeList
|
|
|
- // }
|
|
|
enum: accountTypeList.map(item => item.value),
|
|
|
enumNames: accountTypeList.map(item => item.label)
|
|
|
})
|
|
|
- if (institutionDisable) {
|
|
|
- form.setSchemaByPath('institutionID', {
|
|
|
- type: 'string',
|
|
|
- widget: 'site',
|
|
|
- disabled: true
|
|
|
- })
|
|
|
- } else {
|
|
|
- form.setSchemaByPath('institutionID', {
|
|
|
- type: 'string',
|
|
|
- widget: 'site'
|
|
|
- })
|
|
|
- }
|
|
|
+ form.setSchemaByPath('institutionID', {
|
|
|
+ type: 'string',
|
|
|
+ widget: 'site',
|
|
|
+ disabled: institutionDisable
|
|
|
+ })
|
|
|
if (type === ModalType.UPDATE) {
|
|
|
form.setSchemaByPath('account', {
|
|
|
disabled: true
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
- if (dataId) {
|
|
|
- queryAccountDetail({ ID: dataId }).then(accountDetail => {
|
|
|
- if (accountDetail) {
|
|
|
- if (type === ModalType.PREVIEW) {
|
|
|
- form.setValues({ ...accountDetail.data })
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- if (defaultFormData?.institutionID) {
|
|
|
- queryOrganizationalStructureList({
|
|
|
- dataID: defaultFormData?.institutionID,
|
|
|
- structureType: '1'
|
|
|
- }).then(organizationList => {
|
|
|
- if (organizationList) {
|
|
|
- form.setSchemaByPath('organizationalStructureID', {
|
|
|
- type: 'string',
|
|
|
- widget: 'treeSelect',
|
|
|
- props: {
|
|
|
- treeDefaultExpandAll: true,
|
|
|
- treeData: organizationList.data
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- form.setSchemaByPath('organizationalStructureID', {
|
|
|
- type: 'string',
|
|
|
- widget: 'treeSelect',
|
|
|
- hidden: true
|
|
|
- })
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
const watch = {
|
|
@@ -231,23 +181,6 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // const handleOnFinish = () => {
|
|
|
- // ref.current?.validateFields().then(async values => {
|
|
|
- // try {
|
|
|
- // // 执行表单提交
|
|
|
- // if (type === ModalType.ADD) {
|
|
|
- // await tryAddAccount(values)
|
|
|
- // } else {
|
|
|
- // await tryUpdateAccount(values)
|
|
|
- // }
|
|
|
- // setVisible(false)
|
|
|
- // reloadTable()
|
|
|
- // ref.current?.resetFields()
|
|
|
- // } catch (error) {
|
|
|
- // message.error(error)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
const onFinish = async (formData, errors) => {
|
|
|
if (errors?.length) return
|
|
|
try {
|