From d5c8ce85b6a86065dd30f2835fcf718e9a144da2 Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Tue, 8 Oct 2024 16:42:17 +0700 Subject: [PATCH] refactor: assign worker to selectedWorker --- src/pages/05_quotation/MainPage.vue | 17 +++++++++++++--- src/pages/05_quotation/QuotationForm.vue | 26 ++++++++++++++++++++++-- src/pages/05_quotation/form.ts | 26 ++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/pages/05_quotation/MainPage.vue b/src/pages/05_quotation/MainPage.vue index cb98a314..654efc25 100644 --- a/src/pages/05_quotation/MainPage.vue +++ b/src/pages/05_quotation/MainPage.vue @@ -221,7 +221,10 @@ function triggerAddQuotationDialog() { // TODO: form and state controll } -function triggerQuotationDialog(statusDialog: 'info' | 'edit' | 'create') { +function triggerQuotationDialog( + statusDialog: 'info' | 'edit' | 'create', + quotationId?: string, +) { const url = new URL('/quotation/add-quotation', window.location.origin); url.searchParams.set('branchId', branchId.value); url.searchParams.set( @@ -232,6 +235,10 @@ function triggerQuotationDialog(statusDialog: 'info' | 'edit' | 'create') { url.searchParams.set('special', special.value.toString()); url.searchParams.set('statusDialog', statusDialog); + if (quotationId !== undefined) { + url.searchParams.set('quotationId', quotationId); + } + window.open(url.toString(), '_blank'); } @@ -613,8 +620,12 @@ watch(() => pageState.currentTab, fetchQuotationList); " :reporter="v.actorName" :total-price="v.totalPrice" - @view="quotationFormStore.assignFormData(v.id)" - @edit="quotationFormStore.assignFormData(v.id, 'edit')" + @view=" + () => { + triggerQuotationDialog('info', v.id); + } + " + @edit="triggerQuotationDialog('edit', v.id)" @link="console.log('link')" @upload="console.log('upload')" @delete="triggerDialogDeleteQuottaion(v.id)" diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index c345d528..c51235f3 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -85,6 +85,7 @@ const { currentFormState: quotationFormState, newWorkerList, fileItemNewWorker, + quotationFull, } = storeToRefs(quotationForm); const refSelectZoneEmployee = ref>(); @@ -94,6 +95,7 @@ const selectedCustomer = ref(''); const toggleWorker = ref(true); const rows = ref([]); const branchId = ref(''); +const currentQuotationId = ref(undefined); const date = ref(); const preSelectedWorker = ref([]); @@ -317,7 +319,14 @@ function triggerProductServiceDialog() { function toggleDeleteProduct(index: number) { deleteItem(productServiceList.value, index); - console.log(index); +} +async function assignWorkerToSelectedWorker() { + quotationFormData.value.worker.forEach((value, i) => { + const tempValue: Employee | undefined = workerList.value.find( + (v) => v.id === value.id, + ); + if (tempValue !== undefined) selectedWorker.value.push(tempValue); + }); } function convertToTable(nodes: Node[]) { @@ -432,6 +441,8 @@ onMounted(async () => { date.value = Date.now(); + currentQuotationId.value = urlParams.get('quotationId') || undefined; + quotationFormData.value.customerBranchId = urlParams.get('customerBranchId') || ''; @@ -456,7 +467,18 @@ onMounted(async () => { const retEmp = await customerStore.fetchBranchEmployee( quotationFormData.value.customerBranchId, ); - if (retEmp) workerList.value = workerList.value = retEmp.data.result; + if (retEmp) workerList.value = retEmp.data.result; + } + + if ( + currentQuotationId.value !== undefined && + quotationFormState.value.mode !== 'create' + ) { + await quotationForm.assignFormData( + currentQuotationId.value, + quotationFormState.value.mode, + ); + await assignWorkerToSelectedWorker(); } pageState.isLoaded = true; diff --git a/src/pages/05_quotation/form.ts b/src/pages/05_quotation/form.ts index 7b168a2e..4b7145ef 100644 --- a/src/pages/05_quotation/form.ts +++ b/src/pages/05_quotation/form.ts @@ -4,7 +4,11 @@ import { useI18n } from 'vue-i18n'; import { ref } from 'vue'; // NOTE: Import types -import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types'; +import { + QuotationPayload, + EmployeeWorker, + QuotationFull, +} from 'src/stores/quotations/types'; // NOTE: Import stores import { useQuotationStore } from 'stores/quotations'; @@ -34,6 +38,7 @@ export const useQuotationForm = defineStore('form-quotation', () => { const quotationStore = useQuotationStore(); const employeeStore = useEmployeeStore(); + const quotationFull = ref(undefined); const newWorkerList = ref< (EmployeeWorker & { attachment?: { @@ -91,10 +96,25 @@ export const useQuotationForm = defineStore('form-quotation', () => { if (!data) return; // NOTE: Error should be handled globally by axios instance + quotationFull.value = data; resetFormData = Object.assign(data, { productServiceList: data.productServiceList.map((v) => ({ ...v, - worker: undefined, + worker: v.worker.map((value, index) => ({ + // passportNo: obj.data.passportNo, wait api add + //documentExpireDate: obj.data.documentExpireDate, + id: value.id, + lastNameEN: value.lastNameEN, + lastName: value.lastName, + middleNameEN: value.middleNameEN, + middleName: value.middleName, + firstNameEN: value.firstNameEN, + firstName: value.firstName, + namePrefix: value.namePrefix, + nationality: value.nationality, + gender: value.gender, + dateOfBirth: value.dateOfBirth, + })), workerIndex: v.worker.map((a) => data.worker.findIndex((b) => b.employeeId === a.id), ), @@ -110,6 +130,7 @@ export const useQuotationForm = defineStore('form-quotation', () => { currentFormData.value = structuredClone(resetFormData); + console.log('ทำงาน'); currentFormState.value.mode = mode; } @@ -192,6 +213,7 @@ export const useQuotationForm = defineStore('form-quotation', () => { currentFormData, newWorkerList, fileItemNewWorker, + quotationFull, isFormDataDifferent, injectNewEmployee,