import React, { useEffect, useState } from "react"; //第三方UI库/组件 import { Form, Button, Table , Input, Tree, Row, Col, Space, Tooltip } from 'antd'; import { SearchOutlined, DownloadOutlined, ReloadOutlined } from '@ant-design/icons'; //类型定义 import type { ColumnsType, TablePaginationConfig } from 'antd/es/table'; //umi 相关 import { connect } from 'umi'; //本地组件、弹窗、业务逻辑 import SupplierViewModal from './components/SupplierViewModal'; import SupplierDetailModal from './components/SupplierDetailModal'; //本地服务/接口 import { treeData, systemDict, getPagePe } from './services'; //下拉数据接口 type OptionType = { label: string; value: string }; // 列表数据接口 interface Data { id: number; name: string; region: string; supplierType: string; personName: string; regTime: string; status: string; } interface Props { dispatch: any; } const personQualifiedSupplierQuery: React.FC = ({ dispatch }) => { //搜搜表单 const [form] = Form.useForm(); // 树数据 const [dataTree, setDataTree] = useState([]); //默认选中树 const [treeSelected, setTreeSelected] = useState([]); //当前树key const [selectedKeys, setSelectedKeys] = useState(''); //列表数据 const [data, setData] = useState([]); //列表加载 const [loading, setLoading] = 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 [regionOptions, setRegionOptions] = useState([]); //集采类别 const [categoryOptions, setCategoryOptions] = useState([]); //集采库 const [storeOptions, setStoreOptions] = useState([]); // 导出 const handleExport = () => { window.open( `${SERVER_BASE}/coscoSupplierBase/getPagePeExport`, '_blank', ); }; // 查询 const handleSearch = () => { setPagination({ ...pagination, current: 1 }); getList(selectedKeys); }; // 重置 const handleReset = () => { form.resetFields(); setPagination({ ...pagination, current: 1 }); getList(selectedKeys); }; // 点击树节点请求右表 const handleTreeSelect = (keys: React.Key[]) => { const key = keys[0] as string; setSelectedKeys(key); getList(key) }; //列表方法 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); } }; // 辅助递归找第一个叶子 key(一般最下层为叶子) const findFirstLeafKey = (nodes: any[]): string | undefined => { for (const node of nodes) { if (!node.children || node.children.length === 0) return node.key; const found = findFirstLeafKey(node.children); if (found) return found; } return undefined; }; // 初始化时选中树第一个叶子节点,并请求右表 useEffect(() => { // 境内/境外 下拉 systemDict('regionOptions').then((res) => { const { code, data } = res; if (code == 200) { setRegionOptions(data) } }); // 集采类别 下拉 systemDict('categoryOptions').then((res) => { const { code, data } = res; if (code == 200) { setCategoryOptions(data) } }); // 集采库 下拉 systemDict('storeOptions').then((res) => { const { code, data } = res; if (code == 200) { setStoreOptions(data) } }); //tree数据 treeData().then((res) => { const { code, data } = res; if (code == 200) { setDataTree(data) const key = findFirstLeafKey(data); if (key) { setSelectedKeys(key); setTreeSelected([key]) getList(key) } } }) }, []); 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); }} >准入明细 ), }, ]; return ( <>
{/* 左侧树 */}
{dataTree.length > 0 && ( )}
{/* 右侧主体 */} {/* 查询表单 */}
{/* 表格 */} getList(selectedKeys, pagination.current!, pagination.pageSize!)} /> {/* 查看组件 */} setViewVisible(false)} /> {/* 准入明细组件 */} setDetailVisible(false)} /> ); }; export default connect()(personQualifiedSupplierQuery);