|
@@ -0,0 +1,144 @@
|
|
|
+import { connect, useRequest } from 'umi'
|
|
|
+import { useEffect, useRef, useState } from 'react'
|
|
|
+import { Drawer, message, Tabs } from 'antd'
|
|
|
+import { queryAcountList, getApprovalList, setApproval } from '@/services/api/institution'
|
|
|
+import { delay } from '@/utils/util'
|
|
|
+import FormRender, { useForm } from 'form-render'
|
|
|
+import { BaseMenuEnum } from '@/pages/Schema/Base'
|
|
|
+import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
|
|
|
+import type { ConnectProps } from 'umi'
|
|
|
+import type { ProjectModelState } from '../../model'
|
|
|
+import ProForm, { ProFormSelect } from '@ant-design/pro-form'
|
|
|
+
|
|
|
+export enum ModalType {
|
|
|
+ ADD = 0,
|
|
|
+ UPDATE = 1
|
|
|
+}
|
|
|
+
|
|
|
+type ProjectModalProps = ConnectProps & {
|
|
|
+ visibles: boolean
|
|
|
+ setVisible: (visibles: boolean) => void
|
|
|
+ readOnly: boolean
|
|
|
+ readOnly: boolean
|
|
|
+ type: ModalType
|
|
|
+ defaultFormData?: {
|
|
|
+ ID: string
|
|
|
+ name: string
|
|
|
+ }
|
|
|
+ reloadTable: () => void
|
|
|
+ schema?: Record<string, any> | null
|
|
|
+}
|
|
|
+const DetailModal: React.FC<ProjectModalProps> = ({
|
|
|
+ visibles,
|
|
|
+ setVisible,
|
|
|
+ readOnly,
|
|
|
+ dispatch,
|
|
|
+ schema,
|
|
|
+ defaultFormData,
|
|
|
+ pTypeList,
|
|
|
+ reloadTable
|
|
|
+}) => {
|
|
|
+ const form = useForm()
|
|
|
+ const ref = useRef<FormInstance>(null)
|
|
|
+ const { TabPane } = Tabs
|
|
|
+ const [state, setState] = useState({
|
|
|
+ acountList: [],
|
|
|
+ approvalList: []
|
|
|
+ })
|
|
|
+
|
|
|
+ const { run: tryAcountList } = useRequest(() => queryAcountList(), {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: result => {
|
|
|
+ setState({ ...state, acountList: result.items })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const { run: tryApprovalList } = useRequest(() => getApprovalList(), {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: result => {
|
|
|
+ setState({ ...state, approvalList: result.items })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const { run: trySetApproval } = useRequest(setApproval, {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('提交成功')
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (visibles && !schema) {
|
|
|
+ dispatch({
|
|
|
+ type: 'schemaBase/querySchema',
|
|
|
+ payload: {
|
|
|
+ columnType: BaseMenuEnum.PROJECT
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ tryAcountList()
|
|
|
+ tryApprovalList()
|
|
|
+ }, [visibles])
|
|
|
+
|
|
|
+ const onMount = () => {
|
|
|
+ form.setValues({ ...defaultFormData })
|
|
|
+ delay(80).then(() => {
|
|
|
+ // console.log(pTypeList)
|
|
|
+
|
|
|
+ form.setSchemaByPath('projectTypeID', {
|
|
|
+ enum: pTypeList.map(item => item.value),
|
|
|
+ enumNames: pTypeList.map(item => item.label)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const onFinish = async (formData, value) => {
|
|
|
+ await trySetApproval({ ...formData, ...value, ID: defaultFormData.ID })
|
|
|
+ setVisible(false)
|
|
|
+ reloadTable()
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <Drawer
|
|
|
+ width="50vw"
|
|
|
+ visible={visibles}
|
|
|
+ onClose={() => {
|
|
|
+ // ref.current?.resetFields()
|
|
|
+ setVisible(false)
|
|
|
+ }}
|
|
|
+ title={defaultFormData?.name}>
|
|
|
+ <Tabs>
|
|
|
+ <TabPane tab="项目信息" key="1">
|
|
|
+ {schema && (
|
|
|
+ <FormRender form={form} schema={schema} onMount={onMount} readOnly={readOnly} />
|
|
|
+ )}
|
|
|
+ </TabPane>
|
|
|
+ <TabPane tab="审批流程" key="2">
|
|
|
+ <ProForm
|
|
|
+ formRef={ref}
|
|
|
+ submitter={{ resetButtonProps: { style: { display: 'none' } } }}
|
|
|
+ onFinish={onFinish}>
|
|
|
+ <ProFormSelect
|
|
|
+ name="accountID"
|
|
|
+ label={'上报人'}
|
|
|
+ placeholder="请选择上报人"
|
|
|
+ options={state.acountList}
|
|
|
+ />
|
|
|
+ <ProFormSelect
|
|
|
+ name="approvalID"
|
|
|
+ label={'审批流程'}
|
|
|
+ placeholder="请选择审批流程"
|
|
|
+ options={state.approvalList}
|
|
|
+ />
|
|
|
+ </ProForm>
|
|
|
+ </TabPane>
|
|
|
+ </Tabs>
|
|
|
+ </Drawer>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default connect(
|
|
|
+ ({ project, schemaBase }: { project: ProjectModelState; schemaBase: SchemaBaseModelState }) => ({
|
|
|
+ pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID })),
|
|
|
+ schema: schemaBase.base[BaseMenuEnum.PROJECT]?.schema
|
|
|
+ })
|
|
|
+)(DetailModal)
|