diff --git a/src/pages/05_quotation/MainPage.vue b/src/pages/05_quotation/MainPage.vue index 66629ec2..0ae2a3bc 100644 --- a/src/pages/05_quotation/MainPage.vue +++ b/src/pages/05_quotation/MainPage.vue @@ -187,21 +187,18 @@ function triggerQuotationDialog(opts: { branchId?: string; }) { const url = new URL('/quotation/add-quotation', window.location.origin); - url.searchParams.set( - 'branchId', - opts.branchId !== undefined ? opts.branchId : branchId.value, - ); - url.searchParams.set( - 'customerBranchId', - quotationFormData.value.customerBranchId, - ); - url.searchParams.set('agentPrice', agentPrice.value.toString()); - url.searchParams.set('special', special.value.toString()); - url.searchParams.set('statusDialog', opts.statusDialog); - if (opts.quotationId !== undefined) { - url.searchParams.set('quotationId', opts.quotationId); - } + localStorage.setItem( + 'new-quotation', + JSON.stringify({ + customerBranchId: quotationFormData.value.customerBranchId, + branchId: opts.branchId ?? branchId.value, + agentPrice: agentPrice.value, + special: special.value, + statusDialog: opts.statusDialog, + quotationId: opts.quotationId, + }), + ); window.open(url.toString(), '_blank'); } diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index 05776738..5b9bde0d 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -511,6 +511,8 @@ function changeMode(mode: string) { } } +const sessionData = ref>(); + onMounted(async () => { await configStore.getConfig(); // get language @@ -536,25 +538,57 @@ onMounted(async () => { changeMode('light'); } + sessionStorage.setItem( + 'new-quotation', + localStorage.getItem('new-quotation') || + sessionStorage.getItem('new-quotation') || + '', + ); + + localStorage.removeItem('new-quotation'); + const payload = sessionStorage.getItem('new-quotation'); + + if (!!payload) { + const parsed = JSON.parse(payload); + date.value = Date.now(); + quotationFormState.value.mode = parsed.statusDialog; + quotationFormData.value.registeredBranchId = parsed.branchId; + quotationFormData.value.customerBranchId = parsed.customerBranchId; + currentQuotationId.value = parsed.quotationId; + agentPrice.value = parsed.agentPrice; + if ( + currentQuotationId.value !== undefined && + quotationFormState.value.mode && + quotationFormState.value.mode !== 'create' + ) { + await quotationForm.assignFormData( + currentQuotationId.value, + quotationFormState.value.mode, + ); + await assignWorkerToSelectedWorker(); + } + sessionData.value = parsed; + } + // get query string - const urlParams = new URLSearchParams(window.location.search); - - const price = urlParams.get('agentPrice'); - agentPrice.value = price === 'true' ? true : false; - - date.value = Date.now(); - - currentQuotationId.value = urlParams.get('quotationId') || undefined; - - quotationFormData.value.registeredBranchId = urlParams.get('branchId') || ''; - - quotationFormData.value.customerBranchId = - urlParams.get('customerBranchId') || ''; - - quotationFormState.value.mode = urlParams.get('statusDialog') as - | 'info' - | 'edit' - | 'create'; + // const urlParams = new URLSearchParams(window.location.search); + // + // const price = urlParams.get('agentPrice'); + // agentPrice.value = price === 'true' ? true : false; + // + // date.value = Date.now(); + // + // currentQuotationId.value = urlParams.get('quotationId') || undefined; + // + // quotationFormData.value.registeredBranchId = urlParams.get('branchId') || ''; + // + // quotationFormData.value.customerBranchId = + // urlParams.get('customerBranchId') || ''; + // + // quotationFormState.value.mode = urlParams.get('statusDialog') as + // | 'info' + // | 'edit' + // | 'create'; // fetch option const resultOption = await fetch('/option/option.json'); @@ -562,16 +596,6 @@ onMounted(async () => { if (locale.value === 'eng') optionStore.globalOption = rawOption.eng; if (locale.value === 'tha') optionStore.globalOption = rawOption.tha; - if ( - currentQuotationId.value !== undefined && - quotationFormState.value.mode !== 'create' - ) { - await quotationForm.assignFormData( - currentQuotationId.value, - quotationFormState.value.mode, - ); - await assignWorkerToSelectedWorker(); - } await assignToProductServiceList(); pageState.isLoaded = true; @@ -580,17 +604,13 @@ onMounted(async () => { watch( () => quotationFormData.value.customerBranchId, async (v) => { - const url = new URL(window.location.href); - url.searchParams.set('customerBranchId', v); - history.pushState({}, '', url.toString()); - if (!v) return; + const retEmp = await customerStore.fetchBranchEmployee(v, { passport: true, }); - if (retEmp) { - workerList.value = retEmp.data.result; - } + + if (retEmp) workerList.value = retEmp.data.result; }, );