From f2773a07881ac6fffab02ab4bc755363e82afe44 Mon Sep 17 00:00:00 2001 From: liamzi Date: Thu, 2 Jan 2025 18:02:10 +0800 Subject: [PATCH] =?UTF-8?q?ai=E4=BA=A7=E6=8A=A5=E4=BB=B7=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/company/quotation/detail/index.jsx | 83 +++++++++----------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/src/pages/company/quotation/detail/index.jsx b/src/pages/company/quotation/detail/index.jsx index 256c229..272c441 100644 --- a/src/pages/company/quotation/detail/index.jsx +++ b/src/pages/company/quotation/detail/index.jsx @@ -140,22 +140,8 @@ const QuotationForm = () => { ], }; - // 改添加小节的函数 - const handleAddSection = () => { - setTemplateModalVisible(true); - fetchAvailableSections(); - }; - // 修改添加项目的函数 - const handleAddItem = (add, sectionIndex) => { - add({ - key: uuidv4(), - name: "", - quantity: 1, - price: 0, - description: "", - }); - }; + const fetchQuotationDetail = async () => { try { @@ -208,22 +194,6 @@ const QuotationForm = () => { } }; - // 添加获取可用小节模板的方法 - const fetchAvailableSections = async () => { - try { - const { data: sections, error } = await supabase - .from("resources") - .select("*") - .eq("type", "sections") - .order("created_at", { ascending: false }); - - if (error) throw error; - setAvailableSections(sections || []); - } catch (error) { - message.error("获取小节模版失败"); - console.error(error); - } - }; @@ -375,20 +345,45 @@ const QuotationForm = () => { const [open, setOpen] = useState(false); const handleExport = (data) => { - const _data={ - ...data, - key: uuidv4(), + if(data?.activityName&&data?.currency){ + const quotationData = { + quataName: data.activityName, + description: data.description, + currency: data.currency || "TWD", + sections: data.sections.map((section) => ({ + key: uuidv4(), + sectionName: section.sectionName, + items: section.items.map((item) => ({ + key: uuidv4(), + name: item.name, + quantity: item.quantity, + price: item.price, + description: item.description, + unit: item.unit, + })), + })), + }; + setCurrentCurrency(data.currency || "TWD"); + form.setFieldsValue(quotationData); + setFormValues(quotationData); + setTaxRate(data.taxRate || 0); + message.success('已添加报价单'); + + }else{ + const _data={ + ...data, + key: uuidv4(), + } + const newSections = [...formValues.sections, _data]; + form.setFieldValue('sections', newSections); + const currentFormValues = form.getFieldsValue(); + setFormValues({ + ...currentFormValues, + sections: newSections + }); + message.success('已添加新的服务项目'); } - const newSections = [...formValues.sections, _data]; - console.log(newSections,'newSections'); - - form.setFieldValue('sections', newSections); - const currentFormValues = form.getFieldsValue(); - setFormValues({ - ...currentFormValues, - sections: newSections - }); - message.success('已添加新的服务项目'); + setOpen(false); };