Files
fe_supplier_frontend/src/pages/supplier/informationManagement/SupplierRegisterAgent/index.tsx

205 lines
5.8 KiB
TypeScript
Raw Normal View History

2025-07-02 16:18:03 +08:00
import React, { useRef, useEffect, useState } from 'react';
import { Table, Form, Input, Button, Row, Col, DatePicker, Tabs, Space, message } from 'antd';
2025-06-24 10:52:30 +08:00
import { SearchOutlined, ReloadOutlined, PlusOutlined } from '@ant-design/icons';
2025-07-02 16:18:03 +08:00
import { getPageAgent } from './services';
2025-07-03 10:24:33 +08:00
import type { ColumnsType } from 'antd/es/table';
import SupplierViewModal from './components/SupplierViewModal';
2025-07-04 10:15:56 +08:00
import SupplierExitModal from './components/SupplierExitModal';
2025-06-24 10:52:30 +08:00
const { RangePicker } = DatePicker;
2025-07-02 16:18:03 +08:00
const { TabPane } = Tabs;
2025-07-03 10:24:33 +08:00
interface Columns {
name: string;
enterpriseType: string;
deptId: string;
createTime: string;
id: string;
}
2025-06-24 10:52:30 +08:00
2025-07-02 16:18:03 +08:00
const SupplierRegisterAgent: React.FC = () => {
const [form] = Form.useForm();
const [data, setData] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0 });
const [tabKey, setTabKey] = useState('dvs');
2025-07-03 10:24:33 +08:00
//查看是否显示状态
const [viewVisible, setViewVisible] = useState(false);
//查看 参数传递
const [currentRecord, setCurrentRecord] = useState('');
2025-07-04 10:15:56 +08:00
// 新增与修改
const [exitModalVisible, setExitModalVisible] = useState(false);
const [exitId, setExitId] = useState('');
2025-07-02 16:18:03 +08:00
// 查询数据
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);
// eslint-disable-next-line
}, [tabKey]);
// 查询
const handleSearch = () => {
fetchData(1, pagination.pageSize);
};
// 重置
const handleReset = () => {
form.resetFields();
fetchData(1, pagination.pageSize);
};
// 切页
const handleTableChange = (pag: any) => {
fetchData(pag.current, pag.pageSize);
};
// 列
2025-07-03 10:24:33 +08:00
const columns: ColumnsType<Columns> = [
2025-06-24 10:52:30 +08:00
{
2025-07-02 16:18:03 +08:00
title: '序号',
dataIndex: 'index',
align: 'center',
width: 80,
render: (_: any, __: any, idx: number) => ((pagination.current - 1) * pagination.pageSize) + idx + 1,
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '供应商名称',
dataIndex: 'name',
align: 'center',
ellipsis: true,
2025-06-24 10:52:30 +08:00
},
2025-07-04 08:47:01 +08:00
// {
// title: '供应商类型',
// dataIndex: 'supplierType',
// align: 'center',
// },
2025-06-24 10:52:30 +08:00
{
2025-07-02 16:18:03 +08:00
title: '创建单位',
dataIndex: 'unit',
align: 'center',
ellipsis: true,
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '创建部门',
dataIndex: 'deptId',
align: 'center',
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '创建时间',
dataIndex: 'createTime',
align: 'center',
// sorter 由接口决定是否支持
2025-06-24 10:52:30 +08:00
},
{
2025-07-02 16:18:03 +08:00
title: '操作',
align: 'center',
render: (_: any, record: any) => (
<Space>
2025-07-03 10:24:33 +08:00
<a onClick={() => { setCurrentRecord(record.id); setViewVisible(true); }}></a>
2025-07-04 10:15:56 +08:00
{/* <a onClick={() => {
setExitId(record.id);
setExitModalVisible(true);
}}></a> */}
2025-07-02 16:18:03 +08:00
</Space>
),
2025-06-24 10:52:30 +08:00
},
2025-07-02 16:18:03 +08:00
];
2025-06-24 10:52:30 +08:00
2025-07-02 16:18:03 +08:00
return (
<div>
{/* 查询区 */}
<Form form={form} >
<Row gutter={16}>
<Col span={6}>
<Form.Item name="keyword" label="名称">
<Input placeholder="请输入供应商名称或个人姓名关键字" allowClear />
</Form.Item>
</Col>
<Col span={10}>
<Form.Item name="dateRange" label="创建时间">
<RangePicker style={{ width: '100%' }} />
</Form.Item>
</Col>
<Col span={6} >
<Button type="primary" icon={<SearchOutlined />} onClick={handleSearch} style={{ marginRight: '10px' }}></Button>
<Button icon={<ReloadOutlined />} onClick={handleReset}></Button>
</Col>
</Row>
</Form>
<Row align="middle" justify="space-between" >
<Col flex="auto">
<Tabs activeKey={tabKey} onChange={setTabKey}>
<TabPane tab="境内供应商" key="dvs" />
<TabPane tab="境外供应商" key="ovs" />
2025-07-09 14:01:45 +08:00
<TabPane tab="个人" key="pe" />
2025-07-02 16:18:03 +08:00
</Tabs>
</Col>
<Col>
2025-07-04 10:15:56 +08:00
<Button type="primary" icon={<PlusOutlined />} onClick={() => { setExitModalVisible(true) }} ></Button>
2025-07-02 16:18:03 +08:00
</Col>
</Row>
{/* 表格 */}
<Table
columns={columns}
dataSource={data}
rowKey="id"
loading={loading}
pagination={{
current: pagination.current,
pageSize: pagination.pageSize,
total: pagination.total,
showQuickJumper: true,
showSizeChanger: true,
onChange: (current, pageSize) => handleTableChange({ current, pageSize }),
}}
2025-07-03 10:24:33 +08:00
/>
{/* 查看组件 */}
<SupplierViewModal
visible={viewVisible}
record={currentRecord}
onCancel={() => setViewVisible(false)}
2025-07-02 16:18:03 +08:00
/>
2025-07-04 10:15:56 +08:00
<SupplierExitModal
visible={exitModalVisible}
exitId={exitId}
2025-07-09 14:01:45 +08:00
onOk={() => {
setExitModalVisible(false)
}}
2025-07-04 10:15:56 +08:00
/>
2025-07-02 16:18:03 +08:00
</div>
);
2025-06-24 10:52:30 +08:00
};
export default SupplierRegisterAgent;