import { ProColumns, ActionType } 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_BATCH, OPTIONS_SEX_COMPLETE, } from '../../constants/options'; import { getOrgSelections } from '../../services'; import { isTrue } from '../../utils/auth'; import BatchForm from './components/BatchForm'; import EditForm from './components/EditForm'; import EditLicenseForm from './components/EditLicenseForm'; import ImportForm from './components/ImportForm'; import BaseTable from '../../components/BaseTable'; import { DoctorFields, batchApi, delApi, getListApi } from './services'; const Page: React.FC = () => { const actionRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); const { data: orgList } = useRequest(getOrgSelections); const columns: ProColumns[] = [ { title: '机构名称', dataIndex: 'orgCode', hideInTable: true, valueType: 'select', fieldProps: { options: orgList || [], showSearch: true, }, }, { title: '姓名', dataIndex: 'name', }, { title: '性别', dataIndex: 'sexCode', hideInSearch: true, render: (text, record) => { const { label } = OPTIONS_SEX_COMPLETE.find((item) => item.value === record.sexCode) || {}; return label || '-'; }, }, { title: '出生日期', dataIndex: 'birthDate', hideInSearch: true, }, { title: '执业点位', dataIndex: 'jobCount', hideInSearch: true, render: (_, record) => { return ( {record.jobCount}} > {record.jobCount}} onSubmit={() => { actionRef.current?.reload(); }} /> ); }, }, { title: '身份证件号', dataIndex: 'idno', }, { title: '状态', dataIndex: 'docStatus', valueType: 'select', hideInTable: true, request: async () => OPTIONS_APPROVAL, }, { title: '状态', dataIndex: 'docStatus', hideInSearch: true, render: (_, record) => { const { label, color } = OPTIONS_APPROVAL.find((item) => item.value === record.docStatus) || {}; if (label) { return {label || ''}; } return '-'; }, }, { title: '版本号', dataIndex: 'version', }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 300, render: (_, record) => ( 查看 } /> 编辑} onSubmit={() => { actionRef.current?.reload(); }} /> 新增执业执照} onSubmit={() => { actionRef.current?.reload(); }} /> ), }, ]; /** * @name 批量启用/批量停用/批量审批/批量驳回 * @param selectedRows * @param docStatus */ const onBatch = (selectedRows: DoctorFields[], docStatus: string) => { if (docStatus === '1') { const isCancel = selectedRows.some((item) => item.docStatus !== '2'); if (isCancel) { return message.warning('请勾选状态为已停用的数据!'); } } else if (docStatus === '2') { const isCancel = selectedRows.some((item) => item.docStatus !== '1'); if (isCancel) { return message.warning('请勾选状态为已启用的数据!'); } } const { label } = OPTIONS_BATCH.find((item) => item.value === docStatus) || {}; Modal.confirm({ content: `是否确认执行批量${label}操作?`, maskClosable: true, onOk: async () => { const docCodes = selectedRows.map((item) => item.uuid).join(','); await batchApi({ docCodes, docStatus }); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; /** * @name 批量删除 * @param selectedRows */ const onDel = (selectedRows: DoctorFields[]) => { Modal.confirm({ content: `是否确认执行批量删除操作?`, maskClosable: true, onOk: async () => { const uuids = (selectedRows || []) .map(({ uuid }) => { return uuid; }) .join(','); await delApi(uuids); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; return ( rowKey={'uuid'} actionRef={actionRef} rowSelection={{ onChange(keys, selectedRows) { setSelectedRows(selectedRows); }, }} toolBarRender={() => [ 新增} onSubmit={() => { actionRef.current?.reload(); }} /> , 导入} orgList={orgList || []} onSubmit={() => { actionRef.current?.reload(); }} /> , , , 批量审批 } onSubmit={() => { actionRef.current?.reload(); }} /> , , ]} columns={columns} request={async (params: ParamsType) => { const { current: pageNum, ...rest } = params; const { data = [], total = 0 } = await getListApi({ ...rest, pageNum, }); actionRef.current?.clearSelected?.(); return { data, total, }; }} /> ); }; export default Page;