feat: customer branch form

This commit is contained in:
Methapon2001 2024-08-07 17:56:59 +07:00
parent 779374b164
commit 09b4f2500a
6 changed files with 499 additions and 561 deletions

View file

@ -4,13 +4,27 @@ import { QSelect } from 'quasar';
import { selectFilterOptionRefMod } from 'stores/utils';
import { getRole } from 'src/services/keycloak';
import { onMounted } from 'vue';
import {
SaveButton,
EditButton,
CancelButton,
DeleteButton,
} from 'src/components/button';
defineProps<{
prefixId?: string;
outlined?: boolean;
readonly?: boolean;
create?: boolean;
actionDisabled?: boolean;
customerType?: 'CORP' | 'PERS';
}>();
defineEmits<{
(e: 'save'): void;
(e: 'edit'): void;
(e: 'delete'): void;
(e: 'cancel'): void;
}>();
const personName = defineModel<string>('personName', { required: true });
const customerName = defineModel<string>('customerName', { required: true });
@ -65,15 +79,32 @@ watch(
style="background-color: var(--surface-3)"
/>
<span>{{ $t('customer.form.group.basicInfo') }}</span>
<q-btn
<EditButton
v-if="readonly && !create"
type="button"
@click="$emit('edit')"
class="q-ml-auto"
:disabled="actionDisabled"
/>
<DeleteButton
v-if="readonly && !create"
@click="$emit('delete')"
type="button"
class="q-ml-sm"
:disabled="actionDisabled"
/>
<SaveButton
v-if="!readonly"
type="submit"
dense
unelevated
color="primary"
:label="$t('save')"
@click="$emit('save')"
class="q-px-md q-ml-auto rounded"
class="q-ml-auto"
:disabled="actionDisabled"
/>
<CancelButton
v-if="!readonly && !create"
type="button"
class="q-ml-sm"
:disabled="actionDisabled"
@click="$emit('cancel')"
/>
</div>
<q-select

View file

@ -1,314 +1,291 @@
<script setup lang="ts">
import { ref } from 'vue';
import FormAddress from 'src/components/02_personnel-management/FormAddress.vue';
import FormBusiness from './FormBusiness.vue';
import { CustomerCreate } from 'src/stores/customer/types';
import { dateFormat, parseAndFormatDate } from 'src/utils/datetime';
import { ref, watch } from 'vue';
import FormContact from './FormContact.vue';
import { EditButton } from 'src/components/button';
import DeleteButton from 'src/components/button/DeleteButton.vue';
import SaveButton from 'src/components/button/SaveButton.vue';
import CancelButton from 'src/components/button/CancelButton.vue';
const branch = defineModel<CustomerCreate['customerBranch']>('customerBranch', {
default: [],
});
const tab = ref<
const item = defineModel<NonNullable<CustomerCreate['customerBranch']>[number]>(
'customerBranch',
{
branch: NonNullable<CustomerCreate['customerBranch']>[number];
tab: string;
}[]
>([]);
watch(
branch,
() => {
tab.value =
branch.value?.map((a) => ({
branch: a,
tab:
tab.value.find((b) => (b.branch === a ? true : b.branch.id === a.id))
?.tab || 'main',
})) || [];
required: true,
default: [],
},
{ deep: true },
);
const tab = ref('main');
defineEmits<{
(e: 'addBranch'): void;
(e: 'saveBranch', i: number, v: (typeof tab.value)[number]['branch']): void;
(e: 'deleteBranch', i: number, v: (typeof tab.value)[number]['branch']): void;
(e: 'edit'): void;
(e: 'save'): void;
(e: 'cancel'): void;
(e: 'delete'): void;
}>();
defineProps<{
editable?: boolean;
readonly?: boolean;
prefixId?: string;
actionDisabled?: boolean;
customerType?: 'CORP' | 'PERS';
}>();
</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-briefcase"
style="background-color: var(--surface-3)"
/>
<span>{{ $t('customer.form.group.branch') }}</span>
<q-btn
type="button"
rounded
flat
<span
class="col-12 text-weight-bold row items-center q-mb-sm"
:style="{ opacity: actionDisabled ? '.5' : undefined }"
:id="`form-branch-customer-no-${item.branchNo}`"
>
{{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }}
<EditButton
v-if="readonly"
@click="$emit('edit')"
class="q-ml-auto"
type="button"
:disabled="actionDisabled"
/>
<DeleteButton
v-if="readonly"
@click="$emit('delete')"
class="q-ml-sm"
type="button"
:disabled="actionDisabled"
/>
<SaveButton
v-if="!readonly"
@click="$emit('save')"
class="q-ml-auto"
type="submit"
:disabled="actionDisabled"
/>
<CancelButton
v-if="!readonly"
@click="$emit('cancel')"
class="q-ml-sm"
type="button"
:disabled="actionDisabled"
/>
</span>
<div class="col-12" :style="{ opacity: actionDisabled ? '.5' : undefined }">
<div class="rounded bordered">
<q-tabs
v-model="tab"
dense
unelevated
color="primary"
@click="$emit('addBranch')"
v-if="editable"
icon="mdi-plus"
class="q-ml-md"
/>
</div>
<template v-for="(item, idx) in branch">
<span
class="col-12 text-weight-bold row items-center"
:id="`form-branch-customer-no-${item.branchNo}`"
align="left"
class="bordered-b"
active-color="primary"
no-caps
>
{{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }}
<q-btn
v-if="editable"
type="button"
dense
unelevated
text-color="red-9"
color="red-2"
:label="$t('delete')"
@click="$emit('deleteBranch', idx, item)"
class="q-px-md q-ml-auto rounded"
/>
<q-btn
v-if="editable"
type="submit"
dense
unelevated
color="primary"
:label="$t('save')"
@click="$emit('saveBranch', idx, item)"
class="q-px-md q-ml-sm rounded"
/>
</span>
<div class="col-12" v-if="tab[idx]">
<div class="rounded bordered">
<q-tabs
v-model="tab[idx].tab"
dense
align="left"
class="bordered-b"
active-color="primary"
no-caps
>
<q-tab name="main" label="Main"></q-tab>
<q-tab name="address" label="Address"></q-tab>
<q-tab name="business" label="Business"></q-tab>
</q-tabs>
<q-tab-panels v-model="tab[idx].tab">
<q-tab-panel name="main">
<div class="row q-col-gutter-md">
<q-tab name="main" label="Main"></q-tab>
<q-tab name="address" label="Address"></q-tab>
<q-tab name="business" label="Business"></q-tab>
<q-tab name="contact" label="Contact"></q-tab>
</q-tabs>
<q-tab-panels v-model="tab">
<q-tab-panel name="main">
<div class="row q-col-gutter-md">
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="readonly"
hide-bottom-space
:label="$t('customerBranch.form.no')"
v-model="item.branchNo"
:for="`${prefixId}-input-branch-branch-no`"
type="number"
class="col-12 col-md-2"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
readonly
hide-bottom-space
:label="$t('customerBranch.form.code')"
:model-value="item.code || '-'"
:for="`${prefixId}-input-branch-branch-code`"
class="col-12 col-md-4"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="readonly"
hide-bottom-space
:label="$t('customerBranch.form.taxNo')"
v-model="item.taxNo"
:for="`${prefixId}-input-branch-tax-no`"
type="number"
class="col-12 col-md-4"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="readonly"
hide-bottom-space
:label="$t('customerBranch.form.name')"
v-model="item.name"
:for="`${prefixId}-input-branch-tax-no`"
class="col-12 col-md-6"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="readonly"
hide-bottom-space
:label="$t('customerBranch.form.nameEN')"
v-model="item.nameEN"
:for="`${prefixId}-input-branch-tax-no`"
class="col-12 col-md-6"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
v-if="customerType === 'CORP'"
:readonly="readonly"
hide-bottom-space
:label="$t('customerBranch.form.registerName')"
v-model="item.registerName"
:for="`${prefixId}-input-branch-register-name`"
class="col-12 col-md-4"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="readonly"
hide-bottom-space
v-if="customerType === 'CORP'"
:label="$t('customerBranch.form.authorizedCapital')"
v-model="item.authorizedCapital"
:for="`${prefixId}-input-branch-authorized-capital`"
class="col-12 col-md-4"
/>
<VueDatePicker
:id="`${prefixId}-picker-date-register-date`"
:teleport="true"
utc
v-if="customerType === 'CORP'"
auto-apply
v-model="item.registerDate"
:dark="$q.dark.isActive"
:locale="$i18n.locale === 'th-th' ? 'th' : 'en'"
:enableTimePicker="false"
:disabled="readonly"
class="col-md-4 col-12"
>
<template #year="{ value }">
{{ $i18n.locale === 'th-th' ? value + 543 : value }}
</template>
<template #year-overlay-value="{ value }">
{{ $i18n.locale === 'th-th' ? value + 543 : value }}
</template>
<template #trigger>
<q-input
lazy-rules="ondemand"
:for="`${prefixId}-input-start-date`"
:id="`${prefixId}-input-start-date`"
:label="$t('customerBranch.form.registerDate')"
dense
outlined
:readonly="!editable"
hide-bottom-space
:label="$t('customerBranch.form.no')"
v-model="item.branchNo"
:for="`${prefixId}-input-branch-${idx}-branch-no`"
type="number"
class="col-12 col-md-2"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
readonly
:disable="editable"
hide-bottom-space
:label="$t('customerBranch.form.code')"
:model-value="item.code || '-'"
:for="`${prefixId}-input-branch-${idx}-branch-code`"
class="col-12 col-md-4"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="!editable"
hide-bottom-space
:label="$t('customerBranch.form.taxNo')"
v-model="item.taxNo"
:for="`${prefixId}-input-branch-${idx}-tax-no`"
type="number"
class="col-12 col-md-4"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="!editable"
hide-bottom-space
:label="$t('customerBranch.form.name')"
v-model="item.name"
:for="`${prefixId}-input-branch-${idx}-tax-no`"
class="col-12 col-md-6"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="!editable"
hide-bottom-space
:label="$t('customerBranch.form.nameEN')"
v-model="item.nameEN"
:for="`${prefixId}-input-branch-${idx}-tax-no`"
class="col-12 col-md-6"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
v-if="customerType === 'CORP'"
:readonly="!editable"
hide-bottom-space
:label="$t('customerBranch.form.registerName')"
v-model="item.registerName"
:for="`${prefixId}-input-branch-${idx}-register-name`"
class="col-12 col-md-4"
/>
<q-input
lazy-rules="ondemand"
dense
outlined
:readonly="!editable"
hide-bottom-space
v-if="customerType === 'CORP'"
:label="$t('customerBranch.form.authorizedCapital')"
v-model="item.authorizedCapital"
:for="`${prefixId}-input-branch-${idx}-authorized-capital`"
class="col-12 col-md-4"
/>
<VueDatePicker
:id="`${prefixId}-picker-date-register-date`"
:teleport="true"
utc
v-if="customerType === 'CORP'"
auto-apply
v-model="item.registerDate"
:dark="$q.dark.isActive"
:locale="$i18n.locale === 'th-th' ? 'th' : 'en'"
:enableTimePicker="false"
:disabled="!editable"
class="col-md-4 col-12"
>
<template #year="{ value }">
{{ $i18n.locale === 'th-th' ? value + 543 : value }}
</template>
<template #year-overlay-value="{ value }">
{{ $i18n.locale === 'th-th' ? value + 543 : value }}
</template>
<template #trigger>
<q-input
lazy-rules="ondemand"
:for="`${prefixId}-input-start-date`"
:id="`${prefixId}-input-start-date`"
:label="$t('customerBranch.form.registerDate')"
dense
outlined
:readonly="!editable"
placeholder="DD/MM/YYYY"
:mask="!editable ? '' : '##/##/####'"
:model-value="
item.registerDate
? !editable
? dateFormat(item.registerDate)
: dateFormat(item.registerDate, false, false, true)
: undefined
"
@update:model-value="
(v) => {
if (editable && v && v.toString().length === 10) {
const _date = parseAndFormatDate(v, $i18n.locale);
if (_date) {
item.registerDate?.setDate(_date.getDate());
item.registerDate?.setMonth(_date.getMonth());
item.registerDate?.setFullYear(
_date.getFullYear(),
);
} else {
item.registerDate = null;
}
}
:readonly="readonly"
placeholder="DD/MM/YYYY"
:mask="readonly ? '' : '##/##/####'"
:model-value="
item.registerDate
? readonly
? dateFormat(item.registerDate)
: dateFormat(item.registerDate, false, false, true)
: undefined
"
@update:model-value="
(v) => {
if (readonly && v && v.toString().length === 10) {
const _date = parseAndFormatDate(v, $i18n.locale);
if (_date) {
item.registerDate?.setDate(_date.getDate());
item.registerDate?.setMonth(_date.getMonth());
item.registerDate?.setFullYear(_date.getFullYear());
} else {
item.registerDate = null;
}
"
>
<template v-slot:prepend>
<q-icon
size="xs"
name="mdi-calendar-blank-outline"
class="cursor-pointer"
color="primary"
/>
</template>
<template v-slot:append>
<q-icon
v-if="!item.registerDate && editable"
name="mdi-close-circle"
class="cursor-pointer app-text-muted"
size="sm"
@click="item.registerDate = null"
/>
</template>
</q-input>
}
}
"
>
<template v-slot:prepend>
<q-icon
size="xs"
name="mdi-calendar-blank-outline"
class="cursor-pointer"
color="primary"
/>
</template>
</VueDatePicker>
</div>
</q-tab-panel>
<q-tab-panel name="address">
<FormAddress
:prefix-id="prefixId || 'employer'"
hide-title
dense
:readonly="!editable"
outlined
:title="$t('form.address')"
v-model:address="item.address"
v-model:addressEN="item.addressEN"
v-model:province-id="item.provinceId"
v-model:district-id="item.districtId"
v-model:sub-district-id="item.subDistrictId"
:addressTitle="$t('form.address')"
:addressTitleEN="$t('form.address', { suffix: '(EN)' })"
/>
</q-tab-panel>
<q-tab-panel name="business">
<FormBusiness
dense
outlined
:prefix-id="prefixId || 'employer'"
:readonly="!editable"
v-model:employment-office="item.employmentOffice"
v-model:bussiness-type="item.bussinessType"
v-model:bussiness-type-en="item.bussinessTypeEN"
v-model:job-position="item.jobPosition"
v-model:job-position-en="item.jobPositionEN"
v-model:job-description="item.jobDescription"
v-model:sale-employee="item.saleEmployee"
v-model:pay-date="item.payDate"
v-model:wage-rate="item.wageRate"
/>
</q-tab-panel>
</q-tab-panels>
</div>
</div>
</template>
<template v-slot:append>
<q-icon
v-if="!item.registerDate && readonly"
name="mdi-close-circle"
class="cursor-pointer app-text-muted"
size="sm"
@click="item.registerDate = null"
/>
</template>
</q-input>
</template>
</VueDatePicker>
</div>
</q-tab-panel>
<q-tab-panel name="address">
<FormAddress
:prefix-id="prefixId || 'employer'"
hide-title
dense
:readonly="readonly"
outlined
:title="$t('form.address')"
v-model:address="item.address"
v-model:addressEN="item.addressEN"
v-model:province-id="item.provinceId"
v-model:district-id="item.districtId"
v-model:sub-district-id="item.subDistrictId"
:addressTitle="$t('form.address')"
:addressTitleEN="$t('form.address', { suffix: '(EN)' })"
/>
</q-tab-panel>
<q-tab-panel name="business">
<FormBusiness
dense
outlined
:prefix-id="prefixId || 'employer'"
:readonly="readonly"
v-model:employment-office="item.employmentOffice"
v-model:bussiness-type="item.bussinessType"
v-model:bussiness-type-en="item.bussinessTypeEN"
v-model:job-position="item.jobPosition"
v-model:job-position-en="item.jobPositionEN"
v-model:job-description="item.jobDescription"
v-model:sale-employee="item.saleEmployee"
v-model:pay-date="item.payDate"
v-model:wage-rate="item.wageRate"
/>
</q-tab-panel>
<q-tab-panel name="contact">
<FormContact
:readonly="readonly"
v-model:email="item.email"
v-model:telephone="item.telephoneNo"
/>
</q-tab-panel>
</q-tab-panels>
</div>
</div>
</template>

View file

@ -0,0 +1,37 @@
<script lang="ts" setup>
defineProps<{
readonly?: boolean;
prefixId?: string;
}>();
const mail = defineModel<string>('mail');
const telephone = defineModel<string>('telephone');
</script>
<template>
<div class="col-md-9 col-12 row q-col-gutter-md">
<q-input
lazy-rules="ondemand"
:for="`${prefixId}-input-mail`"
:id="`${prefixId}-input-mail`"
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-md-6 col-12"
:label="$t('formDialogInputEmail')"
v-model="mail"
/>
<q-input
lazy-rules="ondemand"
:for="`${prefixId}-input-telephone`"
:id="`${prefixId}-input-telephone`"
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-md-6 col-12"
:label="$t('formDialogInputTelephone')"
v-model="telephone"
/>
</div>
</template>