管理后台初始化,登录,团队管理,报价单管理 完成
This commit is contained in:
208
src/pages/company/quotation/index.jsx
Normal file
208
src/pages/company/quotation/index.jsx
Normal file
@@ -0,0 +1,208 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Card, Table, Button, Modal, Form, Input, message, Popconfirm } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { useResources } from '@/hooks/resource/useResource';
|
||||
|
||||
const QuotationPage = () => {
|
||||
const [form] = Form.useForm();
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [editingId, setEditingId] = useState(null);
|
||||
const [pagination, setPagination] = useState({ current: 1, pageSize: 10 });
|
||||
const [sorter, setSorter] = useState({ field: 'created_at', order: 'descend' });
|
||||
|
||||
const {
|
||||
resources: quotations,
|
||||
loading,
|
||||
total,
|
||||
fetchResources: fetchQuotations,
|
||||
createResource: createQuotation,
|
||||
updateResource: updateQuotation,
|
||||
deleteResource: deleteQuotation
|
||||
} = useResources(pagination, sorter);
|
||||
|
||||
useEffect(() => {
|
||||
fetchQuotations();
|
||||
}, []);
|
||||
|
||||
const handleTableChange = (pagination, filters, sorter) => {
|
||||
setPagination(pagination);
|
||||
setSorter(sorter);
|
||||
fetchQuotations({
|
||||
current: pagination.current,
|
||||
pageSize: pagination.pageSize,
|
||||
field: sorter.field,
|
||||
order: sorter.order,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (values) => {
|
||||
try {
|
||||
const quotationData = {
|
||||
external_id: values.id,
|
||||
attributes: {
|
||||
customerName: values.customerName,
|
||||
status: values.status || '新建',
|
||||
},
|
||||
type: 'quota'
|
||||
};
|
||||
|
||||
if (editingId) {
|
||||
await updateQuotation(editingId, quotationData);
|
||||
} else {
|
||||
await createQuotation(quotationData);
|
||||
}
|
||||
setVisible(false);
|
||||
form.resetFields();
|
||||
fetchQuotations();
|
||||
} catch (error) {
|
||||
console.error('提交失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id) => {
|
||||
try {
|
||||
await deleteQuotation(id);
|
||||
fetchQuotations();
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '报价单号',
|
||||
dataIndex: ['external_id'],
|
||||
key: 'external_id',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '客户名称',
|
||||
dataIndex: ['attributes', 'customerName'],
|
||||
key: 'customerName',
|
||||
},
|
||||
{
|
||||
title: '创建日期',
|
||||
dataIndex: 'created_at',
|
||||
key: 'created_at',
|
||||
sorter: true,
|
||||
render: (text) => new Date(text).toLocaleString(),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: ['attributes', 'status'],
|
||||
key: 'status',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
<span>
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => {
|
||||
setEditingId(record.id);
|
||||
form.setFieldsValue({
|
||||
id: record.external_id,
|
||||
customerName: record.attributes?.customerName,
|
||||
status: record.attributes?.status,
|
||||
});
|
||||
setVisible(true);
|
||||
}}
|
||||
>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个报价单吗?"
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button type="link" danger>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Card
|
||||
title="报价单管理"
|
||||
extra={
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => {
|
||||
setEditingId(null);
|
||||
form.resetFields();
|
||||
setVisible(true);
|
||||
}}
|
||||
>
|
||||
新增报价单
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={quotations}
|
||||
rowKey="id"
|
||||
loading={loading}
|
||||
onChange={handleTableChange}
|
||||
pagination={{
|
||||
...pagination,
|
||||
total,
|
||||
}}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
title={editingId ? '编辑报价单' : '新增报价单'}
|
||||
open={visible}
|
||||
onCancel={() => {
|
||||
setVisible(false);
|
||||
setEditingId(null);
|
||||
form.resetFields();
|
||||
}}
|
||||
footer={null}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleSubmit}
|
||||
>
|
||||
<Form.Item
|
||||
name="id"
|
||||
label="报价单号"
|
||||
rules={[{ required: true, message: '请输入报价单号' }]}
|
||||
>
|
||||
<Input placeholder="请输入报价单号" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="customerName"
|
||||
label="客户名称"
|
||||
rules={[{ required: true, message: '请输入客户名称' }]}
|
||||
>
|
||||
<Input placeholder="请输入客户名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="status"
|
||||
label="状态"
|
||||
initialValue="新建"
|
||||
>
|
||||
<Input placeholder="请输入状态" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit" block>
|
||||
提交
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default QuotationPage;
|
||||
Reference in New Issue
Block a user