diff --git a/src/pages/05_quotation/form.ts b/src/pages/05_quotation/form.ts index 55d87e0c..85db2d30 100644 --- a/src/pages/05_quotation/form.ts +++ b/src/pages/05_quotation/form.ts @@ -7,7 +7,7 @@ import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types'; // NOTE: Import stores import { useQuotationStore } from 'stores/quotations'; -const DEFAULT_DATA: QuotationPayload & { id?: string } = { +const DEFAULT_DATA: QuotationPayload = { productServiceList: [], urgent: false, customerBranchId: '', @@ -32,7 +32,9 @@ export const useQuotationForm = defineStore('form-quotation', () => { let resetFormData = structuredClone(DEFAULT_DATA); const currentTreeData = ref(); - const currentFormData = ref(structuredClone(resetFormData)); + const currentFormData = ref( + structuredClone(resetFormData), + ); const currentFormState = ref<{ mode: null | 'info' | 'create' | 'edit'; }>({ @@ -77,7 +79,17 @@ export const useQuotationForm = defineStore('form-quotation', () => { currentFormState.value.mode = mode; } - function submitQuotation() { + async function submitQuotation() { + if (currentFormState.value.mode === 'create') { + // await quotationStore.createQuotation(); + } + if (currentFormState.value.mode === 'edit' && currentFormData.value.id) { + // await quotationStore.editQuotation({ + // id: currentFormData.value.id, + // ...currentFormData.value, + // }); + } + currentFormState.value.mode = 'info'; } diff --git a/src/stores/quotations/index.ts b/src/stores/quotations/index.ts index 4f558b70..cd1941c6 100644 --- a/src/stores/quotations/index.ts +++ b/src/stores/quotations/index.ts @@ -41,7 +41,18 @@ export const useQuotationStore = defineStore('quotation-store', () => { } async function createQuotation(payload: QuotationPayload) { - const res = await api.post('/quotation', payload); + const res = await api.post('/quotation', { + ...payload, + productServiceList: payload.productServiceList.map((v) => ({ + vat: v.vat, + amount: v.amount, + pricePerUnit: v.pricePerUnit, + discount: v.discount, + productId: v.product.id, + workId: v.work?.id, + serviceId: v.service?.id, + })), + }); if (res.status < 400) { return res.data; } @@ -51,6 +62,15 @@ export const useQuotationStore = defineStore('quotation-store', () => { async function editQuotation(payload: QuotationPayload & { id: string }) { const res = await api.put(`/quotation/${payload.id}`, { ...payload, + productServiceList: payload.productServiceList.map((v) => ({ + vat: v.vat, + amount: v.amount, + pricePerUnit: v.pricePerUnit, + discount: v.discount, + productId: v.product.id, + workId: v.work?.id, + serviceId: v.service?.id, + })), id: undefined, }); if (res.status < 400) {