From f136eda56e7b0938fe306d17e5cb84e31e105526 Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Thu, 10 Oct 2024 17:22:52 +0700 Subject: [PATCH] refactor: use dialogCheckData --- src/pages/05_quotation/QuotationForm.vue | 81 +++++++++++++----------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index bd895688..ce2ea25b 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -12,7 +12,7 @@ import { ref, watch, } from 'vue'; -import { dialog } from 'stores/utils'; +import { dialog, dialogCheckData } from 'stores/utils'; import { quotationProductTree } from './utils'; // NOTE: Import stores @@ -229,30 +229,6 @@ const productServiceList = ref< Required[] >([]); -async function dialogWarning( - callback: () => void, - check: () => void | boolean, -) { - const status = check(); - - if (status) { - dialog({ - color: 'warning', - icon: 'mdi-alert', - title: t('form.warning.title'), - actionText: t('general.ok'), - persistent: true, - message: t('form.warning.message'), - action: async () => { - callback(); - }, - cancel: () => {}, - }); - } else { - callback(); - } -} - async function assignToProductServiceList() { const ret = await productServiceStore.fetchListProductService({ page: 1, @@ -1152,26 +1128,57 @@ watch( async (group, allMeta) => { if (allMeta === undefined) return; - console.log(allMeta); - if (group === 'passport') { const fullName = allMeta['full_name'].split(' '); + let tempValue: { + oldData: { filName: string; value: string }[]; + newData: { filName: string; value: string }[]; + } = { oldData: [], newData: [] }; - await dialogWarning( - () => { + if (formDataEmployee.firstName !== '') { + tempValue.oldData.push({ + filName: $t('personnel.form.firstName'), + value: formDataEmployee.firstName, + }); + tempValue.newData.push({ + filName: $t('personnel.form.firstName'), + value: fullName[0], + }); + } + + if (formDataEmployee.lastName !== '') { + tempValue.oldData.push({ + filName: $t('personnel.form.lastName'), + value: formDataEmployee.lastName, + }); + tempValue.newData.push({ + filName: $t('personnel.form.lastName'), + value: fullName[1], + }); + } + + if (formDataEmployee.passportNo !== '') { + tempValue.oldData.push({ + filName: $t('customerEmployee.form.passportNo'), + value: formDataEmployee.passportNo || '', + }); + tempValue.newData.push({ + filName: $t('customerEmployee.form.passportNo'), + value: allMeta['doc_number'], + }); + } + + dialogCheckData({ + action: async () => { formDataEmployee.firstName = fullName[0]; formDataEmployee.lastName = fullName[1]; formDataEmployee.passportNo = allMeta['doc_number']; }, - () => { - let status = false; - if (formDataEmployee.firstName !== '') status = true; - if (formDataEmployee.lastName !== '') status = true; - if (formDataEmployee.passportNo !== '') status = true; - - return status; + checkData: () => { + return tempValue; }, - ); + cancel: () => {}, + }); } } "