lanjianrong 3 gadi atpakaļ
vecāks
revīzija
7a1da7fa5c

+ 29 - 3
src/pages/Institutions/Company/Add/index.tsx

@@ -1,15 +1,18 @@
 import { useEffect } from 'react'
 import { BaseMenuEnum } from '@/pages/Schema/Base'
-import { connect } from 'umi'
+import { connect, useRequest, history } from 'umi'
 import FormRender, { useForm } from 'form-render'
 import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
 import type { ConnectProps } from 'umi'
 import { PageContainer } from '@ant-design/pro-layout'
+import { Button, message } from 'antd'
+import { addInstitution, updateInstitution } from '@/services/api/institution'
 
 type CompanyAddProps = ConnectProps & {
   schema?: Record<string, any> | null
 }
 const CompanyAdd: React.FC<CompanyAddProps> = ({ dispatch, schema }) => {
+  const form = useForm()
   useEffect(() => {
     dispatch({
       type: 'schemaBase/querySchema',
@@ -18,11 +21,34 @@ const CompanyAdd: React.FC<CompanyAddProps> = ({ dispatch, schema }) => {
       }
     })
   }, [])
-  const form = useForm()
+  const { run: tryUpdateInstitution } = useRequest(updateInstitution, {
+    manual: true,
+    onSuccess: () => {
+      message.success('更新成功')
+      history.push('/institutions/company/list')
+    }
+  })
+  const { run: tryAddInstitution } = useRequest(addInstitution, {
+    manual: true,
+    onSuccess: () => {
+      message.success('创建成功')
+      history.push('/institutions/company/list')
+    }
+  })
+  const onFinish = (formData, errors) => {
+    console.log('formData:', formData, 'errors', errors)
+    tryAddInstitution(formData)
+  }
+
   return (
     <PageContainer title={false}>
       <div className="bg-white p-4">
-        {schema && <FormRender form={form} schema={JSON.parse(schema)} />}
+        {schema && <FormRender form={form} schema={JSON.parse(schema)} onFinish={onFinish} />}
+        <div className="ml-137px">
+          <Button type="primary" onClick={form.submit}>
+            提交
+          </Button>
+        </div>
       </div>
     </PageContainer>
   )

+ 44 - 10
src/pages/Institutions/Company/List/index.tsx

@@ -1,28 +1,40 @@
+import dayjs from 'dayjs'
 import ProTable from '@ant-design/pro-table'
-import type { ProColumnType, ActionType } from '@ant-design/pro-table'
-import { Button } from 'antd'
 import consts from '@/utils/consts'
+import CompanyModal, { ModalType } from '../Detail/components/CompanyModal'
+import { Button } from 'antd'
 import { useRef, useState, useEffect } from 'react'
 import { connect, history } from 'umi'
+import { queryInstitutionList } from '@/services/api/institution'
+import type { ProColumnType, ActionType } from '@ant-design/pro-table'
 import type { ConnectProps } from 'umi'
 import type { ProjectModelState } from '../../model'
-import CompanyModal, { ModalType } from '../Detail/components/CompanyModal'
-import { queryInstitutionList } from '@/services/api/institution'
-import dayjs from 'dayjs'
+import type { SchemaBaseModelState } from '@/pages/Schema/Base/model'
+import { BaseMenuEnum } from '@/pages/Schema/Base'
 // import CompanyName from './CompanyName'
 
 type ListProps = ConnectProps & {
   pTypeList: { label: string; value: string }[]
+  base: Record<string, any>
 }
 
-const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
+const CompanyList: React.FC<ListProps> = ({ base, dispatch, pTypeList }) => {
   const tRef = useRef<ActionType>(null)
+  const schema = base?.[BaseMenuEnum.COMPANY]?.schema
   useEffect(() => {
     if (!pTypeList.length) {
       dispatch({
         type: 'project/queryProjectTypeList'
       })
     }
+    if (!base[BaseMenuEnum.COMPANY]) {
+      dispatch({
+        type: 'schemaBase/querySchema',
+        payload: {
+          columnType: BaseMenuEnum.COMPANY
+        }
+      })
+    }
   }, [])
   const [state, setState] = useState({
     params: {
@@ -120,13 +132,32 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
       )
     }
   ]
+
+  function generateColumns(c, s) {
+    // if (!s) return c
+    console.log(s && JSON.parse(s))
+    // 新的列
+    const nC = [...c]
+    if (s) {
+      const properties = JSON.parse(s).properties
+      const keys = Object.keys(properties)
+      keys.forEach(item => {
+        const isExist = c.some(column => column.dataIndex === item)
+        // 该列在columns中未定义
+        if (!isExist) {
+          nC.splice(-2, 0, { dataIndex: item, title: properties[item].title })
+        }
+      })
+    }
+    return nC
+  }
   return (
     <div>
       <ProTable<API.InstitutionListItem>
         rowKey="ID"
         params={state.params}
         actionRef={tRef}
-        columns={columns}
+        columns={generateColumns(columns, schema)}
         request={async (params, filter, sorter) => {
           const { code = -1, data: { items = [], totle = 0 } = {} } = await queryInstitutionList({
             ...params,
@@ -167,6 +198,9 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
   )
 }
 
-export default connect(({ project }: { project: ProjectModelState }) => ({
-  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID }))
-}))(CompanyList)
+export default connect(
+  ({ project, schemaBase }: { project: ProjectModelState; schemaBase: SchemaBaseModelState }) => ({
+    pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.ID })),
+    base: schemaBase.base
+  })
+)(CompanyList)

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

@@ -57,12 +57,12 @@ const CompanyList: React.FC<ListProps> = ({ dispatch, accountType }) => {
         return obj
       }, {})
     },
-    {
-      dataIndex: 'institution',
-      title: '所属企事业单位',
-      renderText: (_, record) => record.institution.name
-      // valueEnum:
-    },
+    // {
+    //   dataIndex: 'institution',
+    //   title: '所属企事业单位',
+    //   renderText: (_, record) => record.institution.name
+    //   // valueEnum:
+    // },
     {
       dataIndex: 'createdTime',
       title: '创建时间',