feat: customer branch management

This commit is contained in:
Methapon2001 2024-08-08 13:32:46 +07:00
parent 0f9c752e04
commit ee4c202088
4 changed files with 72 additions and 8 deletions

View file

@ -52,7 +52,6 @@ import FormEmployeeOther from 'src/components/03_customer-management/FormEmploye
import useOptionStore from 'src/stores/options'; import useOptionStore from 'src/stores/options';
import { DialogContainer, DialogHeader } from 'src/components/dialog'; import { DialogContainer, DialogHeader } from 'src/components/dialog';
const { t, locale } = useI18n(); const { t, locale } = useI18n();
const $q = useQuasar(); const $q = useQuasar();
const route = useRoute(); 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() { async function fetchListOfOptionBranch() {
if (registerAbleBranchOption.value) return; if (registerAbleBranchOption.value) return;
@ -1931,10 +1950,36 @@ watch(
/> />
</div> </div>
<q-form <q-form
@submit.prevent="async () => await fetchListCustomer()"
class="full-width" class="full-width"
v-if="customerFormData.customerBranch" v-if="customerFormData.customerBranch"
v-for="(_, idx) in 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();
}
"
> >
<EmployerFormBranch <EmployerFormBranch
v-if="!!customerFormState.editCustomerId" v-if="!!customerFormState.editCustomerId"
@ -1948,7 +1993,21 @@ watch(
:readonly="customerFormState.branchIndex !== idx" :readonly="customerFormState.branchIndex !== idx"
@edit="() => (customerFormState.branchIndex = idx)" @edit="() => (customerFormState.branchIndex = idx)"
@cancel="() => customerFormUndo(false)" @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="() => {}" @save="() => {}"
/> />
</q-form> </q-form>

View file

@ -80,6 +80,7 @@ watch(
/> />
<span>{{ $t('customer.form.group.basicInfo') }}</span> <span>{{ $t('customer.form.group.basicInfo') }}</span>
<EditButton <EditButton
icon-only
v-if="readonly && !create" v-if="readonly && !create"
type="button" type="button"
@click="$emit('edit')" @click="$emit('edit')"
@ -87,18 +88,21 @@ watch(
:disabled="actionDisabled" :disabled="actionDisabled"
/> />
<DeleteButton <DeleteButton
icon-only
v-if="readonly && !create" v-if="readonly && !create"
@click="$emit('delete')" @click="$emit('delete')"
type="button" type="button"
:disabled="actionDisabled" :disabled="actionDisabled"
/> />
<SaveButton <SaveButton
icon-only
v-if="!readonly" v-if="!readonly"
@click="$emit('save')" @click="$emit('save')"
class="q-ml-auto" class="q-ml-auto"
:disabled="actionDisabled" :disabled="actionDisabled"
/> />
<CancelButton <CancelButton
icon-only
v-if="!readonly && !create" v-if="!readonly && !create"
type="button" type="button"
:disabled="actionDisabled" :disabled="actionDisabled"

View file

@ -12,10 +12,7 @@ import CancelButton from 'src/components/button/CancelButton.vue';
const item = defineModel<NonNullable<CustomerCreate['customerBranch']>[number]>( const item = defineModel<NonNullable<CustomerCreate['customerBranch']>[number]>(
'customerBranch', 'customerBranch',
{ { required: true },
required: true,
default: [],
},
); );
const tab = ref('main'); const tab = ref('main');
@ -43,6 +40,7 @@ defineProps<{
{{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }} {{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }}
<EditButton <EditButton
v-if="readonly" v-if="readonly"
style="width: 5rem"
@click="$emit('edit')" @click="$emit('edit')"
class="q-ml-auto" class="q-ml-auto"
type="button" type="button"
@ -50,12 +48,14 @@ defineProps<{
/> />
<DeleteButton <DeleteButton
v-if="readonly" v-if="readonly"
style="width: 5rem"
@click="$emit('delete')" @click="$emit('delete')"
type="button" type="button"
:disabled="actionDisabled" :disabled="actionDisabled"
/> />
<SaveButton <SaveButton
v-if="!readonly" v-if="!readonly"
style="width: 5rem"
@click="$emit('save')" @click="$emit('save')"
class="q-ml-auto" class="q-ml-auto"
type="submit" type="submit"
@ -63,6 +63,7 @@ defineProps<{
/> />
<CancelButton <CancelButton
v-if="!readonly" v-if="!readonly"
style="width: 5rem"
@click="$emit('cancel')" @click="$emit('cancel')"
type="button" type="button"
:disabled="actionDisabled" :disabled="actionDisabled"

View file

@ -3,7 +3,7 @@ defineProps<{
readonly?: boolean; readonly?: boolean;
prefixId?: string; prefixId?: string;
}>(); }>();
const mail = defineModel<string>('mail'); const mail = defineModel<string>('email');
const telephone = defineModel<string>('telephone'); const telephone = defineModel<string>('telephone');
</script> </script>