import React, { useEffect, useState } from "react"; import { Form, Button, Table, Input, Tree, Space, Tooltip, Spin } from 'antd'; import { SearchOutlined, DeleteOutlined, DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons'; import type { ColumnsType, TablePaginationConfig } from 'antd/es/table'; import { connect } from 'umi'; import SupplierViewModal from './components/SupplierViewModal'; import SupplierDetailModal from './components/SupplierDetailModal'; import { treeData, getPagePe } from './services'; import tableProps from '@/utils/tableProps' type OptionType = { label: string; value: string }; interface Data { id: number; name: string; region: string; supplierType: string; personName: string; regTime: string; status: string; idCard?: string; personPhone?: string; type?: string; createTime?: string; } interface Props { dispatch: any; } interface TreeNode { key: string; title: string; orgId: string; orgName: string; [key: string]: any; children?: TreeNode[]; } function formatTreeData(nodes: any[]): TreeNode[] { return nodes.map(node => ({ ...node, key: node.orgId, title: node.orgName })); } function updateNodeChildren(list: TreeNode[], key: string, children: TreeNode[]): TreeNode[] { return list.map(item => { if (item.key === key) return { ...item, children }; if (item.children) return { ...item, children: updateNodeChildren(item.children, key, children) }; return item; }); } const findFirstLeafKey = (nodes: any[]): string | undefined => { for (const node of nodes) { if (!node.children) return node.key; const found = findFirstLeafKey(node.children); if (found) return found; } return undefined; }; const PersonQualifiedSupplierQuery: React.FC = ({ dispatch }) => { const [form] = Form.useForm(); const [dataTree, setDataTree] = useState([]); const [treeSelected, setTreeSelected] = useState([]); const [selectedKeys, setSelectedKeys] = useState(''); const [data, setData] = useState([]); const [loading, setLoading] = useState(false); const [treeLoading, setTreeLoading] = useState(false); const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 }); const [viewVisible, setViewVisible] = useState(false); const [detailVisible, setDetailVisible] = useState(false); const [currentRecord, setCurrentRecord] = useState(null); // 查询 const handleSearch = () => { setPagination(p => ({ ...p, current: 1 })); getList(selectedKeys); }; const handleReset = () => { form.resetFields(); setPagination(p => ({ ...p, current: 1 })); getList(selectedKeys); }; const handleTreeSelect = (keys: React.Key[]) => { const key = keys[0] as string; if(key) { setSelectedKeys(key); setTreeSelected([key]); getList(key); } }; // 懒加载树节点 const onLoadTreeData = async (treeNode: any) => { if (treeNode.children && treeNode.children.length > 0) return; setTreeLoading(true); try { const res = await treeData({ upOrgId: treeNode.orgId }); const { code, data } = res; if (code === 200) { const children = formatTreeData(data); setDataTree(origin => updateNodeChildren(origin, treeNode.key, children)); } } finally { setTreeLoading(false); } }; const getList = async (treeId: string, pageNo: number = 1, pageSize: number = 10) => { setLoading(true); try { const values = form.getFieldsValue(); const { code, data, message } = await getPagePe({ pageNo, pageSize, treeId, ...values }); if (code === 200) { setData(data.records); setPagination({ current: pageNo, pageSize, total: data.total }); } else { message.error(message); } } finally { setLoading(false); } }; // 初始化 useEffect(() => { setTreeLoading(true); treeData({}).then((res) => { const { code, data } = res; if (code === 200) { const tree = formatTreeData(data); setDataTree(tree); const firstLeafKey = findFirstLeafKey(tree); if (firstLeafKey) { setSelectedKeys(firstLeafKey); setTreeSelected([firstLeafKey]); getList(firstLeafKey); } } }).finally(() => { setTreeLoading(false); }); }, []); const columns: ColumnsType = [ { title: '序号', dataIndex: 'index', key: 'index', align: 'center', width: 60, render: (_: any, __: any, idx: number) => (((pagination.current ?? 1) - 1) * (pagination.pageSize ?? 10)) + idx + 1, }, { title: '姓名', dataIndex: 'personName', key: 'personName', align: 'center', ellipsis: true, render: (dom, record) => { dispatch({ type: 'globalModal/show', payload: { id: record.id }, }); }}> {record.personName} , }, { title: '身份证号', dataIndex: 'idCard', key: 'idCard', align: 'center', ellipsis: true }, { title: '联系电话', dataIndex: 'personPhone', key: 'personPhone', align: 'center', ellipsis: true }, { title: '准入单位', dataIndex: 'type', key: 'type', align: 'center' }, { title: '创建部门', dataIndex: 'regTime', key: 'regTime', align: 'center' }, { title: '创建时间', dataIndex: 'createTime', key: 'createTime', align: 'center', ellipsis: true }, { title: '操作', key: 'option', align: 'center', width: 140, render: (record: any) => ( { setCurrentRecord(record.id); setViewVisible(true); }}>查看 { setCurrentRecord(record.id); setDetailVisible(true); }}>准入明细 ), }, ]; const [collapsed, setCollapsed] = useState(false); return ( <>
{!collapsed && ( <>
{dataTree.length > 0 && ( )}
setCollapsed(true)}>
)} {collapsed && (
setCollapsed(false)}>
)}
getList(selectedKeys, pagination.current!, pagination.pageSize!)} style={{ flex: 1, minHeight: 0 }} scroll={{ y: 'calc(100vh - 350px)' }} /> setViewVisible(false)} /> setDetailVisible(false)} /> ); }; export default connect()(PersonQualifiedSupplierQuery);