jws-frontend/src/components/02_personnel-management/FormPerson.vue

322 lines
8.6 KiB
Vue
Raw Normal View History

2024-04-17 15:44:13 +07:00
<script setup lang="ts">
2024-06-24 07:21:36 +00:00
import useOptionStore from 'src/stores/options';
2024-07-30 04:04:17 +00:00
import { selectFilterOptionRefMod } from 'src/stores/utils';
2024-07-16 03:23:45 +00:00
import {
dateFormat,
calculateAge,
parseAndFormatDate,
2024-07-16 03:23:45 +00:00
disabledAfterToday,
} from 'src/utils/datetime';
2024-07-30 04:04:17 +00:00
import { ref } from 'vue';
2024-07-17 10:49:36 +00:00
import { useI18n } from 'vue-i18n';
2024-04-17 15:44:13 +07:00
2024-07-17 10:49:36 +00:00
const { locale } = useI18n();
2024-06-24 07:21:36 +00:00
const optionStore = useOptionStore();
2024-04-17 15:44:13 +07:00
const firstName = defineModel<string>('firstName');
const lastName = defineModel<string>('lastName');
const firstNameEN = defineModel<string>('firstNameEN');
const lastNameEN = defineModel<string>('lastNameEN');
const telephoneNo = defineModel<string>('telephoneNo');
const email = defineModel<string>('email');
const gender = defineModel<string>('gender');
2024-07-16 03:23:45 +00:00
const birthDate = defineModel<Date | string | null>('birthDate');
const nationality = defineModel<string>('nationality');
2024-04-17 15:44:13 +07:00
2024-07-30 04:04:17 +00:00
const genderOptions = ref<Record<string, unknown>[]>([]);
const genderFilter = selectFilterOptionRefMod(
ref(optionStore.globalOption.gender),
genderOptions,
'label',
);
const nationalityOptions = ref<Record<string, unknown>[]>([]);
const nationalityFilter = selectFilterOptionRefMod(
ref(optionStore.globalOption.nationality),
nationalityOptions,
'label',
2024-07-26 11:37:07 +07:00
);
2024-04-17 15:44:13 +07:00
defineProps<{
dense?: boolean;
outlined?: boolean;
readonly?: boolean;
separator?: boolean;
employee?: boolean;
2024-06-25 10:38:37 +00:00
title?: string;
2024-07-25 14:44:32 +07:00
prefixId: string;
2024-04-17 15:44:13 +07:00
}>();
</script>
<template>
2024-07-24 06:39:01 +00:00
<div class="col-md-3 col-12 app-text-muted">
2024-06-25 10:38:37 +00:00
{{ title || $t('formDialogTitlePersonnel') }}
</div>
2024-07-24 06:39:01 +00:00
<div class="col-md-9 col-12 row q-col-gutter-md">
2024-04-17 15:44:13 +07:00
<q-input
lazy-rules="ondemand"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-first-name`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
hide-bottom-space
2024-07-24 06:39:01 +00:00
class="col-md-3 col-6"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputFirstName')"
2024-04-17 15:44:13 +07:00
v-model="firstName"
2024-04-22 10:53:56 +07:00
:rules="[
(val: string) => !!val || $t('formDialogInputFirstNameValidate'),
]"
2024-04-17 15:44:13 +07:00
/>
<q-input
lazy-rules="ondemand"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-last-name`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
hide-bottom-space
2024-07-24 06:39:01 +00:00
class="col-md-3 col-6"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputLastName')"
2024-04-17 15:44:13 +07:00
v-model="lastName"
2024-04-22 10:53:56 +07:00
:rules="[(val: string) => !!val || $t('formDialogInputLastNameValidate')]"
2024-04-17 15:44:13 +07:00
/>
<q-input
lazy-rules="ondemand"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-first-name-en`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
hide-bottom-space
2024-07-24 06:39:01 +00:00
class="col-md-3 col-6"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputFirstNameEN')"
2024-04-17 15:44:13 +07:00
v-model="firstNameEN"
2024-04-22 10:53:56 +07:00
:rules="[
(val: string) => !!val || $t('formDialogInputFirstNameENValidate'),
]"
2024-04-17 15:44:13 +07:00
/>
<q-input
lazy-rules="ondemand"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-last-name-en`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
hide-bottom-space
2024-07-24 06:39:01 +00:00
class="col-md-3 col-6"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputLastNameEN')"
2024-04-17 15:44:13 +07:00
v-model="lastNameEN"
2024-04-22 10:53:56 +07:00
:rules="[
(val: string) => !!val || $t('formDialogInputLastNameENValidate'),
]"
2024-04-17 15:44:13 +07:00
/>
<q-input
lazy-rules="ondemand"
v-if="!employee"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-telephone`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
class="col-6"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputTelephone')"
2024-04-17 15:44:13 +07:00
v-model="telephoneNo"
mask="##########"
/>
<q-input
lazy-rules="ondemand"
v-if="!employee"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-email`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputEmail')"
2024-04-17 15:44:13 +07:00
class="col-6"
v-model="email"
/>
<q-select
v-if="!employee"
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
2024-04-17 15:44:13 +07:00
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
hide-bottom-space
v-model="gender"
input-debounce="0"
2024-04-17 15:44:13 +07:00
option-label="label"
option-value="value"
2024-07-30 04:04:17 +00:00
lazy-rules="ondemand"
class="col-md-3 col-6"
:dense="dense"
:readonly="readonly"
2024-07-26 11:37:07 +07:00
:options="genderOptions"
2024-07-30 04:04:17 +00:00
:hide-dropdown-icon="readonly"
2024-07-30 11:18:34 +07:00
:for="`${prefixId}-select-gender`"
2024-07-30 04:04:17 +00:00
:label="$t('formDialogInputGender')"
@filter="genderFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
</q-item>
</template>
</q-select>
2024-04-17 15:44:13 +07:00
<VueDatePicker
2024-07-25 14:44:32 +07:00
:id="`${prefixId}-input-birth-date`"
:for="`${prefixId}-input-birth-date`"
2024-04-17 15:44:13 +07:00
utc
autoApply
v-model="birthDate"
2024-07-16 03:23:45 +00:00
:disabled-dates="disabledAfterToday"
2024-07-01 04:03:39 +00:00
:teleport="true"
:dark="$q.dark.isActive"
2024-06-14 11:04:31 +00:00
:locale="$i18n.locale === 'th-th' ? 'th' : 'en'"
2024-04-17 15:44:13 +07:00
:enableTimePicker="false"
:disabled="readonly"
2024-07-24 06:39:01 +00:00
class="col-md-3 col-6"
2024-04-17 15:44:13 +07:00
>
<template #year="{ value }">
2024-06-14 11:04:31 +00:00
{{ $i18n.locale === 'th-th' ? value + 543 : value }}
</template>
<template #year-overlay-value="{ value }">
{{ $i18n.locale === 'th-th' ? value + 543 : value }}
2024-04-17 15:44:13 +07:00
</template>
<template #trigger>
<q-input
lazy-rules="ondemand"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-birth-date`"
2024-06-11 04:58:59 +00:00
hide-bottom-space
placeholder="DD/MM/YYYY"
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputBirthDate')"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
:readonly="readonly"
2024-06-11 04:58:59 +00:00
:rules="[
(val: string) =>
!!val || $t('selectValidate') + $t('formDialogInputBirthDate'),
]"
2024-07-17 10:49:36 +00:00
:mask="readonly ? '' : '##/##/####'"
:model-value="
birthDate && readonly
? dateFormat(birthDate)
: dateFormat(birthDate, false, false, true)
"
@update:model-value="
(v) => {
if (v && v.toString().length === 10) {
2024-07-16 08:23:54 +00:00
const today = new Date();
2024-07-17 10:49:36 +00:00
const date = parseAndFormatDate(v, locale);
2024-07-16 08:23:54 +00:00
birthDate = date && date > today ? today : date;
}
}
"
2024-04-17 15:44:13 +07:00
>
<!-- v-model="birthDate" -->
2024-04-17 15:44:13 +07:00
<template v-slot:prepend>
<q-icon
size="xs"
name="mdi-calendar-blank-outline"
class="cursor-pointer"
color="positive"
/>
</template>
</q-input>
</template>
</VueDatePicker>
<q-input
lazy-rules="ondemand"
2024-07-25 14:44:32 +07:00
:for="`${prefixId}-input-age`"
2024-07-30 11:18:34 +07:00
:id="`${prefixId}-input-age`"
2024-04-17 15:44:13 +07:00
:dense="dense"
outlined
2024-04-17 15:44:13 +07:00
readonly
2024-04-22 10:53:56 +07:00
:label="$t('formDialogInputAge')"
2024-07-24 06:39:01 +00:00
class="col-md-3 col-6"
:model-value="
birthDate?.toString() === 'Invalid Date' ||
birthDate?.toString() === undefined
? ''
: calculateAge(birthDate)
"
2024-04-17 15:44:13 +07:00
/>
<q-select
v-if="employee"
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
hide-bottom-space
input-debounce="0"
option-label="label"
option-value="value"
2024-07-30 04:04:17 +00:00
lazy-rules="ondemand"
class="col-md-3 col-6"
:dense="dense"
v-model="gender"
2024-07-30 04:04:17 +00:00
:readonly="readonly"
2024-07-26 11:37:07 +07:00
:options="genderOptions"
2024-07-30 04:04:17 +00:00
:hide-dropdown-icon="readonly"
2024-07-30 11:18:34 +07:00
:for="`${prefixId}-select-gender`"
2024-07-30 04:04:17 +00:00
:label="$t('formDialogInputGender')"
2024-06-11 04:58:59 +00:00
:rules="[
(val: string) =>
!!val || $t('selectValidate') + $t('formDialogInputGender'),
]"
2024-07-30 04:04:17 +00:00
@filter="genderFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-select
v-if="employee"
outlined
2024-07-30 04:04:17 +00:00
clearable
use-input
fill-input
emit-value
map-options
2024-07-30 04:04:17 +00:00
hide-selected
hide-bottom-space
input-debounce="0"
option-label="label"
option-value="label"
v-model="nationality"
2024-07-30 04:04:17 +00:00
lazy-rules="ondemand"
class="col-md-3 col-6"
:dense="dense"
:readonly="readonly"
2024-07-26 11:37:07 +07:00
:options="nationalityOptions"
2024-07-30 04:04:17 +00:00
:hide-dropdown-icon="readonly"
2024-07-30 14:17:47 +07:00
:for="`${prefixId}-select-nationality`"
2024-07-30 04:04:17 +00:00
:label="$t('formDialogInputNationality')"
2024-06-11 04:58:59 +00:00
:rules="[
(val: string) =>
!!val || $t('selectValidate') + $t('formDialogInputNationality'),
]"
2024-07-30 04:04:17 +00:00
@filter="nationalityFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('noResults') }}
</q-item-section>
</q-item>
</template>
</q-select>
2024-04-17 15:44:13 +07:00
</div>
<q-separator
v-if="separator"
class="col-12 q-mb-md"
style="padding-block: 0.5px; margin-top: 32px"
/>
</template>