|
@@ -1,9 +1,11 @@
|
|
|
import { useRequest } from 'umi'
|
|
|
import { useRef, useEffect } from 'react'
|
|
|
import ProForm, { ProFormSelect, ProFormText } from '@ant-design/pro-form'
|
|
|
-import { message, Modal } from 'antd'
|
|
|
+import { Col, message, Modal, Row, Form } from 'antd'
|
|
|
import type { FormInstance } from 'antd'
|
|
|
-import { addAccount, updateAccount } from '@/services/api/institution'
|
|
|
+import { addAccount, queryInstitutionList, updateAccount } from '@/services/api/institution'
|
|
|
+import DebounceSelect from './DebounceSelect'
|
|
|
+import consts from '@/utils/consts'
|
|
|
|
|
|
export enum ModalType {
|
|
|
ADD = 0,
|
|
@@ -15,7 +17,7 @@ type StaffModalProps = {
|
|
|
setVisible: (visible: boolean) => void
|
|
|
type: ModalType
|
|
|
defaultFormData?: API.AccountListItem
|
|
|
- // pTypeList: API.ProjectTypeList
|
|
|
+ accountType: API.AccountType
|
|
|
reloadTable: () => void
|
|
|
}
|
|
|
const StaffModal: React.FC<StaffModalProps> = ({
|
|
@@ -23,6 +25,7 @@ const StaffModal: React.FC<StaffModalProps> = ({
|
|
|
setVisible,
|
|
|
type,
|
|
|
defaultFormData,
|
|
|
+ accountType,
|
|
|
// pTypeList,
|
|
|
reloadTable
|
|
|
}) => {
|
|
@@ -31,15 +34,18 @@ const StaffModal: React.FC<StaffModalProps> = ({
|
|
|
labelCol: { flex: '100px' }
|
|
|
}
|
|
|
const ref = useRef<FormInstance>(null)
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
defaultFormData && ref.current?.setFieldsValue({ ...defaultFormData })
|
|
|
}, [defaultFormData])
|
|
|
+
|
|
|
const { run: tryUpdateAccount } = useRequest(updateAccount, {
|
|
|
manual: true,
|
|
|
onSuccess: () => {
|
|
|
message.success('更新成功')
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
const { run: tryAddAccount } = useRequest(addAccount, {
|
|
|
manual: true,
|
|
|
onSuccess: () => {
|
|
@@ -64,6 +70,19 @@ const StaffModal: React.FC<StaffModalProps> = ({
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+ const queryInstitutionOptions = async search => {
|
|
|
+ const { code = -1, data = {} } = await queryInstitutionList({
|
|
|
+ search,
|
|
|
+ current: 1,
|
|
|
+ pageSize: 100
|
|
|
+ })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ return data.items.map(item => ({ label: item.name, value: item.ID }))
|
|
|
+ }
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ const { institution } = defaultFormData || {}
|
|
|
+
|
|
|
return (
|
|
|
<Modal
|
|
|
width="35vw"
|
|
@@ -76,17 +95,63 @@ const StaffModal: React.FC<StaffModalProps> = ({
|
|
|
onOk={() => handleOnFinish()}>
|
|
|
<ProForm formRef={ref} submitter={{ render: false }} {...layout}>
|
|
|
{type === ModalType.UPDATE ? <ProFormText name="ID" hidden /> : null}
|
|
|
- <ProFormText
|
|
|
- name="name"
|
|
|
- label="名称"
|
|
|
- rules={[{ required: true, message: '请输入账号名称' }]}
|
|
|
- />
|
|
|
- <ProFormSelect
|
|
|
+ <Form.Item
|
|
|
+ labelCol={{ flex: '150px' }}
|
|
|
name="institutionID"
|
|
|
- label="企事业单位"
|
|
|
+ label="所属企事业单位"
|
|
|
+ rules={[{ required: true, message: '请选择企事业单位' }]}>
|
|
|
+ <DebounceSelect
|
|
|
+ fetchOptions={queryInstitutionOptions}
|
|
|
+ showSearch
|
|
|
+ defaultOptions={institution && [{ label: institution.name, value: institution.ID }]}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ {/* <ProFormSelect
|
|
|
+ labelCol={{ flex: '150px' }}
|
|
|
+ name="institutionID"
|
|
|
+ label="所属企事业单位"
|
|
|
rules={[{ required: true, message: '请选择企事业单位' }]}
|
|
|
- />
|
|
|
- <ProFormText name="phone" label="手机号" />
|
|
|
+ /> */}
|
|
|
+ <Row>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormText
|
|
|
+ name="account"
|
|
|
+ label="账号"
|
|
|
+ rules={[{ required: true, message: '请输入账号' }]}
|
|
|
+ />
|
|
|
+ <ProFormText
|
|
|
+ name="name"
|
|
|
+ label="姓名"
|
|
|
+ rules={[{ required: true, message: '请输入名称' }]}
|
|
|
+ />
|
|
|
+ <ProFormText name="phone" label="手机号" />
|
|
|
+ </Col>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormSelect
|
|
|
+ name="accountType"
|
|
|
+ label="账号类型"
|
|
|
+ options={accountType.map(item => ({ label: item.name, value: item.value }))}
|
|
|
+ rules={[{ required: true, message: '请选择账号类型' }]}
|
|
|
+ />
|
|
|
+ {type === ModalType.ADD && (
|
|
|
+ <ProFormText
|
|
|
+ name="password"
|
|
|
+ label="密码"
|
|
|
+ rules={[{ required: true, message: '请输入密码' }]}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+
|
|
|
+ <ProFormSelect
|
|
|
+ name="gender"
|
|
|
+ label="性别"
|
|
|
+ options={[
|
|
|
+ { label: '男', value: 0 },
|
|
|
+ { label: '女', value: 1 }
|
|
|
+ ]}
|
|
|
+ rules={[{ required: true, message: '请选择性别' }]}
|
|
|
+ />
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
</ProForm>
|
|
|
</Modal>
|
|
|
)
|