|
@@ -0,0 +1,171 @@
|
|
|
+import { addSubject, delSubject, querySubject } from '@/services/api/subject'
|
|
|
+import consts from '@/utils/consts'
|
|
|
+import { PageContainer } from '@ant-design/pro-layout'
|
|
|
+import ProTable from '@ant-design/pro-table'
|
|
|
+import type { ProColumnType } from '@ant-design/pro-table'
|
|
|
+import React, { useEffect, useRef, useState } from 'react'
|
|
|
+import { Button, message, Modal } from 'antd'
|
|
|
+import { ModalForm, ProFormSelect } from '@ant-design/pro-form'
|
|
|
+import { useRequest } from '@umijs/max'
|
|
|
+import { queryInstitutionList } from '@/services/api/institution'
|
|
|
+import { DeleteOutlined } from '@ant-design/icons'
|
|
|
+
|
|
|
+const Mainstay = () => {
|
|
|
+ const tRef = useRef<ActionType>(null)
|
|
|
+ const formRef = useRef<ProFormInstance>(null)
|
|
|
+ const [state, setState] = useState<iRestrictProps>({
|
|
|
+ params: {
|
|
|
+ search: null
|
|
|
+ },
|
|
|
+ modalVisible: false,
|
|
|
+ institutionList: []
|
|
|
+ })
|
|
|
+
|
|
|
+ const { run: tryInstitutionList } = useRequest(
|
|
|
+ () => queryInstitutionList({ current: 1, pageSize: 214000, subject: true }),
|
|
|
+ {
|
|
|
+ manual: true,
|
|
|
+ onSuccess(result) {
|
|
|
+ setState({
|
|
|
+ ...state,
|
|
|
+ institutionList: result.items
|
|
|
+ .filter(item => !item.isSubjectBind)
|
|
|
+ .map(item => ({ label: item.name, value: item.ID }))
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ const { run: tryAddSubject } = useRequest(addSubject, {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ message.success('添加成功')
|
|
|
+ tRef.current?.reload()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const handleDelSubject = ID => {
|
|
|
+ Modal.confirm({
|
|
|
+ title: '删除主体',
|
|
|
+ content: '确认删除该行数据?',
|
|
|
+ okButtonProps: {
|
|
|
+ danger: true
|
|
|
+ },
|
|
|
+ onOk: async () => {
|
|
|
+ // 进行删除的接口请求
|
|
|
+ const { code = -1 } = await delSubject({ ID })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ message.success('删除成功')
|
|
|
+ tRef.current?.reload()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ tryInstitutionList()
|
|
|
+ }, [])
|
|
|
+ const columns: ProColumnType<API.SubjectParams> = [
|
|
|
+ {
|
|
|
+ dataIndex: 'name',
|
|
|
+ key: 'name',
|
|
|
+ title: '名称',
|
|
|
+ width: 86,
|
|
|
+ onHeaderCell: () => ({ style: { textAlign: 'center' } })
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'operate',
|
|
|
+ width: 61,
|
|
|
+ align: 'center',
|
|
|
+ onHeaderCell: () => ({ style: { textAlign: 'center' } }),
|
|
|
+ render: (_, record) => (
|
|
|
+ <div className="divide-x divide-bg-gray-400 flex flex-row justify-center">
|
|
|
+ <div
|
|
|
+ className="text-hex-fd3995 cursor-pointer hover:text-hex-e7026e"
|
|
|
+ onClick={() => handleDelSubject(record.ID)}>
|
|
|
+ <DeleteOutlined />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ return (
|
|
|
+ <PageContainer title={false}>
|
|
|
+ <ProTable<API.SubjectParams>
|
|
|
+ rowKey="ID"
|
|
|
+ actionRef={tRef}
|
|
|
+ params={state.params}
|
|
|
+ columns={columns}
|
|
|
+ search={false}
|
|
|
+ request={async (params, filter, sorter) => {
|
|
|
+ const { code = -1, data: { items = [], total = 0 } = {} } = await querySubject({
|
|
|
+ ...params,
|
|
|
+ ...filter,
|
|
|
+ ...sorter
|
|
|
+ })
|
|
|
+ return {
|
|
|
+ data: items,
|
|
|
+ success: code === consts.RET_CODE.SUCCESS,
|
|
|
+ total
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ toolbar={{
|
|
|
+ search: {
|
|
|
+ onSearch: val => setState({ ...state, params: { ...state.params, search: val } }),
|
|
|
+ style: { width: '250px' },
|
|
|
+ placeholder: '请搜索业务主体名称'
|
|
|
+ },
|
|
|
+ actions: [
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ key="add_flow_btn"
|
|
|
+ onClick={() => {
|
|
|
+ tryInstitutionList()
|
|
|
+ setState({
|
|
|
+ ...state,
|
|
|
+ modalVisible: true
|
|
|
+ })
|
|
|
+ }}>
|
|
|
+ 添加主体
|
|
|
+ </Button>
|
|
|
+ ]
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <ModalForm
|
|
|
+ visible={state.modalVisible}
|
|
|
+ isKeyPressSubmit
|
|
|
+ layout="horizontal"
|
|
|
+ labelCol={{ span: 4 }}
|
|
|
+ modalProps={{
|
|
|
+ width: '30%'
|
|
|
+ }}
|
|
|
+ onVisibleChange={visible => {
|
|
|
+ setState({ ...state, modalVisible: visible })
|
|
|
+ setTimeout(() => {
|
|
|
+ if (!visible) formRef.current?.resetFields()
|
|
|
+ }, 80)
|
|
|
+ }}
|
|
|
+ title={'添加主体'}
|
|
|
+ formRef={formRef}
|
|
|
+ onFinish={async values => {
|
|
|
+ try {
|
|
|
+ await tryAddSubject(values)
|
|
|
+ tRef.current?.reload()
|
|
|
+ return true
|
|
|
+ } catch (error) {
|
|
|
+ message.error(error)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }}>
|
|
|
+ <ProFormSelect
|
|
|
+ label="单位选择"
|
|
|
+ tooltip="同步新增隶属该主体的审批业务、业务编号、步骤执行者、业务步骤、业务事项、审批角色、指标库、材价库业务。"
|
|
|
+ name="institutionIDs"
|
|
|
+ className="w-full"
|
|
|
+ options={state.institutionList}
|
|
|
+ />
|
|
|
+ </ModalForm>
|
|
|
+ </PageContainer>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+export default Mainstay
|