refactor: create / edit function

This commit is contained in:
Methapon2001 2024-08-05 15:29:11 +07:00
parent 6bb4256dec
commit 542e48cd1d
2 changed files with 35 additions and 16 deletions

View file

@ -384,6 +384,12 @@ async function editCustomerForm(id: string) {
customerFormState.value.dialogModal = true;
}
function createCustomerForm(customerType: 'CORP' | 'PERS') {
customerFormState.value.dialogModal = true;
customerFormState.value.dialogType = 'create';
customerFormData.value.customerType = customerType;
}
// TODO: When in employee form, if select address same as customer then auto fill
</script>
@ -394,11 +400,7 @@ async function editCustomerForm(id: string) {
v-if="currentTab === 'employer'"
id="add-customer-legal-entity"
style="color: white; background-color: hsla(var(--violet-11-hsl))"
@click="
(customerFormState.dialogModal = true),
(customerFormState.dialogType = 'create'),
(customerFormData.customerType = 'CORP')
"
@click="createCustomerForm('CORP')"
padding="xs"
icon="mdi-office-building"
:label="$t('add') + ' ' + $t('customerLegalEntity')"
@ -411,11 +413,7 @@ async function editCustomerForm(id: string) {
:label="$t('add') + ' ' + $t('customerNaturalPerson')"
external-label
label-position="left"
@click="
(customerFormState.dialogModal = true),
(customerFormState.dialogType = 'create'),
(customerFormData.customerType = 'CORP')
"
@click="createCustomerForm('PERS')"
style="color: white; background-color: hsla(var(--teal-10-hsl))"
padding="xs"
icon="mdi-account-plus"
@ -1639,9 +1637,11 @@ async function editCustomerForm(id: string) {
:title="$t('form.title.create', { name: 'Employer' })"
:show="
async () =>
await fetchListOfOptionBranch().then(() =>
customerFormStore.resetForm(),
)
await fetchListOfOptionBranch().then(() => {
customerFormStore.resetForm(
customerFormState.dialogType === 'create',
);
})
"
:submit="
() => {
@ -1701,6 +1701,7 @@ async function editCustomerForm(id: string) {
id="customer-form-content"
style="height: 100%; max-height: 100%; overflow-y: auto"
>
{{ customerFormData.customerType }}
<FormBasicInfo
id="form-basic-info-customer"
@save="customerFormState.saveMode = 'customer'"