From ee4c202088c713e3fb4fcf9cf0cb2e3930ceccdf Mon Sep 17 00:00:00 2001
From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com>
Date: Thu, 8 Aug 2024 13:32:46 +0700
Subject: [PATCH] feat: customer branch management
---
src/pages/03_customer-management/MainPage.vue | 65 ++++++++++++++++++-
.../employer/EmployerFormBasicInfo.vue | 4 ++
.../employer/EmployerFormBranch.vue | 9 +--
.../employer/EmployerFormContact.vue | 2 +-
4 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue
index 98fbcf6e..3c9f81f5 100644
--- a/src/pages/03_customer-management/MainPage.vue
+++ b/src/pages/03_customer-management/MainPage.vue
@@ -52,7 +52,6 @@ import FormEmployeeOther from 'src/components/03_customer-management/FormEmploye
import useOptionStore from 'src/stores/options';
import { DialogContainer, DialogHeader } from 'src/components/dialog';
-
const { t, locale } = useI18n();
const $q = useQuasar();
const route = useRoute();
@@ -263,6 +262,26 @@ function deleteCustomerById(id: string) {
});
}
+async function deleteCustomerBranchById(id: string) {
+ return await new Promise((resolve) => {
+ dialog({
+ color: 'negative',
+ icon: 'mdi-alert',
+ title: t('deleteConfirmTitle'),
+ actionText: t('ok'),
+ persistent: true,
+ message: t('deleteConfirmMessage'),
+ action: async () => {
+ await customerStore.deleteBranchById(id);
+ flowStore.rotate();
+ resolve(true);
+ },
+ cancel: () => {
+ resolve(false);
+ },
+ });
+ });
+}
async function fetchListOfOptionBranch() {
if (registerAbleBranchOption.value) return;
@@ -1931,10 +1950,36 @@ watch(
/>
await fetchListCustomer()"
class="full-width"
v-if="customerFormData.customerBranch"
v-for="(_, idx) in customerFormData.customerBranch"
+ @submit.prevent="
+ async () => {
+ if (!customerFormData.customerBranch) return;
+ if (!customerFormState.editCustomerId) return;
+
+ if (!customerFormData.customerBranch[idx].id) {
+ await customerStore.createBranch({
+ ...customerFormData.customerBranch[idx],
+ customerId: customerFormState.editCustomerId,
+ id: undefined,
+ });
+ } else {
+ await customerStore.editBranchById(
+ customerFormData.customerBranch[idx].id,
+ {
+ ...customerFormData.customerBranch[idx],
+ id: undefined,
+ },
+ );
+ }
+
+ await customerFormStore.assignFormData(
+ customerFormState.editCustomerId,
+ );
+ customerFormStore.resetForm();
+ }
+ "
>
(customerFormState.branchIndex = idx)"
@cancel="() => customerFormUndo(false)"
- @delete="() => {}"
+ @delete="
+ async () => {
+ if (!!customerFormData.customerBranch?.[idx].id) {
+ const action = await deleteCustomerBranchById(
+ customerFormData.customerBranch[idx].id,
+ );
+ if (action) {
+ await customerFormStore.assignFormData(
+ customerFormState.editCustomerId,
+ );
+ }
+ customerFormStore.resetForm();
+ }
+ }
+ "
@save="() => {}"
/>
diff --git a/src/pages/03_customer-management/components/employer/EmployerFormBasicInfo.vue b/src/pages/03_customer-management/components/employer/EmployerFormBasicInfo.vue
index 6036db98..f0182ba5 100644
--- a/src/pages/03_customer-management/components/employer/EmployerFormBasicInfo.vue
+++ b/src/pages/03_customer-management/components/employer/EmployerFormBasicInfo.vue
@@ -80,6 +80,7 @@ watch(
/>
{{ $t('customer.form.group.basicInfo') }}
[number]>(
'customerBranch',
- {
- required: true,
- default: [],
- },
+ { required: true },
);
const tab = ref('main');
@@ -43,6 +40,7 @@ defineProps<{
{{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }}
();
-const mail = defineModel('mail');
+const mail = defineModel('email');
const telephone = defineModel('telephone');