客户,供应商

This commit is contained in:
liamzi
2024-12-18 17:46:56 +08:00
parent 9b4a7f5fd8
commit 7ba9f537fb
12 changed files with 787 additions and 65 deletions

View File

@@ -25,6 +25,7 @@ const QuotationForm = () => {
const [dataSource, setDataSource] = useState([{ id: Date.now() }]);
const [totalAmount, setTotalAmount] = useState(0);
const [currentCurrency, setCurrentCurrency] = useState('CNY');
const [customers, setCustomers] = useState([]);
const calculateTotal = (items = []) => {
const total = items.reduce((sum, item) => {
@@ -127,7 +128,7 @@ const QuotationForm = () => {
},
{
title: '操作',
width: '10%',
width: 100,
render: (_, record, index) => (
<Button
type="link"
@@ -157,13 +158,13 @@ const QuotationForm = () => {
if (error) throw error;
if (isEdit) {
// 设置表单初始值
form.setFieldsValue({
quataName: data.attributes.quataName,
companyName: data.attributes.companyName,
supplierName: data.attributes.supplierName,
customer: {
id: data.attributes.customerId,
name: data.attributes.customerName
},
description: data.attributes.description,
currency: data.attributes.currency,
items: data.attributes.items,
@@ -194,8 +195,8 @@ const QuotationForm = () => {
type: 'quota',
attributes: {
quataName: values.quataName,
companyName: values.companyName,
supplierName: values.supplierName,
customerId: values.customer.id,
customerName: values.customer.name,
description: values.description,
currency: values.currency,
items: values.items,
@@ -224,7 +225,25 @@ const QuotationForm = () => {
}
};
const fetchCustomers = async () => {
try {
const { data, error } = await supabase
.from('resources')
.select('*')
.eq('type', 'customer')
.eq('attributes->>status', 'active'); // 只获取启用状态的客户
if (error) throw error;
setCustomers(data || []);
} catch (error) {
console.error('获取客户列表失败:', error);
}
};
useEffect(() => {
fetchCustomers();
}, []);
return (
<div className="bg-gradient-to-b from-gray-50 to-white min-h-screen p-6">
@@ -259,7 +278,7 @@ const QuotationForm = () => {
</Space>
</div>
}
bodyStyle={{ backgroundColor: '#fff' }}
style={{ backgroundColor: '#fff' }}
>
<Form
form={form}
@@ -297,7 +316,7 @@ const QuotationForm = () => {
/>
</Form.Item>
<Form.Item
{/* <Form.Item
name="companyName"
label={<span className="text-gray-700 font-medium">公司名称</span>}
rules={[{ required: true, message: '请输入公司名称' }]}
@@ -306,17 +325,46 @@ const QuotationForm = () => {
placeholder="请输入公司名称"
className="rounded-md hover:border-blue-400 focus:border-blue-500"
/>
</Form.Item> */}
<Form.Item
name={['customer', 'name']}
label={<span className="text-gray-700 font-medium">客户名称</span>}
rules={[{ required: true, message: '请选择客户' }]}
>
<Select
placeholder="请选择客户"
className="rounded-md hover:border-blue-400 focus:border-blue-500"
showSearch
optionFilterProp="children"
filterOption={(input, option) =>
(option?.children ?? '').toLowerCase().includes(input.toLowerCase())
}
onChange={(value, option) => {
form.setFieldsValue({
customer: {
id: option.key,
name: value
}
});
}}
>
{customers.map(customer => (
<Select.Option
key={customer.id}
value={customer.attributes.name}
>
{customer.attributes.name}
</Select.Option>
))}
</Select>
</Form.Item>
<Form.Item
name="supplierName"
label={<span className="text-gray-700 font-medium">供应商名称</span>}
rules={[{ required: true, message: '请输入供应商名称' }]}
name={['customer', 'id']}
hidden
>
<Input
placeholder="请输入供应商名称"
className="rounded-md hover:border-blue-400 focus:border-blue-500"
/>
<Input />
</Form.Item>
</div>
</Card>