diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index 6d6c229d..6b10dff4 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -471,6 +471,7 @@ const statsCustomerType = ref({ CORP: 0, PERS: 0, }); +const hideBranch = ref(true); const currentCustomerId = ref(''); const dialogInputCustomerBranchForm = ref(false); const currentCustomer = ref(); @@ -580,6 +581,7 @@ const fieldCustomer = ref([ 'customerNaturalPerson', ]); +const countStartsOne = ref(1); const dialogCustomerType = ref(false); const dialogInputForm = ref(false); const dialogEmployee = ref(false); @@ -701,7 +703,10 @@ function onCloseBranch() { } function clearForm() { + inputFile.value = ''; profileFile.value = undefined; + profileUrl.value = null; + hideBranch.value = true; dialogInputForm.value = false; formData.value = { @@ -748,6 +753,7 @@ function clearForm() { } function clearFormEmployee() { + inputFile.value = ''; profileUrl.value = null; profileSubmit.value = false; dialogEmployee.value = false; @@ -912,17 +918,88 @@ async function onSubmit() { flowStore.rotate(); } -async function onSubmitCustomerBranch() { - dialogInputCustomerBranchForm.value = false; - // await createBranch(); +async function onSubmitBasicInformation() { + if (selectorLabel.value === 'EMPLOYER') { + dialog({ + color: 'info', + icon: 'mdi-alert', + title: t('saveConfirmTitle'), + actionText: t('ok'), + persistent: true, + message: t('saveConfirmMessage'), + action: async () => { + const res = await create({ + ...formData.value, + customerBranch: [], + customerType: customerType.value === 'CORP' ? 'CORP' : 'PERS', + image: profileSubmit.value ? profileFile.value ?? null : null, + }); - for (const item of formData.value.customerBranch || []) { - await createBranch({ - ...item, - customerId: currentCustomerId.value, + if (res) { + currentCustomerId.value = res.id; + hideBranch.value = false; + } + const resultList = await fetchList({ includeBranch: true }); + if (resultList) listCustomer.value = resultList.result; + }, + cancel: () => {}, }); } - clearForm(); + + // if (selectorLabel.value === 'EMPLOYEE') { + // const isOk = await checkEmployeeForm(); + // if (isOk) { + // await employeeStore.create({ + // ...formDataEmployee.value, + // image: profileSubmit.value ? profileFile.value ?? null : null, + // }); + // const resultList = await employeeStore.fetchList(); + // if (resultList) listEmployee.value = resultList.result; + + // const resultStatsEmployee = await employeeStore.getStatsEmployee(); + // if (resultStatsEmployee) statsEmployee.value = resultStatsEmployee; + + // clearFormEmployee(); + // } + // } + flowStore.rotate(); +} + +async function onSubmitCustomerBranch(opt: { isClearForm: boolean }) { + // await createBranch(); + + // for (const item of formData.value.customerBranch || []) { + // await createBranch({ + // ...item, + // customerId: currentCustomerId.value, + // }); + // } + + dialog({ + color: 'info', + icon: 'mdi-alert', + title: t('saveConfirmTitle'), + actionText: t('ok'), + persistent: true, + message: t('saveConfirmMessage'), + action: async () => { + if ( + formData.value.customerBranch !== undefined && + formData.value.customerBranch[indexTab.value] !== undefined + ) { + await createBranch({ + ...formData.value.customerBranch[indexTab.value], + customerId: currentCustomerId.value, + }); + } + }, + cancel: () => {}, + }); + + if (opt.isClearForm) { + dialogInputCustomerBranchForm.value = false; + clearForm(); + } const result = await fetchListById(currentCustomerId.value); if (result) { currentCustomerName.value = result.customerName; @@ -1178,6 +1255,7 @@ async function assignFormData( if (!data) return; indexTab.value = tabNo; + countStartsOne.value = 1; prevCustomer.value = { registeredBranchId: data.registeredBranchId, @@ -1225,8 +1303,39 @@ async function assignFormData( }); cloneData(); -} + if (formData.value.customerBranch?.length === 0) { + formData.value.customerBranch?.push({ + code: '', + branchNo: 1, + address: '', + addressEN: '', + provinceId: '', + districtId: '', + subDistrictId: '', + zipCode: '', + email: '', + telephoneNo: '', + name: '', + status: 'CREATED', + taxNo: '', + nameEN: '', + legalPersonNo: '', + registerName: '', + registerDate: new Date(), + authorizedCapital: '', + employmentOffice: '', + bussinessType: '', + bussinessTypeEN: '', + jobPosition: '', + jobPositionEN: '', + jobDescription: '', + saleEmployee: '', + payDate: new Date(), + wageRate: 0, + }); + } +} function cloneData() { formData.value = { ...prevCustomer.value, @@ -2972,7 +3081,12 @@ watch(isMainPage, () => { no-app-box width="60vw" height="50vh" - :close="() => (dialogCustomerType = false)" + :close=" + () => { + clearForm(); + dialogCustomerType = false; + } + " >
{ v-model:modal="dialogInputForm" :title="$t('customerEmployerAdd')" :customer-label="customerType" - :submit=" - () => { - onSubmit(); - } - " + :hiddenBtnSave="false" + :submit="() => {}" :close=" () => { - clearForm(); - dialogInputForm = false; + if (hideBranch && countStartsOne === 1) { + dialog({ + color: 'warning', + icon: 'mdi-alert', + title: t('warning'), + actionText: t('ok'), + persistent: true, + message: t('notRecorded'), + action: async () => { + countStartsOne++; + clearForm(); + dialogInputForm = false; + }, + cancel: () => {}, + }); + } else { + clearForm(); + dialogInputForm = false; + } } " > @@ -3031,131 +3159,148 @@ watch(isMainPage, () => { v-model:customer-name-en="formData.customerNameEN" v-model:person-name="formData.personName" v-model:tax-no="formData.taxNo" + @save=" + async () => { + await onSubmitBasicInformation(); + console.log('สร้าง'); + } + " /> @@ -3319,144 +3464,7 @@ watch(isMainPage, () => { - - - - @@ -3671,6 +3689,7 @@ watch(isMainPage, () => { :readonly="!infoDrawerEdit" v-model:customer-branch="formData.customerBranch" v-model:tab-index="indexTab" + @save="() => onSubmitCustomerBranch({ isClearForm: false })" >