feat: add basic form customer
This commit is contained in:
parent
0a745885ee
commit
6bb4256dec
8 changed files with 408 additions and 80 deletions
BIN
public/images/customer-legal-avartar.png
Normal file
BIN
public/images/customer-legal-avartar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 218 KiB |
BIN
public/images/customer-legal-banner-bg.jpg
Normal file
BIN
public/images/customer-legal-banner-bg.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 277 KiB |
|
|
@ -25,6 +25,7 @@ defineProps<{
|
||||||
|
|
||||||
editData?: (...args: unknown[]) => void;
|
editData?: (...args: unknown[]) => void;
|
||||||
deleteData?: (...args: unknown[]) => void;
|
deleteData?: (...args: unknown[]) => void;
|
||||||
|
show?: (...args: unknown[]) => void;
|
||||||
submit?: (...args: unknown[]) => void;
|
submit?: (...args: unknown[]) => void;
|
||||||
close?: (...args: unknown[]) => void;
|
close?: (...args: unknown[]) => void;
|
||||||
undo?: (...args: unknown[]) => void;
|
undo?: (...args: unknown[]) => void;
|
||||||
|
|
@ -34,7 +35,7 @@ const modal = defineModel('modal', { default: false });
|
||||||
const currentTab = defineModel<string>('currentTab');
|
const currentTab = defineModel<string>('currentTab');
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<q-dialog v-model="modal" @hide="close">
|
<q-dialog v-model="modal" @hide="close" @before-show="show">
|
||||||
<div
|
<div
|
||||||
class="surface-1"
|
class="surface-1"
|
||||||
style="padding: 0; border-radius: var(--radius-2); height: 100%"
|
style="padding: 0; border-radius: var(--radius-2); height: 100%"
|
||||||
|
|
@ -199,7 +200,7 @@ const currentTab = defineModel<string>('currentTab');
|
||||||
<q-btn
|
<q-btn
|
||||||
id="cancelBtn"
|
id="cancelBtn"
|
||||||
unelevated
|
unelevated
|
||||||
class="col btn-cancel-dialog"
|
class="col btn-cancel-dialog rounded"
|
||||||
color="grey-4"
|
color="grey-4"
|
||||||
text-color="grey-10"
|
text-color="grey-10"
|
||||||
@click="close"
|
@click="close"
|
||||||
|
|
@ -212,7 +213,7 @@ const currentTab = defineModel<string>('currentTab');
|
||||||
id="submitBtn"
|
id="submitBtn"
|
||||||
type="submit"
|
type="submit"
|
||||||
color="primary"
|
color="primary"
|
||||||
class="q-px-md"
|
class="q-px-md rounded"
|
||||||
:label="$t('save')"
|
:label="$t('save')"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import otherDocument from './other-document';
|
||||||
import productService from './product-service';
|
import productService from './product-service';
|
||||||
import alertDialog from './alert-dialog';
|
import alertDialog from './alert-dialog';
|
||||||
import bank from './bank';
|
import bank from './bank';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
ok: 'Confirm',
|
ok: 'Confirm',
|
||||||
agree: 'Ok',
|
agree: 'Ok',
|
||||||
|
|
@ -87,4 +88,28 @@ export default {
|
||||||
...productService,
|
...productService,
|
||||||
...alertDialog,
|
...alertDialog,
|
||||||
...bank,
|
...bank,
|
||||||
|
|
||||||
|
form: {
|
||||||
|
title: {
|
||||||
|
create: 'Create {name}',
|
||||||
|
edit: 'Edit {name}',
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
required: 'This field is required.',
|
||||||
|
invalid: 'Invalid value.',
|
||||||
|
invalidCustomeMessage: 'Invalid value. {msg}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
form: {
|
||||||
|
group: {
|
||||||
|
basicInfo: 'Basic Information',
|
||||||
|
},
|
||||||
|
registeredBranch: 'Registered Branch',
|
||||||
|
customerName: 'Company Name',
|
||||||
|
customerNameEN: 'Company Name (EN)',
|
||||||
|
personName: 'Customer Name',
|
||||||
|
taxIdentificationNumber: 'Tax Identification Number',
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import { ref, watch, onMounted } from 'vue';
|
import { ref, watch, onMounted } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { getUserId, getRole } from 'src/services/keycloak';
|
import { getUserId, getRole } from 'src/services/keycloak';
|
||||||
|
|
||||||
import { calculateAge, dateFormat } from 'src/utils/datetime';
|
import { calculateAge, dateFormat } from 'src/utils/datetime';
|
||||||
|
|
@ -22,13 +23,15 @@ import TooltipComponent from 'components/TooltipComponent.vue';
|
||||||
import AddButton from 'components/AddButton.vue';
|
import AddButton from 'components/AddButton.vue';
|
||||||
import NoData from 'components/NoData.vue';
|
import NoData from 'components/NoData.vue';
|
||||||
import PaginationComponent from 'components/PaginationComponent.vue';
|
import PaginationComponent from 'components/PaginationComponent.vue';
|
||||||
|
import SideMenu from 'components/SideMenu.vue';
|
||||||
import DialogForm from 'components/DialogForm.vue';
|
import DialogForm from 'components/DialogForm.vue';
|
||||||
|
|
||||||
import CustomerInfoComponent from './components/CustomerBranch.vue';
|
import FormBasicInfo from './components/FormBasicInfo.vue';
|
||||||
import { columnsCustomer, columnsEmployee } from './constant';
|
import { columnsCustomer, columnsEmployee } from './constant';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
|
||||||
import { useCustomerForm } from './form';
|
import { useCustomerForm } from './form';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
import ProfileBanner from 'src/components/ProfileBanner.vue';
|
||||||
|
import ImageUploadDialog from 'src/components/ImageUploadDialog.vue';
|
||||||
|
|
||||||
const { t, locale } = useI18n();
|
const { t, locale } = useI18n();
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
|
@ -41,7 +44,8 @@ const userBranchStore = useMyBranchStore();
|
||||||
const employeeStore = useEmployeeStore();
|
const employeeStore = useEmployeeStore();
|
||||||
const customerFormStore = useCustomerForm();
|
const customerFormStore = useCustomerForm();
|
||||||
|
|
||||||
const { state: customerFormState } = storeToRefs(customerFormStore);
|
const { state: customerFormState, currentFormData: customerFormData } =
|
||||||
|
storeToRefs(customerFormStore);
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
utilsStore.currentTitle.title = 'customerManagement';
|
utilsStore.currentTitle.title = 'customerManagement';
|
||||||
|
|
@ -105,6 +109,7 @@ const maxPageCustomer = ref<number>(1);
|
||||||
const currentPageEmployee = ref<number>(1);
|
const currentPageEmployee = ref<number>(1);
|
||||||
const maxPageEmployee = ref<number>(1);
|
const maxPageEmployee = ref<number>(1);
|
||||||
const pageSize = ref<number>(10);
|
const pageSize = ref<number>(10);
|
||||||
|
const dialogCustomerImageUpload = ref<InstanceType<typeof ImageUploadDialog>>();
|
||||||
|
|
||||||
watch(() => route.name, init);
|
watch(() => route.name, init);
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -373,6 +378,12 @@ async function openHistory(id: string) {
|
||||||
employeeHistoryDialog.value = true;
|
employeeHistoryDialog.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function editCustomerForm(id: string) {
|
||||||
|
await customerFormStore.assignFormData(id);
|
||||||
|
customerFormState.value.dialogType = 'edit';
|
||||||
|
customerFormState.value.dialogModal = true;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: When in employee form, if select address same as customer then auto fill
|
// TODO: When in employee form, if select address same as customer then auto fill
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -383,7 +394,11 @@ async function openHistory(id: string) {
|
||||||
v-if="currentTab === 'employer'"
|
v-if="currentTab === 'employer'"
|
||||||
id="add-customer-legal-entity"
|
id="add-customer-legal-entity"
|
||||||
style="color: white; background-color: hsla(var(--violet-11-hsl))"
|
style="color: white; background-color: hsla(var(--violet-11-hsl))"
|
||||||
@click=""
|
@click="
|
||||||
|
(customerFormState.dialogModal = true),
|
||||||
|
(customerFormState.dialogType = 'create'),
|
||||||
|
(customerFormData.customerType = 'CORP')
|
||||||
|
"
|
||||||
padding="xs"
|
padding="xs"
|
||||||
icon="mdi-office-building"
|
icon="mdi-office-building"
|
||||||
:label="$t('add') + ' ' + $t('customerLegalEntity')"
|
:label="$t('add') + ' ' + $t('customerLegalEntity')"
|
||||||
|
|
@ -396,7 +411,11 @@ async function openHistory(id: string) {
|
||||||
:label="$t('add') + ' ' + $t('customerNaturalPerson')"
|
:label="$t('add') + ' ' + $t('customerNaturalPerson')"
|
||||||
external-label
|
external-label
|
||||||
label-position="left"
|
label-position="left"
|
||||||
@click=""
|
@click="
|
||||||
|
(customerFormState.dialogModal = true),
|
||||||
|
(customerFormState.dialogType = 'create'),
|
||||||
|
(customerFormData.customerType = 'CORP')
|
||||||
|
"
|
||||||
style="color: white; background-color: hsla(var(--teal-10-hsl))"
|
style="color: white; background-color: hsla(var(--teal-10-hsl))"
|
||||||
padding="xs"
|
padding="xs"
|
||||||
icon="mdi-account-plus"
|
icon="mdi-account-plus"
|
||||||
|
|
@ -870,13 +889,7 @@ async function openHistory(id: string) {
|
||||||
dense
|
dense
|
||||||
round
|
round
|
||||||
flat
|
flat
|
||||||
@click.stop="
|
@click.stop="editCustomerForm(props.row.id)"
|
||||||
async () => {
|
|
||||||
await fetchListOfOptionBranch();
|
|
||||||
const { branch, ...payload } = props.row;
|
|
||||||
currentCustomer = payload;
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<q-btn
|
<q-btn
|
||||||
|
|
@ -1623,9 +1636,111 @@ async function openHistory(id: string) {
|
||||||
|
|
||||||
<DialogForm
|
<DialogForm
|
||||||
v-model:modal="customerFormState.dialogModal"
|
v-model:modal="customerFormState.dialogModal"
|
||||||
:title="$t('')"
|
:title="$t('form.title.create', { name: 'Employer' })"
|
||||||
@submit="customerFormStore.submitForm"
|
:show="
|
||||||
></DialogForm>
|
async () =>
|
||||||
|
await fetchListOfOptionBranch().then(() =>
|
||||||
|
customerFormStore.resetForm(),
|
||||||
|
)
|
||||||
|
"
|
||||||
|
:submit="
|
||||||
|
() => {
|
||||||
|
customerFormStore.submitForm();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
:close="() => (customerFormState.dialogModal = false)"
|
||||||
|
no-footer
|
||||||
|
>
|
||||||
|
<div class="q-mx-lg q-mt-lg">
|
||||||
|
<ProfileBanner
|
||||||
|
active
|
||||||
|
v-model:cover-url="customerFormState.customerImageUrl"
|
||||||
|
:hide-fade="
|
||||||
|
customerFormState.customerImageUrl === '' ||
|
||||||
|
customerFormState.customerImageUrl === null
|
||||||
|
"
|
||||||
|
fallback-cover="/images/customer-legal-banner-bg.jpg"
|
||||||
|
:img="
|
||||||
|
customerFormState.customerImageUrl ||
|
||||||
|
'/images/customer-legal-avartar.png'
|
||||||
|
"
|
||||||
|
color="hsla(var(--pink-6-hsl)/1)"
|
||||||
|
bg-color="hsla(var(--pink-6-hsl)/0.15)"
|
||||||
|
@view="customerFormState.imageDialog = true"
|
||||||
|
@edit="dialogCustomerImageUpload?.browse()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="col surface-1 q-ma-lg rounded bordered scroll row relative-position"
|
||||||
|
id="customer-form"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="col"
|
||||||
|
style="height: 100%; max-height: 100; overflow-y: auto"
|
||||||
|
v-if="$q.screen.gt.sm"
|
||||||
|
>
|
||||||
|
<div class="q-py-md q-pl-md">
|
||||||
|
<SideMenu
|
||||||
|
:menu="[
|
||||||
|
{
|
||||||
|
name: $t('customer.form.group.basicInfo'),
|
||||||
|
anchor: 'form-basic-info-customer',
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
background="transparent"
|
||||||
|
:active="{
|
||||||
|
background: 'hsla(var(--blue-6-hsl) / .2)',
|
||||||
|
foreground: 'var(--blue-6)',
|
||||||
|
}"
|
||||||
|
scroll-element="#customer-form-content"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="col-12 col-md-10 q-pa-md"
|
||||||
|
id="customer-form-content"
|
||||||
|
style="height: 100%; max-height: 100%; overflow-y: auto"
|
||||||
|
>
|
||||||
|
<FormBasicInfo
|
||||||
|
id="form-basic-info-customer"
|
||||||
|
@save="customerFormState.saveMode = 'customer'"
|
||||||
|
:customer-type="customerFormData.customerType"
|
||||||
|
v-model:tax-no="customerFormData.taxNo"
|
||||||
|
v-model:customer-name="customerFormData.customerName"
|
||||||
|
v-model:customer-name-en="customerFormData.customerNameEN"
|
||||||
|
v-model:person-name="customerFormData.personName"
|
||||||
|
v-model:registered-branch-id="customerFormData.registeredBranchId"
|
||||||
|
v-model:branch-options="registerAbleBranchOption"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <q-btn -->
|
||||||
|
<!-- @click="customerFormState.saveMode = 'customer'" -->
|
||||||
|
<!-- type="submit" -->
|
||||||
|
<!-- label="Save" -->
|
||||||
|
<!-- /> -->
|
||||||
|
<!-- <q-btn -->
|
||||||
|
<!-- @click="customerFormState.saveMode = 'branch'" -->
|
||||||
|
<!-- type="submit" -->
|
||||||
|
<!-- label="Save" -->
|
||||||
|
<!-- /> -->
|
||||||
|
</DialogForm>
|
||||||
|
|
||||||
|
<ImageUploadDialog
|
||||||
|
ref="dialogCustomerImageUpload"
|
||||||
|
v-model:dialog-state="customerFormState.imageDialog"
|
||||||
|
v-model:file="customerFormData.image"
|
||||||
|
v-model:image-url="customerFormState.customerImageUrl"
|
||||||
|
:hidden-footer="
|
||||||
|
!customerFormData.image ||
|
||||||
|
!customerFormState.customerImageUrl ||
|
||||||
|
customerFormState.dialogType === 'edit'
|
||||||
|
"
|
||||||
|
fallback-url="/images/customer-legal-avartar.png"
|
||||||
|
clear-button
|
||||||
|
@save="() => {}"
|
||||||
|
></ImageUploadDialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
169
src/pages/03_customer-management/components/FormBasicInfo.vue
Normal file
169
src/pages/03_customer-management/components/FormBasicInfo.vue
Normal file
|
|
@ -0,0 +1,169 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, watch } from 'vue';
|
||||||
|
import { QSelect } from 'quasar';
|
||||||
|
import { selectFilterOptionRefMod } from 'stores/utils';
|
||||||
|
import { getRole } from 'src/services/keycloak';
|
||||||
|
import { onMounted } from 'vue';
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
prefixId?: string;
|
||||||
|
outlined?: boolean;
|
||||||
|
readonly?: boolean;
|
||||||
|
saveEnabled?: boolean;
|
||||||
|
customerType?: 'CORP' | 'PERS';
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const personName = defineModel<string>('personName', { required: true });
|
||||||
|
const customerName = defineModel<string>('customerName', { required: true });
|
||||||
|
const customerNameEN = defineModel<string>('customerNameEn', {
|
||||||
|
required: true,
|
||||||
|
});
|
||||||
|
const taxNo = defineModel<string | null>('taxNo');
|
||||||
|
const registeredBranchId = defineModel<string>('registeredBranchId', {
|
||||||
|
required: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const branchOptions = defineModel<{ id: string; name: string }[]>(
|
||||||
|
'branchOptions',
|
||||||
|
{ default: [] },
|
||||||
|
);
|
||||||
|
const filteredBranchOptions = ref<Record<string, unknown>[]>([]);
|
||||||
|
|
||||||
|
let branchFilter: (
|
||||||
|
value: string,
|
||||||
|
update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void,
|
||||||
|
) => void;
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
branchFilter = selectFilterOptionRefMod(
|
||||||
|
branchOptions,
|
||||||
|
filteredBranchOptions,
|
||||||
|
'name',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => branchOptions.value,
|
||||||
|
() => {
|
||||||
|
branchFilter = selectFilterOptionRefMod(
|
||||||
|
branchOptions,
|
||||||
|
filteredBranchOptions,
|
||||||
|
'name',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="row q-col-gutter-md">
|
||||||
|
<div class="col-12 text-weight-bold text-body1 row items-center">
|
||||||
|
<q-icon
|
||||||
|
flat
|
||||||
|
size="xs"
|
||||||
|
class="q-pa-sm rounded q-mr-xs"
|
||||||
|
color="info"
|
||||||
|
name="mdi-office-building-outline"
|
||||||
|
style="background-color: var(--surface-3)"
|
||||||
|
/>
|
||||||
|
<span>{{ $t('customer.form.group.basicInfo') }}</span>
|
||||||
|
<q-btn
|
||||||
|
type="submit"
|
||||||
|
dense
|
||||||
|
unelevated
|
||||||
|
color="primary"
|
||||||
|
:label="$t('save')"
|
||||||
|
@click="$emit('save')"
|
||||||
|
class="q-px-md q-ml-auto rounded"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<q-select
|
||||||
|
outlined
|
||||||
|
clearable
|
||||||
|
use-input
|
||||||
|
fill-input
|
||||||
|
emit-value
|
||||||
|
map-options
|
||||||
|
hide-selected
|
||||||
|
hide-bottom-space
|
||||||
|
dense
|
||||||
|
class="col-12 col-md-4"
|
||||||
|
option-value="id"
|
||||||
|
input-debounce="0"
|
||||||
|
option-label="name"
|
||||||
|
lazy-rules="ondemand"
|
||||||
|
v-model="registeredBranchId"
|
||||||
|
:readonly="readonly"
|
||||||
|
:options="filteredBranchOptions"
|
||||||
|
:hide-dropdown-icon="readonly"
|
||||||
|
:label="$t('registeredBranch')"
|
||||||
|
:for="`${prefixId}-input-source-nationality`"
|
||||||
|
:rules="[
|
||||||
|
(val) => {
|
||||||
|
const roles = getRole() || [];
|
||||||
|
return (
|
||||||
|
['admin', 'system', 'head_of_admin'].some((v) =>
|
||||||
|
roles.includes(v),
|
||||||
|
) ||
|
||||||
|
!!val ||
|
||||||
|
$t('form.error.required')
|
||||||
|
);
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
@filter="branchFilter"
|
||||||
|
>
|
||||||
|
<template v-slot:no-option>
|
||||||
|
<q-item>
|
||||||
|
<q-item-section class="text-grey">
|
||||||
|
{{ $t('noResults') }}
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
<q-input
|
||||||
|
lazy-rules="ondemand"
|
||||||
|
dense
|
||||||
|
outlined
|
||||||
|
hide-bottom-space
|
||||||
|
:label="$t('customer.form.customerName')"
|
||||||
|
v-model="customerName"
|
||||||
|
class="col-12 col-md-4"
|
||||||
|
:readonly="readonly"
|
||||||
|
:for="`${prefixId}-input-company-name`"
|
||||||
|
/>
|
||||||
|
<q-input
|
||||||
|
lazy-rules="ondemand"
|
||||||
|
dense
|
||||||
|
outlined
|
||||||
|
:readonly="readonly"
|
||||||
|
hide-bottom-space
|
||||||
|
:label="$t('customer.form.customerNameEN')"
|
||||||
|
v-model="customerNameEN"
|
||||||
|
:for="`${prefixId}-input-company-name-en`"
|
||||||
|
class="col-12 col-md-4"
|
||||||
|
/>
|
||||||
|
<q-input
|
||||||
|
lazy-rules="ondemand"
|
||||||
|
dense
|
||||||
|
outlined
|
||||||
|
:readonly="readonly"
|
||||||
|
hide-bottom-space
|
||||||
|
v-model="personName"
|
||||||
|
:label="$t('customer.form.personName')"
|
||||||
|
:for="`${prefixId}-input-person-name`"
|
||||||
|
:rules="[(v: string) => !!v || $t('form.error.required')]"
|
||||||
|
class="col-12 col-md-4"
|
||||||
|
/>
|
||||||
|
<q-input
|
||||||
|
lazy-rules="ondemand"
|
||||||
|
dense
|
||||||
|
outlined
|
||||||
|
v-if="customerType === 'PERS'"
|
||||||
|
:readonly="readonly"
|
||||||
|
hide-bottom-space
|
||||||
|
:label="$t('customer.form.taxIdentificationNumber')"
|
||||||
|
v-model="taxNo"
|
||||||
|
:for="`${prefixId}-input-tax-no`"
|
||||||
|
class="col-12 col-md-4"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -16,40 +16,10 @@ export const useCustomerForm = defineStore('form-customer', () => {
|
||||||
customerNameEN: '',
|
customerNameEN: '',
|
||||||
taxNo: '',
|
taxNo: '',
|
||||||
registeredBranchId: branchStore.currentMyBranch?.id || '',
|
registeredBranchId: branchStore.currentMyBranch?.id || '',
|
||||||
customerBranch: [
|
customerBranch: [],
|
||||||
// {
|
|
||||||
// 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,
|
|
||||||
// },
|
|
||||||
],
|
|
||||||
image: null,
|
image: null,
|
||||||
};
|
};
|
||||||
let resetCustomerData = structuredClone(defaultFormData);
|
let resetFormData = structuredClone(defaultFormData);
|
||||||
|
|
||||||
const currentFormData = ref<CustomerCreate>(structuredClone(defaultFormData));
|
const currentFormData = ref<CustomerCreate>(structuredClone(defaultFormData));
|
||||||
const state = ref<{
|
const state = ref<{
|
||||||
|
|
@ -57,31 +27,37 @@ export const useCustomerForm = defineStore('form-customer', () => {
|
||||||
dialogOpen: boolean;
|
dialogOpen: boolean;
|
||||||
dialogModal: boolean;
|
dialogModal: boolean;
|
||||||
branchIndex: number;
|
branchIndex: number;
|
||||||
customerType: 'CORP' | 'PERS';
|
|
||||||
saveMode: 'customer' | 'branch';
|
saveMode: 'customer' | 'branch';
|
||||||
|
customerImageUrl: string;
|
||||||
|
imageDialog: boolean;
|
||||||
|
imageEdit: boolean;
|
||||||
editCustomerId?: string;
|
editCustomerId?: string;
|
||||||
editCustomerBranchId?: string;
|
editCustomerBranchId?: string;
|
||||||
}>({
|
}>({
|
||||||
dialogType: 'info',
|
dialogType: 'info',
|
||||||
dialogOpen: false,
|
dialogOpen: false,
|
||||||
dialogModal: false,
|
dialogModal: false,
|
||||||
|
imageDialog: false,
|
||||||
branchIndex: 0,
|
branchIndex: 0,
|
||||||
customerType: 'CORP',
|
imageEdit: false,
|
||||||
saveMode: 'customer',
|
saveMode: 'customer',
|
||||||
|
customerImageUrl: '',
|
||||||
editCustomerId: '',
|
editCustomerId: '',
|
||||||
editCustomerBranchId: '',
|
editCustomerBranchId: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
function isFormDataDifferent() {
|
function isFormDataDifferent() {
|
||||||
return (
|
return (
|
||||||
JSON.stringify(resetCustomerData) !==
|
JSON.stringify(resetFormData) !== JSON.stringify(currentFormData.value)
|
||||||
JSON.stringify(currentFormData.value)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetFormData(cb?: (...args: any[]) => unknown) {
|
function resetForm() {
|
||||||
currentFormData.value = structuredClone(resetCustomerData);
|
if (!resetFormData.registeredBranchId) {
|
||||||
cb?.();
|
resetFormData.registeredBranchId = branchStore.currentMyBranch?.id || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFormData.value = structuredClone(resetFormData);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assignFormData(id: string) {
|
async function assignFormData(id: string) {
|
||||||
|
|
@ -89,15 +65,15 @@ export const useCustomerForm = defineStore('form-customer', () => {
|
||||||
|
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
resetCustomerData.registeredBranchId = data.registeredBranchId;
|
resetFormData.registeredBranchId = data.registeredBranchId;
|
||||||
resetCustomerData.status = data.status;
|
resetFormData.status = data.status;
|
||||||
resetCustomerData.customerType = data.customerType;
|
resetFormData.customerType = data.customerType;
|
||||||
resetCustomerData.customerName = data.customerName;
|
resetFormData.customerName = data.customerName;
|
||||||
resetCustomerData.customerNameEN = data.customerNameEN;
|
resetFormData.customerNameEN = data.customerNameEN;
|
||||||
resetCustomerData.personName = data.personName;
|
resetFormData.personName = data.personName;
|
||||||
resetCustomerData.taxNo = data.taxNo;
|
resetFormData.taxNo = data.taxNo;
|
||||||
resetCustomerData.image = null;
|
resetFormData.image = null;
|
||||||
resetCustomerData.customerBranch = data.branch.map((v) => ({
|
resetFormData.customerBranch = data.branch.map((v) => ({
|
||||||
id: v.id,
|
id: v.id,
|
||||||
code: v.code,
|
code: v.code,
|
||||||
branchNo: v.branchNo,
|
branchNo: v.branchNo,
|
||||||
|
|
@ -128,33 +104,75 @@ export const useCustomerForm = defineStore('form-customer', () => {
|
||||||
wageRate: v.wageRate,
|
wageRate: v.wageRate,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
currentFormData.value = structuredClone(resetCustomerData);
|
currentFormData.value = structuredClone(resetFormData);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCurrentCustomerBranch() {
|
||||||
|
currentFormData.value.customerBranch?.push({
|
||||||
|
id: '',
|
||||||
|
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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitForm() {
|
async function submitForm() {
|
||||||
console.log(state.value.saveMode);
|
if (state.value.saveMode === 'customer') await submitFormCustomer();
|
||||||
if (state.value.dialogType === 'edit' && !state.value.editCustomerId) {
|
|
||||||
throw new Error('Form mode is set to edit but no ID is provided.');
|
|
||||||
}
|
|
||||||
if (state.value.dialogType === 'edit') {
|
|
||||||
return submitEdit();
|
|
||||||
}
|
|
||||||
return submitCreate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitCreate() {
|
async function submitFormCustomer() {
|
||||||
// customerStore.create(currentFormData.value);
|
if (state.value.dialogType === 'info') return;
|
||||||
}
|
|
||||||
|
|
||||||
async function submitEdit() {}
|
if (state.value.dialogType === 'create') {
|
||||||
|
return await customerStore.create(currentFormData.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!state.value.editCustomerId) {
|
||||||
|
throw new Error(
|
||||||
|
'Form mode is set to edit but no ID is provided. Make sure to set customer ID.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await customerStore.editById(state.value.editCustomerId, {
|
||||||
|
...currentFormData.value,
|
||||||
|
image: currentFormData.value.image || undefined,
|
||||||
|
customerBranch: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
|
resetFormData,
|
||||||
currentFormData,
|
currentFormData,
|
||||||
isFormDataDifferent,
|
isFormDataDifferent,
|
||||||
resetFormData,
|
resetForm,
|
||||||
assignFormData,
|
assignFormData,
|
||||||
submitForm,
|
submitForm,
|
||||||
|
addCurrentCustomerBranch,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue