Files
fe_supplier_frontend/src/pages/supplierEvaluateManage/supplierTemplateManage/supplierTemplateManage.tsx

304 lines
9.5 KiB
TypeScript
Raw Normal View History

2025-06-23 10:54:39 +08:00
import React, { useState, useEffect } from 'react';
2025-07-01 17:02:11 +08:00
import { history, useIntl } from 'umi';
2025-06-23 10:54:39 +08:00
import {
Button,
Table,
Space,
message,
Input,
Select,
Form,
Tooltip,
Tag,
} from 'antd';
2025-06-23 19:15:13 +08:00
import type { TablePaginationConfig } from 'antd';
2025-06-23 10:54:39 +08:00
import {
PlusOutlined,
DeleteOutlined,
SearchOutlined,
} from '@ant-design/icons';
2025-06-23 19:15:13 +08:00
import {
TemplateStatusText,
TemplateStatusColor,
TemplateStatus,
} from '@/dicts/supplierTemplateDict';
import {
getTemplateList,
} from '@/servers/api/supplierEvaluate';
2025-06-24 18:58:43 +08:00
import CategorySelector from '@/components/CategorySelector/CategorySelector';
2025-06-23 10:54:39 +08:00
const { Option } = Select;
2025-06-23 19:15:13 +08:00
2025-06-18 22:04:33 +08:00
const SupplierTemplateManage: React.FC = () => {
2025-07-01 17:02:11 +08:00
const intl = useIntl();
2025-06-23 10:54:39 +08:00
const [loading, setLoading] = useState<boolean>(false);
const [form] = Form.useForm();
const [templateData, setTemplateData] = useState<SupplierEvaluate.TemplateRecord[]>([]);
const [pagination, setPagination] = useState<TablePaginationConfig>({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
2025-07-01 17:02:11 +08:00
showTotal: (total) => intl.formatMessage(
{ id: 'supplierTemplateManage.pagination.total' },
{ total }
),
2025-06-23 10:54:39 +08:00
});
const [searchParams, setSearchParams] = useState<SupplierEvaluate.TemplateSearchParams>({});
2025-06-24 18:58:43 +08:00
// 部门下拉选项
2025-06-23 19:15:13 +08:00
const [companyOptions, setCompanyOptions] = useState<{ label: string, value: string }[]>([
2025-06-23 10:54:39 +08:00
{ label: '中山市合创展包装材料有限公司', value: '中山市合创展包装材料有限公司' },
{ label: '广州市科技发展有限公司', value: '广州市科技发展有限公司' },
{ label: '深圳市创新科技有限公司', value: '深圳市创新科技有限公司' },
{ label: '东莞市制造业有限公司', value: '东莞市制造业有限公司' },
2025-06-23 19:15:13 +08:00
]);
2025-06-23 10:54:39 +08:00
2025-06-23 19:15:13 +08:00
// 获取模板列表
2025-06-23 10:54:39 +08:00
const fetchTemplateList = async (
current = 1,
pageSize = 10,
params: SupplierEvaluate.TemplateSearchParams = searchParams,
) => {
// 更新搜索参数状态
if (params !== searchParams) {
setSearchParams(params);
}
setLoading(true);
try {
2025-06-23 19:15:13 +08:00
const requestParams: SupplierEvaluate.TemplateRequest = {
basePageRequest: {
pageNo: current,
pageSize: pageSize,
},
...params,
};
2025-06-23 10:54:39 +08:00
2025-06-23 19:15:13 +08:00
const res = await getTemplateList(requestParams);
2025-06-23 10:54:39 +08:00
2025-06-23 19:15:13 +08:00
if (res.success && res.data) {
// 处理返回的数据
const records = res.data.records
2025-06-23 10:54:39 +08:00
2025-06-23 19:15:13 +08:00
setTemplateData(records);
2025-06-23 10:54:39 +08:00
setPagination({
...pagination,
2025-06-23 19:15:13 +08:00
current: res.data.current,
pageSize: res.data.size,
total: res.data.total,
2025-06-23 10:54:39 +08:00
});
2025-06-23 19:15:13 +08:00
} else {
2025-07-01 17:02:11 +08:00
message.error(intl.formatMessage({ id: 'supplierTemplateManage.message.fetchFailed' }) || res.message);
2025-06-23 19:15:13 +08:00
}
2025-06-23 10:54:39 +08:00
} catch (error) {
console.error('获取模板列表失败:', error);
2025-07-01 17:02:11 +08:00
message.error(intl.formatMessage({ id: 'supplierTemplateManage.message.fetchFailed' }));
2025-06-23 19:15:13 +08:00
} finally {
2025-06-23 10:54:39 +08:00
setLoading(false);
}
};
// 首次加载获取数据
useEffect(() => {
fetchTemplateList(pagination.current, pagination.pageSize, {});
}, []);
// 处理查看
const handleView = (record: SupplierEvaluate.TemplateRecord) => {
2025-06-23 19:15:13 +08:00
// 跳转到详情页面
history.push({
2025-06-24 09:54:08 +08:00
pathname: 'supplierTemplateManageDetail',
2025-06-23 19:15:13 +08:00
state: {
id: record.id,
}
});
2025-06-23 10:54:39 +08:00
};
// 处理编辑
const handleEdit = (record: SupplierEvaluate.TemplateRecord) => {
2025-06-23 19:15:13 +08:00
// 跳转到新增页面并传递编辑数据
history.push({
2025-06-24 09:54:08 +08:00
pathname: 'supplierTemplateManageAdd',
2025-06-23 19:15:13 +08:00
state: {
isEdit: true,
editData: record
}
2025-06-23 10:54:39 +08:00
});
};
// 获取状态标签
2025-06-23 19:15:13 +08:00
const getStatusTag = (status: string | undefined) => {
2025-07-01 17:02:11 +08:00
if (!status) return <Tag>{intl.formatMessage({ id: 'supplierTemplateManage.status.unknown' })}</Tag>;
2025-06-23 10:54:39 +08:00
const color = TemplateStatusColor[status as keyof typeof TemplateStatusColor] || 'default';
2025-07-01 17:02:11 +08:00
const text = TemplateStatusText[status as keyof typeof TemplateStatusText] || intl.formatMessage({ id: 'supplierTemplateManage.status.unknown' });
2025-06-23 10:54:39 +08:00
return <Tag color={color}>{text}</Tag>;
};
// 处理表格分页变化
const handleTableChange = (newPagination: TablePaginationConfig) => {
fetchTemplateList(newPagination.current, newPagination.pageSize, searchParams);
};
const columns = [
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.index' }),
2025-06-23 10:54:39 +08:00
render: (_: any, __: SupplierEvaluate.TemplateRecord, index: number) =>
(pagination.current! - 1) * pagination.pageSize! + index + 1,
width: 80,
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.templateName' }),
2025-06-23 10:54:39 +08:00
dataIndex: 'templateName',
key: 'templateName',
width: 200,
ellipsis: {
showTitle: false,
},
render: (templateName: string) => (
<Tooltip placement="topLeft" title={templateName}>
{templateName}
</Tooltip>
),
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.category' }),
2025-06-23 19:15:13 +08:00
dataIndex: 'categoryName',
key: 'categoryName',
2025-06-23 10:54:39 +08:00
width: 120,
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.tenantName' }),
2025-06-23 19:15:13 +08:00
dataIndex: 'tenantName',
key: 'tenantName',
2025-06-23 10:54:39 +08:00
width: 180,
ellipsis: {
showTitle: false,
},
render: (text: string) => (
<Tooltip placement="topLeft" title={text}>
{text}
</Tooltip>
),
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.deptName' }),
2025-06-23 19:15:13 +08:00
dataIndex: 'deptName',
key: 'deptName',
2025-06-23 10:54:39 +08:00
width: 120,
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.createTime' }),
2025-06-23 10:54:39 +08:00
dataIndex: 'createTime',
key: 'createTime',
width: 150,
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.status' }),
2025-06-23 10:54:39 +08:00
dataIndex: 'status',
key: 'status',
width: 100,
render: (status: string) => getStatusTag(status),
},
{
2025-07-01 17:02:11 +08:00
title: intl.formatMessage({ id: 'supplierTemplateManage.column.action' }),
2025-06-23 10:54:39 +08:00
key: 'action',
width: 150,
align: 'center' as const,
render: (_: unknown, record: SupplierEvaluate.TemplateRecord) => (
<Space size="middle">
<Button type="link" onClick={() => handleEdit(record)}>
2025-07-01 17:02:11 +08:00
{intl.formatMessage({ id: 'supplierTemplateManage.button.edit' })}
2025-06-23 10:54:39 +08:00
</Button>
<Button type="link" onClick={() => handleView(record)}>
2025-07-01 17:02:11 +08:00
{intl.formatMessage({ id: 'supplierTemplateManage.button.view' })}
2025-06-23 10:54:39 +08:00
</Button>
</Space>
),
},
];
// 处理添加
const handleAdd = () => {
2025-06-23 19:15:13 +08:00
// 跳转到新增页面
2025-06-24 09:54:08 +08:00
history.push('supplierTemplateManageAdd');
2025-06-23 10:54:39 +08:00
};
// 处理搜索
const handleSearch = (values: any) => {
const { dateRange, ...rest } = values;
const params: SupplierEvaluate.TemplateSearchParams = { ...rest };
if (dateRange && dateRange.length === 2) {
params.dateRange = [dateRange[0].format('YYYY-MM-DD'), dateRange[1].format('YYYY-MM-DD')];
}
fetchTemplateList(1, pagination.pageSize, params);
};
2025-06-18 22:04:33 +08:00
return (
2025-06-23 10:54:39 +08:00
<div className={`common-container`}>
<div className="filter-action-row">
<Form
form={form}
name="search"
onFinish={handleSearch}
layout="inline"
className="filter-form"
>
2025-07-01 17:02:11 +08:00
<Form.Item name="templateName" label={intl.formatMessage({ id: 'supplierTemplateManage.column.templateName' })}>
<Input placeholder={intl.formatMessage({ id: 'supplierTemplateManage.placeholder.templateName' })} allowClear />
2025-06-23 10:54:39 +08:00
</Form.Item>
2025-07-01 17:02:11 +08:00
<Form.Item name="tenantName" label={intl.formatMessage({ id: 'supplierTemplateManage.column.tenantName' })}>
<Select placeholder={intl.formatMessage({ id: 'supplierTemplateManage.placeholder.tenantName' })} allowClear style={{ width: 200 }}>
2025-06-23 10:54:39 +08:00
{companyOptions.map(option => (
<Option key={option.value} value={option.value}>{option.label}</Option>
))}
</Select>
</Form.Item>
2025-07-01 17:02:11 +08:00
<Form.Item name="categoryId" label={intl.formatMessage({ id: 'supplierTemplateManage.column.category' })}>
2025-06-24 18:58:43 +08:00
<CategorySelector multiple={false} style={{ width: 200 }} />
2025-06-23 10:54:39 +08:00
</Form.Item>
<Form.Item className="filter-btns">
2025-06-23 19:15:13 +08:00
<Button type="primary" htmlType="submit" icon={<SearchOutlined />}>
2025-07-01 17:02:11 +08:00
{intl.formatMessage({ id: 'supplierTemplateManage.button.search' })}
2025-06-23 10:54:39 +08:00
</Button>
<Button
type="primary"
danger
icon={<DeleteOutlined />}
onClick={() => {
form.resetFields();
fetchTemplateList(1, pagination.pageSize, {});
}}
>
2025-07-01 17:02:11 +08:00
{intl.formatMessage({ id: 'supplierTemplateManage.button.reset' })}
2025-06-23 10:54:39 +08:00
</Button>
</Form.Item>
</Form>
<div className="right-buttons">
<Button type="primary" ghost icon={<PlusOutlined />} onClick={handleAdd}>
2025-07-01 17:02:11 +08:00
{intl.formatMessage({ id: 'supplierTemplateManage.button.add' })}
2025-06-23 10:54:39 +08:00
</Button>
</div>
</div>
<div className="content-area">
<Table
columns={columns}
2025-06-24 14:00:51 +08:00
rowKey="id"
2025-06-23 10:54:39 +08:00
dataSource={templateData}
pagination={pagination}
loading={loading}
onChange={handleTableChange}
scroll={{ x: 1200 }}
/>
</div>
</div>
2025-06-18 22:04:33 +08:00
);
};
export default SupplierTemplateManage;