Browse Source

feat: 企事业单位-单位管理增改

lanjianrong 3 năm trước cách đây
mục cha
commit
0bb6b3d3b1

+ 145 - 0
src/pages/Institutions/Company/components/CompanyModal.tsx

@@ -0,0 +1,145 @@
+import { useRequest } from 'umi'
+import { useRef, useEffect } from 'react'
+import ProForm, { ProFormSelect, ProFormText } from '@ant-design/pro-form'
+import { Col, message, Modal, Row } from 'antd'
+import { addProject, updateProject } from '@/services/api/project'
+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 CompanyModal: React.FC<CompanyModalProps> = ({
+  visible,
+  setVisible,
+  type,
+  defaultFormData,
+  // pTypeList,
+  reloadTable
+}) => {
+  const layout = {
+    layout: 'horizontal',
+    labelCol: { flex: '100px' }
+  }
+  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 (
+    <Modal
+      width="35vw"
+      visible={visible}
+      onCancel={() => {
+        ref.current?.resetFields()
+        setVisible(false)
+      }}
+      title={type === ModalType.ADD ? '新增企事业单位' : '编辑企事业单位'}
+      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: '请输入项目名称' }]}
+        />
+        <Row>
+          <Col span={12}>
+            <ProFormText
+              name="acronym"
+              label="简称"
+              rules={[{ required: true, message: '请输入简称' }]}
+            />
+            <ProFormText
+              name="organization_code"
+              label="组织架构代码"
+              rules={[{ required: true, message: '请输入组织架构代码' }]}
+            />
+
+            <ProFormText
+              name="bank"
+              label="银行"
+              rules={[{ required: true, message: '请输入银行' }]}
+            />
+            <ProFormText
+              name="phone"
+              label="手机"
+              rules={[{ required: true, message: '请输入手机' }]}
+            />
+          </Col>
+          <Col span={12}>
+            <ProFormText
+              name="enterprise_code"
+              label="企业代码"
+              rules={[{ required: true, message: '请输入企业代码' }]}
+            />
+            <ProFormText
+              name="id_card"
+              label="身份证号码"
+              rules={[{ required: true, message: '请输入身份证号码' }]}
+            />
+            <ProFormText
+              name="bank_account"
+              label="银行账号"
+              rules={[{ required: true, message: '请输入银行账号' }]}
+            />
+            <ProFormText
+              name="legal_person"
+              label="法人代表"
+              rules={[{ required: true, message: '请输入法人代表' }]}
+            />
+          </Col>
+        </Row>
+        <ProFormText name="fax" label="传真" rules={[{ required: true, message: '请输入传真' }]} />
+        <ProFormText
+          name="address"
+          label="地址"
+          rules={[{ required: true, message: '请输入地址' }]}
+        />
+      </ProForm>
+    </Modal>
+  )
+}
+
+export default CompanyModal

+ 149 - 3
src/pages/Institutions/Company/index.tsx

