import { ActionType, ProColumns } from '@ant-design/pro-table'; import { ParamsType } from '@ant-design/pro-components'; import { Button, Modal, Space, Tag, message } from 'antd'; import React, { useMemo, useRef, useState } from 'react'; import Truly from '../../components/Truly'; import { OPTIONS_APPROVAL, OPTIONS_APPROVAL_SEARCH, } from '../../constants/options'; import { isTrue } from '../../utils/auth'; import EditForm from './components/EditForm'; import BaseTable from '../../components/BaseTable'; import { RegionFields, batchApi, getListApi } from './services'; const Page: React.FC = () => { const [selectedRows, setSelectedRows] = useState([]); const actionRef = useRef(); const [supRegion, setSupRegion] = useState([]); const { onSubRegionForward, onSubRegionBack } = useMemo(() => { const onSubRegionForward = (record: RegionFields) => { setSupRegion((pre) => { if (record.regionCode === pre[pre.length - 1]?.regionCode) return pre; return [...pre, { ...record }]; }); actionRef.current?.reset?.(); }; const onSubRegionBack = () => { setSupRegion((pre) => { return pre.slice(0, -1); }); actionRef.current?.reset?.(); }; return { onSubRegionForward, onSubRegionBack, }; }, []); /** * @name 批量启用/批量停用 * @param selectedRows * @param regionStatus * @param optionName */ const onBatch = ( selectedRows: RegionFields[], regionStatus: string, optionName: string, ) => { const { label } = OPTIONS_APPROVAL.find((item) => item.value !== regionStatus) || {}; const flag = selectedRows.some( (item) => item.regionStatus === regionStatus, ); if (flag) { return message.warning(`请勾选状态为${label}的数据`); } Modal.confirm({ content: `是否确认执行批量${optionName}操作?`, maskClosable: true, onOk: async () => { const regionCodes = (selectedRows || []).map(({ regionCode }) => { return regionCode; }); await batchApi({ regionCodes, regionStatus }); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const columns: ProColumns[] = [ { title: '区划代码', dataIndex: 'regionCode', }, { title: '区划简称', dataIndex: 'regionDesc', hideInSearch: true, }, { title: '区划名称', dataIndex: 'regionName', // valueType: 'select', // fieldProps: { // showSearch: true, // options: orgList, // }, }, { title: '子地区数量', dataIndex: 'subcounts', hideInSearch: true, }, { title: '状态', dataIndex: 'regionStatus', valueType: 'select', hideInTable: true, request: async () => OPTIONS_APPROVAL_SEARCH, }, { title: '状态', dataIndex: 'regionStatus', valueType: 'select', hideInSearch: true, render: (text, record) => { const { label, color } = OPTIONS_APPROVAL_SEARCH.find( (item) => record.regionStatus === item.value, ) || {}; return {label || '0'}; }, }, { title: '版本', dataIndex: 'version', }, // { // title: '创建时间', // dataIndex: 'createDate', // align: 'center', // hideInSearch: true, // }, // { // title: '更新时间', // dataIndex: 'updateDate', // align: 'center', // hideInSearch: true, // }, { title: '操作', dataIndex: 'option', valueType: 'option', render: (_, record) => ( 编辑} HandleonSubmit={() => { actionRef.current?.reload(); }} /> ), }, ]; /** * @name 获取列表数据 */ async function getBaseData(params: ParamsType) { const supRegionCode = supRegion[supRegion.length - 1]?.regionCode; const { current: pageNum } = params; const PegParams = { ...params, pageNum, // regionCode: regionCode, supRegionCode: supRegionCode || '', }; const res = await getListApi(PegParams); const { total, data } = res || {}; actionRef.current?.clearSelected?.(); return { data, total, }; } return ( rowKey={'regionCode'} actionRef={actionRef} rowSelection={{ onChange(keys, selectedRows) { setSelectedRows(selectedRows); }, }} expandable={{ onExpand: () => {}, }} toolBarRender={() => [ 新增 } HandleonSubmit={() => { actionRef.current?.reload(); }} /> , , , , ]} columns={columns} childrenColumnName="children" expandRowByClick={true} request={(params) => getBaseData(params)} /> ); }; export default Page;