import { ParamsType, ProFormInstance } 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_BATCH, OPTIONS_BED_TYPE, } from '../../constants/options'; import { getOrgSelections, getDeptSelections } 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 { ActionType, ProColumns } from '@ant-design/pro-table'; import { BedFields, batchApi, delApi, getListApi } from './services'; const Page: React.FC = () => { const actionRef = useRef(); const formRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); const { data: orgList } = useRequest(getOrgSelections); const { data: deptList, run: getDeptOptions, mutate: mutateDeptOptions, } = useRequest(getDeptSelections, { manual: true, onSuccess() { formRef.current?.setFieldValue('deptCode', undefined); }, }); const columns: ProColumns[] = [ { title: '床位编码', dataIndex: 'bedCode', }, { title: '床号', dataIndex: 'bedNo', hideInSearch: true, }, { title: '机构名称', dataIndex: 'orgCode', valueType: 'select', hideInTable: true, fieldProps: { options: orgList || [], showSearch: true, onChange: (orgCode: string) => { getDeptOptions({ orgCode }); }, }, }, { title: '机构名称', dataIndex: 'orgName', hideInSearch: true, }, { title: '科室名称', dataIndex: 'deptCode', valueType: 'select', hideInTable: true, fieldProps: { options: deptList || [], showSearch: true, }, }, { title: '科室名称', dataIndex: 'deptName', hideInSearch: true, }, { title: '床位类型', dataIndex: 'bedClass', valueType: 'select', hideInTable: true, request: async () => OPTIONS_BED_TYPE, }, { title: '床位类型', dataIndex: 'bedClass', hideInSearch: true, render: (_, record) => { const { label } = OPTIONS_BED_TYPE.find((item) => item.value === record.bedClass) || {}; return label || '-'; }, }, { title: '状态', dataIndex: 'bedStatus', valueType: 'select', hideInTable: true, request: async () => OPTIONS_APPROVAL, }, { title: '状态', dataIndex: 'bedStatus', hideInSearch: true, render: (_, record) => { const { label, color } = OPTIONS_APPROVAL.find((item) => item.value === record.bedStatus) || {}; if (label) { return {label || ''}; } return '-'; }, }, { title: '版本号', dataIndex: 'version', }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 160, fixed: 'right', render: (_, record) => ( 查看 } /> 编辑 } onSubmit={() => { actionRef.current?.reload(); }} /> ), }, ]; /** * @name 批量启用/批量停用/批量审批/批量驳回 * @param selectedRows * @param bedStatus */ const onBatch = (selectedRows: BedFields[], bedStatus: string) => { if (bedStatus === '1') { const isCancel = selectedRows.some((item) => item.bedStatus !== '2'); if (isCancel) { return message.warning('请勾选状态为已停用的数据!'); } } else if (bedStatus === '2') { const isCancel = selectedRows.some((item) => item.bedStatus !== '1'); if (isCancel) { return message.warning('请勾选状态为已启用的数据!'); } } const { label } = OPTIONS_BATCH.find((item) => item.value === bedStatus) || {}; Modal.confirm({ content: `是否确认执行批量${label}操作?`, maskClosable: true, onOk: async () => { const beds = selectedRows.map(({ bedCode, deptCode, orgCode }) => { return { bedCode, deptCode, orgCode }; }); await batchApi({ beds, bedStatus }); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onDel = (selectedRows: BedFields[]) => { Modal.confirm({ content: `是否确认执行批量删除操作?`, maskClosable: true, onOk: async () => { const beds = (selectedRows || []).map( ({ orgCode, deptCode, bedCode }) => { return { orgCode, deptCode, bedCode }; }, ); await delApi(beds); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; return ( rowKey={(record) => { return `${record.deptCode}-${record.bedCode}`; }} actionRef={actionRef} formRef={formRef} rowSelection={{ onChange(keys, selectedRows) { setSelectedRows(selectedRows); }, }} onReset={() => { mutateDeptOptions([]); }} toolBarRender={() => [ 新增} onSubmit={() => { actionRef.current?.reload(); }} /> , 导入} onSubmit={() => { actionRef.current?.reload(); }} /> , , , 批量审批 } onSubmit={() => { actionRef.current?.reload(); }} /> , , ]} columns={columns} request={async (params: ParamsType) => { const { current: pageNum = 1, ...rest } = params; const pageParams = { ...rest, pageNum, }; const res = await getListApi(pageParams); const { total, data } = res || {}; actionRef.current?.clearSelected?.(); return { data, total, }; }} /> ); }; export default Page;