合并代码
This commit is contained in:
@ -1,212 +1,170 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import ProTable from '@ant-design/pro-table';
|
||||
import type { ProColumns, ActionType } from '@ant-design/pro-table';
|
||||
import { Form, Input, Button, Row, Col, DatePicker, Tabs, Space } from 'antd';
|
||||
import React, { useRef, useEffect, useState } from 'react';
|
||||
import { Table, Form, Input, Button, Row, Col, DatePicker, Tabs, Space, message } from 'antd';
|
||||
import { SearchOutlined, ReloadOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { getPageAgent } from './services';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
// 示例数据
|
||||
const tableData = [
|
||||
{
|
||||
id: 1,
|
||||
name: '中山市合创展包装材料有限公司',
|
||||
type: '经销商',
|
||||
unit: '重工',
|
||||
dept: '采购部',
|
||||
createTime: '2025-03-03',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '深圳市欧阳华斯电源有限公司',
|
||||
type: '服务商',
|
||||
unit: '重工二级单位XXX',
|
||||
dept: '采购部',
|
||||
createTime: '2023-10-26',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '广东振兴塑胶机械有限公司',
|
||||
type: '代理商',
|
||||
unit: '重工',
|
||||
dept: '采购部',
|
||||
createTime: '2023-10-18',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: '上海硕建建筑技术工程有限公司',
|
||||
type: '服务商',
|
||||
unit: '重工二级单位XXX',
|
||||
dept: '采购部',
|
||||
createTime: '2023-09-12',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: '中山市合创展包装材料有限公司',
|
||||
type: '经销商',
|
||||
unit: '重工',
|
||||
dept: '采购部',
|
||||
createTime: '2023-08-30',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: '深圳市欧阳华斯电源有限公司',
|
||||
type: '服务商',
|
||||
unit: '重工二级单位XXX',
|
||||
dept: '采购部',
|
||||
createTime: '2023-07-31',
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: '广东振兴塑胶机械有限公司',
|
||||
type: '代理商',
|
||||
unit: '重工',
|
||||
dept: '采购部',
|
||||
createTime: '2023-07-25',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: '上海硕建建筑技术工程有限公司',
|
||||
type: '服务商',
|
||||
unit: '重工二级单位XXX',
|
||||
dept: '采购部',
|
||||
createTime: '2023-07-19',
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: '广东振兴塑胶机械有限公司',
|
||||
type: '代理商',
|
||||
unit: '重工',
|
||||
dept: '采购部',
|
||||
createTime: '2023-07-17',
|
||||
},
|
||||
{
|
||||
id: 10,
|
||||
name: '上海硕建建筑技术工程有限公司',
|
||||
type: '服务商',
|
||||
unit: '重工二级单位XXX',
|
||||
dept: '采购部',
|
||||
createTime: '2023-07-10',
|
||||
},
|
||||
];
|
||||
|
||||
const columns: ProColumns<any>[] = [
|
||||
{
|
||||
title: '序号',
|
||||
dataIndex: 'index',
|
||||
valueType: 'index',
|
||||
width: 48,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '供应商名称',
|
||||
dataIndex: 'name',
|
||||
align: 'center',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '供应商类型',
|
||||
dataIndex: 'type',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '创建单位',
|
||||
dataIndex: 'unit',
|
||||
align: 'center',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '创建部门',
|
||||
dataIndex: 'dept',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
align: 'center',
|
||||
sorter: (a, b) => new Date(a.createTime).getTime() - new Date(b.createTime).getTime(),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
dataIndex: 'option',
|
||||
align: 'center',
|
||||
valueType: 'option',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<a>查看</a>
|
||||
<a>编辑</a>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
const { TabPane } = Tabs;
|
||||
|
||||
const SupplierRegisterAgent: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [tabKey, setTabKey] = useState('inland');
|
||||
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');
|
||||
|
||||
// 查询区
|
||||
const searchFormRender = (
|
||||
<Form layout="vertical">
|
||||
<Row gutter={16}>
|
||||
<Col span={6}>
|
||||
<Form.Item name="keyword" label="名称">
|
||||
<Input placeholder="请输入供应商名称或个人姓名关键字" allowClear />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="dateRange" label="创建时间">
|
||||
<RangePicker style={{ width: '100%' }} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={6} style={{ display: 'flex', alignItems: 'flex-end', gap: 8 }}>
|
||||
<Button type="primary" icon={<SearchOutlined />}>查询</Button>
|
||||
<Button icon={<ReloadOutlined />}>重置</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form>
|
||||
);
|
||||
// 查询数据
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* 查询区 */}
|
||||
{searchFormRender}
|
||||
<Row align="middle" justify="space-between" style={{ marginBottom: 16, marginTop: 8 }}>
|
||||
<Col flex="auto">
|
||||
<Tabs
|
||||
activeKey={tabKey}
|
||||
onChange={setTabKey}
|
||||
style={{ marginBottom: 0 }} // 防止双距
|
||||
>
|
||||
<Tabs.TabPane tab="境内供应商" key="inland" />
|
||||
<Tabs.TabPane tab="境外供应商" key="overseas" />
|
||||
<Tabs.TabPane tab="个人" key="personal" />
|
||||
</Tabs>
|
||||
</Col>
|
||||
<Col>
|
||||
<Button type="primary" icon={<PlusOutlined />}>新增</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
{/* 表格 */}
|
||||
<ProTable
|
||||
columns={columns}
|
||||
actionRef={actionRef}
|
||||
dataSource={tableData}
|
||||
rowKey="id"
|
||||
search={false}
|
||||
pagination={{
|
||||
showQuickJumper: true,
|
||||
showSizeChanger: true,
|
||||
pageSize: 10,
|
||||
total: 188,
|
||||
current: 1,
|
||||
}}
|
||||
options={false}
|
||||
bordered
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
// 首次&依赖刷新
|
||||
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);
|
||||
};
|
||||
|
||||
// 列
|
||||
const columns = [
|
||||
{
|
||||
title: '序号',
|
||||
dataIndex: 'index',
|
||||
align: 'center',
|
||||
width: 80,
|
||||
render: (_: any, __: any, idx: number) => ((pagination.current - 1) * pagination.pageSize) + idx + 1,
|
||||
},
|
||||
{
|
||||
title: '供应商名称',
|
||||
dataIndex: 'name',
|
||||
align: 'center',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '供应商类型',
|
||||
dataIndex: 'enterpriseType',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '创建单位',
|
||||
dataIndex: 'unit',
|
||||
align: 'center',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '创建部门',
|
||||
dataIndex: 'deptId',
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
align: 'center',
|
||||
// sorter 由接口决定是否支持
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
align: 'center',
|
||||
render: (_: any, record: any) => (
|
||||
<Space>
|
||||
<a onClick={() => message.info(`查看:${record.name}`)}>查看</a>
|
||||
<a onClick={() => message.info(`编辑:${record.name}`)}>编辑</a>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
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" />
|
||||
</Tabs>
|
||||
</Col>
|
||||
<Col>
|
||||
<Button type="primary" icon={<PlusOutlined />}>新增</Button>
|
||||
</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 }),
|
||||
}}
|
||||
bordered
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SupplierRegisterAgent;
|
||||
|
Reference in New Issue
Block a user