import React, { useEffect, useState } from 'react'; import { Table, Form, Input, Button, Row, Col, DatePicker, Tabs, Space, Tooltip } from 'antd'; import { SearchOutlined, DeleteOutlined } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; //组件 import SupplierViewModal from './components/SupplierViewModal'; import SupplierExitModal from './components/SupplierExitModal'; //接口 import { getPageAgent } from './services'; //统一列表分页 import tableProps from '@/utils/tableProps' import { useSupplierDetailModal } from '@/components/SupplierDetailModalContext/SupplierDetailModalContext'; const { RangePicker } = DatePicker; const { TabPane } = Tabs; interface Columns { name: string; enterpriseType: string; deptId: string; createTime: string; id: string; } const SupplierRegisterAgent: React.FC = () => { const [form] = Form.useForm(); const [data, setData] = useState([]); const [loading, setLoading] = useState(false); const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 }); const [tabKey, setTabKey] = useState('dvs'); //查看是否显示状态 const [viewVisible, setViewVisible] = useState(false); //查看 参数传递 const [currentRecord, setCurrentRecord] = useState(''); // 新增与修改 const [exitModalVisible, setExitModalVisible] = useState(false); const [exitId, setExitId] = useState(''); const supplierDetailModal = useSupplierDetailModal(); // 查询数据 const fetchData = async (page = 1, pageSize = 10) => { setLoading(true); // 获取表单参数 const { keyword, dateRange } = form.getFieldsValue(); let params: any = { pageNo: page, pageSize, supplierType: tabKey, }; if (keyword) params.keyword = keyword; if (dateRange && dateRange.length === 2) { params.startDate = dateRange[0].format('YYYY-MM-DD'); params.endDate = dateRange[1].format('YYYY-MM-DD'); } try { const res = await getPageAgent(params); if (res.code === 200 && res.data) { setData(res.data.records || []); setPagination({ current: res.data.current || page, pageSize: res.data.size || pageSize, total: res.data.total || 0, }); } else { setData([]); setPagination({ current: 1, pageSize: 10, total: 0 }); } } finally { setLoading(false); } }; // 首次&依赖刷新 useEffect(() => { fetchData(1, pagination.pageSize); }, [tabKey]); // 查询 const handleSearch = () => { fetchData(1, pagination.pageSize); }; // 重置 const handleReset = () => { form.resetFields(); fetchData(1, pagination.pageSize); }; // 切页 const handleTableChange = (pag: any) => { fetchData(pag.current, pag.pageSize); }; // 列 const columns: ColumnsType = [ { title: '序号', dataIndex: 'index', align: 'center', width: 80, render: (_: any, __: any, idx: number) => ((pagination.current - 1) * pagination.pageSize) + idx + 1, }, { title: "供应商名称", dataIndex: "name", align: "left", width: 200, ellipsis: true, render: (dom, record) => { return ( supplierDetailModal?.(record.id)}>{record.name || ''} ) } }, { title: '创建单位', dataIndex: 'orgName', align: 'center', ellipsis: true, }, { title: '创建部门', dataIndex: 'deptName', align: 'center', }, { title: '创建时间', dataIndex: 'createTime', align: 'center', width: 180, }, { title: '操作', align: 'center', width: 120, render: (_: any, record: any) => ( { setCurrentRecord(record.id); setViewVisible(true); }}>查看 ), }, ]; return (
{/* 表格 */} handleTableChange({ current, pageSize })} style={{ flex: 1, minHeight: 0 }} scroll={{ y: 'calc(100vh - 350px)' }} /> {/* 查看组件 */} setViewVisible(false)} /> { fetchData(1, pagination.pageSize); setExitModalVisible(false) }} /> ); }; export default SupplierRegisterAgent;