import { ParamsType } from '@ant-design/pro-components'; import { ProColumns, ActionType } from '@ant-design/pro-table'; 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 } 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 { DeptFields, getListApi, batchApi, delApi } from './services'; const Page: React.FC = () => { const actionRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); /** * @name 获取列表数据 */ async function getBaseData(params: ParamsType) { const { current: pageNum } = params; const PegParams = { ...params, pageNum, }; const res = await getListApi(PegParams); const { total, data } = res || {}; actionRef.current?.clearSelected?.(); return { data, total, }; } /** * @name 批量启用/批量停用/批量审批/批量驳回 * @param selectedRows * @param docStatus */ const onBatch = ( selectedRows: DeptFields[], deptStatus: string, optionName: string, ) => { const { label } = OPTIONS_APPROVAL.find((item) => item.value !== deptStatus) || {}; const flag = selectedRows.some((item) => item.deptStatus === deptStatus); if (flag) { return message.warning(`请勾选状态为${label}的数据`); } Modal.confirm({ content: `是否确认执行批量${optionName}操作?`, maskClosable: true, onOk: async () => { const depts = selectedRows.map(({ orgCode, insDeptCode }) => { return { orgCode, deptCode: insDeptCode }; }); await batchApi({ depts, deptStatus }); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; /** * @name 批量删除 * @param selectedRows */ const onDel = (selectedRows: DeptFields[]) => { Modal.confirm({ content: `是否确认执行批量删除操作?`, maskClosable: true, onOk: async () => { const depts = selectedRows.map(({ orgCode, insDeptCode }) => { return { orgCode, deptCode: insDeptCode }; }); await delApi(depts); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const { data: orgList } = useRequest(getOrgSelections); const columns: ProColumns[] = [ { title: '机构名称', dataIndex: 'orgName', hideInSearch: true, ellipsis: true, }, { title: '机构名称', dataIndex: 'orgCode', hideInTable: true, valueType: 'select', fieldProps: { showSearch: true, options: orgList, }, }, { title: '科室名称', dataIndex: 'deptName', }, { title: '内部代码', dataIndex: 'insDeptCode', hideInSearch: true, }, { title: '标准代码', dataIndex: 'staDeptCode', hideInSearch: true, }, { title: '下级科室数', dataIndex: 'subCounts', hideInSearch: true, }, { title: '联系电话', dataIndex: 'deptPhone', hideInSearch: true, }, { title: '病区名称', dataIndex: 'wardName', hideInSearch: true, }, { title: '状态', dataIndex: 'deptStatus', valueType: 'select', hideInTable: true, request: async () => OPTIONS_APPROVAL, }, { title: '状态', dataIndex: 'deptStatus', valueType: 'select', hideInSearch: true, render: (text, record) => { const { label, color } = OPTIONS_APPROVAL.find((item) => record.deptStatus === item.value) || {}; return {label || '待审核'}; }, }, { title: '版本号', dataIndex: 'version', }, { title: '操作', dataIndex: 'option', valueType: 'option', render: (_, record) => ( {}} trigger={} > actionRef.current?.reload()} trigger={} > ), }, ]; return ( rowKey={(record) => `${record.orgCode} + ${record.insDeptCode}`} actionRef={actionRef} rowSelection={{ onChange(keys, selectedRows) { setSelectedRows(selectedRows); }, }} toolBarRender={() => [ actionRef.current?.reload()} trigger={ } > , 导入} onSubmit={() => { actionRef.current?.reload(); }} /> , , , 批量审批 } onSubmit={() => { actionRef.current?.reload(); }} /> , , ]} columns={columns} request={(params) => getBaseData(params)} /> ); }; export default Page;