import { ActionType, ProColumns } from '@ant-design/pro-table'; import { ParamsType } from '@ant-design/pro-components'; import { useRequest } from 'ahooks'; import { Button, Modal, Space, Tag, message } from 'antd'; import React, { useRef, useState } from 'react'; import Truly from '../../components/Truly'; import { OPTIONS_APPROVAL, OPTIONS_ORG_EQUAL_DEGREE, OPTIONS_ORG_LEVEL, } from '../../constants/options'; import { getOrgSelections } from '../../services'; import { isTrue } from '../../utils/auth'; import BatchForm from './components/BatchForm'; import EditForm from './components/EditForm'; import ImportForm from './components/ImportForm'; import BaseTable from '../../components/BaseTable'; import { OrgFields, batchApi, delApi, getListApi } from './services'; const Page: React.FC = () => { const actionRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); /** * @name 批量启用/批量停用 * @param selectedRows * @param orgStatus * @param optionName */ const onBatch = ( selectedRows: OrgFields[], orgStatus: string, optionName: string, ) => { const { label } = OPTIONS_APPROVAL.find((item) => item.value !== orgStatus) || {}; const flag = selectedRows.some((item) => item.orgStatus === orgStatus); if (flag) { return message.warning(`请勾选状态为${label}的数据`); } Modal.confirm({ content: `是否确认执行批量${optionName}操作?`, maskClosable: true, onOk: async () => { const orgCodes = (selectedRows || []) .map(({ orgCode }) => { return orgCode; }) .join(','); await batchApi({ orgCodes, orgStatus }); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; /** * @name 批量删除 * @param selectedRows */ const onDel = (selectedRows: OrgFields[]) => { Modal.confirm({ content: `是否确认执行批量删除操作?`, maskClosable: true, onOk: async () => { const orgCodes = (selectedRows || []) .map(({ orgCode }) => { return orgCode; }) .join(','); await delApi(orgCodes); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; /** * @name 获取列表数据 */ async function getBaseData(params: ParamsType) { const { current: pageNum } = params; const pageParams = { pageNum, ...params, }; const res = await getListApi(pageParams); const { total, data } = res || {}; actionRef.current?.clearSelected?.(); return { data, total, }; } const { data: orgList } = useRequest(() => getOrgSelections({ orgStatus: '' }), ); const columns: ProColumns[] = [ { title: '机构名称', dataIndex: 'orgName', hideInSearch: true, width: 200, ellipsis: true, }, { title: '机构名称', dataIndex: 'orgCode', hideInTable: true, valueType: 'select', fieldProps: { showSearch: true, options: orgList, }, }, { title: '机构联系电话', dataIndex: 'orgPhone', hideInSearch: true, }, { title: '等级', dataIndex: 'orgLevel', valueType: 'select', request: async () => OPTIONS_ORG_LEVEL, }, { title: '等次', dataIndex: 'orgDegree', valueType: 'select', request: async () => OPTIONS_ORG_EQUAL_DEGREE, }, { title: '医护人员', dataIndex: 'docCounts', hideInSearch: true, }, { title: '科室', dataIndex: 'deptCounts', hideInSearch: true, }, { title: '床位', dataIndex: 'bedCounts', hideInSearch: true, }, { title: '状态', dataIndex: 'orgStatus', valueType: 'select', hideInTable: true, request: async () => OPTIONS_APPROVAL, }, { title: '状态', dataIndex: 'orgStatus', valueType: 'select', hideInSearch: true, render: (text, record) => { const { label, color } = OPTIONS_APPROVAL.find((item) => record.orgStatus === item.value) || {}; return {label || '待审核'}; }, }, { title: '版本号', dataIndex: 'version', // request: async () => OPTIONS_ORG_STATUS, }, { title: '操作', dataIndex: 'option', valueType: 'option', render: (_, record) => ( 查看} // onSubmit={() => { // actionRef.current?.reload(); // }} /> 编辑} onSubmit={() => { actionRef.current?.reload(); }} /> ), }, ]; return ( rowKey={'orgCode'} actionRef={actionRef} rowSelection={{ onChange(keys, selectedRows) { setSelectedRows(selectedRows); }, }} toolBarRender={() => [ 新增} onSubmit={() => { actionRef.current?.reload(); }} /> , 导入} onSubmit={() => { actionRef.current?.reload(); }} /> , , , 批量审批 } onSubmit={() => { actionRef.current?.reload(); }} /> , , ]} columns={columns} request={(params) => getBaseData(params)} /> ); }; export default Page;