@@ -1,5 +1,151 @@
-const Company = () => {
-  return <div>这是单位管理</div>
+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 { useRef, useState, useEffect } from 'react'
+import { connect } from 'umi'
+import type { ConnectProps } from 'umi'
+import type { ProjectModelState } from '../model'
+import CompanyModal, { ModalType } from './components/CompanyModal'
+import { queryInstitutionList } from '@/services/api/institution'
+
+type ListProps = ConnectProps & {
+  pTypeList: { label: string; value: string }[]
+}
+
+const CompanyList: React.FC<ListProps> = ({ dispatch, pTypeList }) => {
+  const tRef = useRef<ActionType>(null)
+  useEffect(() => {
+    if (!pTypeList.length) {
+      dispatch({
+        type: 'project/queryProjectTypeList'
+      })
+    }
+  }, [])
+  const [state, setState] = useState({
+    params: {
+      search: null
+    },
+    visible: false,
+    currentModalType: ModalType.ADD,
+    defaultFormData: null
+  })
+  // const { run: tryDelProject } = useRequest(delProject, {
+  //   manual: true,
+  //   onSuccess: () => tRef.current?.reload()
+  // })
+  const columns: ProColumnType<API.InstitutionListItem>[] = [
+    {
+      dataIndex: 'name',
+      title: '企事业单位名称'
+    },
+    {
+      dataIndex: 'acronym',
+      title: '企事业单位简称'
+    },
+    {
+      dataIndex: 'institution_account_total',
+      title: '人员账号'
+    },
+    {
+      dataIndex: 'create_time',
+      title: '创建时间'
+    },
+    // {
+    //   dataIndex: 'project_type_id',
+    //   title: '项目类型',
+    //   filters: true,
+    //   filterMultiple: false,
+    //   render: (_, record) => <div>{record.project_type.name}</div>,
+    //   valueEnum: pTypeList.reduce((prev, curr) => {
+    //     const items = { ...prev }
+    //     items[curr.value] = {
+    //       text: curr.label
+    //     }
+    //     return items
+    //   }, {})
+    // },
+    {
+      dataIndex: 'created',
+      title: '创建人'
+    },
+    {
+      title: '操作',
+      dataIndex: 'operation',
+      render: (_, record) => (
+        <div className="divide-x divide-bg-gray-400 flex flex-row">
+          <div
+            className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
+            onClick={() => {
+              setState({
+                ...state,
+                visible: true,
+                currentModalType: ModalType.UPDATE,
+                defaultFormData: record
+              })
+            }}>
+            编辑
+          </div>
+          {/* <Popconfirm
+            title="确认删除吗?"
+            okText="确认"
+            cancelText="取消"
+            onConfirm={() => tryDelProject({ id: record.id })}
+          >
+            <div className="pl-2 text-hex-fd3995 cursor-pointer hover:text-hex-e7026e">
+              <DeleteOutlined />
+            </div>
+          </Popconfirm> */}
+        </div>
+      )
+    }
+  ]
+  return (
+    <div>
+      <ProTable<API.InstitutionListItem>
+        rowKey="id"
+        params={state.params}
+        actionRef={tRef}
+        columns={columns}
+        request={async (params, filter, sorter) => {
+          const { code = -1, data: { items = [], totle = 0 } = {} } = await queryInstitutionList({
+            ...params,
+            ...filter,
+            ...sorter
+          })
+          return {
+            data: items,
+            success: code === consts.RET_CODE.SUCCESS,
+            totle
+          }
+        }}
+        toolbar={{
+          search: {
+            onSearch: val => setState({ ...state, params: { ...state.params, search: val } })
+          },
+          actions: [
+            <Button
+              onClick={() =>
+                setState({ ...state, visible: true, currentModalType: ModalType.ADD })
+              }>
+              新建企事业单位
+            </Button>
+          ]
+        }}
+        search={false}
+      />
+      <CompanyModal
+        type={state.currentModalType}
+        defaultFormData={state.defaultFormData}
+        pTypeList={pTypeList}
+        visible={state.visible}
+        reloadTable={() => tRef.current?.reload()}
+        setVisible={(visible: boolean) => setState({ ...state, visible })}
+      />
+    </div>
+  )
 }
 
-export default Company
+export default connect(({ project }: { project: ProjectModelState }) => ({
+  pTypeList: project.projectTypeList.map(item => ({ label: item.name, value: item.id }))
+}))(CompanyList)

+ 2 - 3
src/pages/Project/Management/components/ProjectModal.tsx

@@ -66,15 +66,14 @@ const ProjectModal: React.FC<ProjectModalProps> = ({
   }
   return (
     <Modal
-      width="30vw"
+      width="35vw"
       visible={visible}
       onCancel={() => {
         ref.current?.resetFields()
         setVisible(false)
       }}
       title={type === ModalType.ADD ? '新增项目' : '编辑项目'}
-      onOk={() => handleOnFinish()}
-    >
+      onOk={() => handleOnFinish()}>
       <ProForm formRef={ref} submitter={{ render: false }}>
         {type === ModalType.UPDATE ? <ProFormText name="id" hidden /> : null}
         <ProFormText

+ 2 - 2
src/services/api/institution.ts

@@ -8,7 +8,7 @@ export async function queryInstitutionList(params: API.InstitutionListParams) {
   })
 }
 /** 编辑企事业单位 */
-export async function updateInstitutionList(params: API.InstitutionUpdateParams) {
+export async function updateInstitution(params: API.InstitutionUpdateParams) {
   return request('/Institution/update', {
     method: 'POST',
     data: params
@@ -16,7 +16,7 @@ export async function updateInstitutionList(params: API.InstitutionUpdateParams)
 }
 /** 新增企事业单位 */
 export async function addInstitution(params: API.InstitutionAddParams) {
-  return request('/Institution/update', {
+  return request('/Institution/add', {
     method: 'POST',
     data: params
   })

+ 2 - 0
src/services/api/typings.d.ts

@@ -62,6 +62,8 @@ declare namespace API {
     enterprise_code?: string
     /** @name 组织结构代码 */
     organization_code?: string
+    /** @name 人员账号数量 */
+    institution_account_total?: number
     bank?: string
     bank_account?: string
     phone?: string