|
@@ -1,157 +0,0 @@
|
|
|
-import { useRequest } from 'umi'
|
|
|
-import { useRef, useEffect } from 'react'
|
|
|
-import ProForm, { DrawerForm, ProFormText } from '@ant-design/pro-form'
|
|
|
-import { message } from 'antd'
|
|
|
-import type { FormInstance } from 'antd'
|
|
|
-import { addInstitution, updateInstitution } from '@/services/api/institution'
|
|
|
-
|
|
|
-export enum ModalType {
|
|
|
- ADD = 0,
|
|
|
- UPDATE = 1
|
|
|
-}
|
|
|
-
|
|
|
-type CompanyModalProps = {
|
|
|
- visible: boolean
|
|
|
- setVisible: (visible: boolean) => void
|
|
|
- type: ModalType
|
|
|
- defaultFormData?: API.InstitutionListItem
|
|
|
- pTypeList: API.ProjectTypeList
|
|
|
- reloadTable: () => void
|
|
|
-}
|
|
|
-
|
|
|
-const CompanyDrawer: React.FC<CompanyModalProps> = ({
|
|
|
- visible,
|
|
|
- setVisible,
|
|
|
- type,
|
|
|
- defaultFormData,
|
|
|
- // pTypeList,
|
|
|
- reloadTable
|
|
|
-}) => {
|
|
|
- const ref = useRef<FormInstance>(null)
|
|
|
- useEffect(() => {
|
|
|
- defaultFormData && ref.current?.setFieldsValue({ ...defaultFormData })
|
|
|
- }, [defaultFormData])
|
|
|
- const { run: tryUpdateInstitution } = useRequest(updateInstitution, {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- message.success('更新成功')
|
|
|
- }
|
|
|
- })
|
|
|
- const { run: tryAddInstitution } = useRequest(addInstitution, {
|
|
|
- manual: true,
|
|
|
- onSuccess: () => {
|
|
|
- message.success('创建成功')
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- const handleOnFinish = () => {
|
|
|
- ref.current?.validateFields().then(async values => {
|
|
|
- try {
|
|
|
- // 执行表单提交
|
|
|
- if (type === ModalType.ADD) {
|
|
|
- console.log('111')
|
|
|
-
|
|
|
- await tryAddInstitution(values)
|
|
|
- } else {
|
|
|
- await tryUpdateInstitution(values)
|
|
|
- }
|
|
|
- setVisible(false)
|
|
|
- reloadTable()
|
|
|
- ref.current?.resetFields()
|
|
|
- } catch (error) {
|
|
|
- message.error(error)
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- return (
|
|
|
- <DrawerForm
|
|
|
- width="60vw"
|
|
|
- formRef={ref}
|
|
|
- visible={visible}
|
|
|
- title={type === ModalType.ADD ? '新增企事业单位' : '编辑企事业单位'}
|
|
|
- onVisibleChange={setVisible}
|
|
|
- onFinish={() => handleOnFinish()}>
|
|
|
- <ProForm.Group>
|
|
|
- {type === ModalType.UPDATE ? <ProFormText width="md" name="ID" hidden /> : null}
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="name"
|
|
|
- label="项目名称"
|
|
|
- rules={[{ required: true, message: '请输入项目名称' }]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- <ProForm.Group>
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="acronym"
|
|
|
- label="简称"
|
|
|
- rules={[{ required: true, message: '请输入简称' }]}
|
|
|
- />
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="organizationCode"
|
|
|
- label="组织架构代码"
|
|
|
- rules={[{ required: true, message: '请输入组织架构代码' }]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- <ProForm.Group>
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="bank"
|
|
|
- label="银行"
|
|
|
- rules={[{ required: true, message: '请输入银行' }]}
|
|
|
- />
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="phone"
|
|
|
- label="手机"
|
|
|
- rules={[{ required: true, message: '请输入手机' }]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- <ProForm.Group>
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="enterpriseCode"
|
|
|
- label="企业代码"
|
|
|
- rules={[{ required: true, message: '请输入企业代码' }]}
|
|
|
- />
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="idCard"
|
|
|
- label="身份证号码"
|
|
|
- rules={[{ required: true, message: '请输入身份证号码' }]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- <ProForm.Group>
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="bankAccount"
|
|
|
- label="银行账号"
|
|
|
- rules={[{ required: true, message: '请输入银行账号' }]}
|
|
|
- />
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="legalPerson"
|
|
|
- label="法人代表"
|
|
|
- rules={[{ required: true, message: '请输入法人代表' }]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- <ProForm.Group>
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="fax"
|
|
|
- label="传真"
|
|
|
- rules={[{ required: true, message: '请输入传真' }]}
|
|
|
- />
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="address"
|
|
|
- label="地址"
|
|
|
- rules={[{ required: true, message: '请输入地址' }]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- </DrawerForm>
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-export default CompanyDrawer
|