refactor: edit layout visa

This commit is contained in:
Thanaphon Frappet 2024-11-12 09:03:46 +07:00
parent b4fc7c7202
commit 3527d29427

View file

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { QSelect } from 'quasar'; import { QSelect } from 'quasar';
import { onMounted, reactive, ref } from 'vue'; import { onMounted, reactive, ref, computed } from 'vue';
import useAddressStore, { import useAddressStore, {
District, District,
Province, Province,
@ -23,25 +23,25 @@ const addrOptions = reactive<{
districtOps: [], districtOps: [],
subDistrictOps: [], subDistrictOps: [],
}); });
const arrivalAt = defineModel<string>('arrivalAt');
const visaType = defineModel<string>('visaType'); const arrivalTMNo = defineModel<string>('arrivalTmNo');
const visaNumber = defineModel<string>('visaNumber'); const arrivalTM = defineModel<string>('arrivalTm');
const visaIssueDate = defineModel<Date | null | string>('visaIssueDate'); const mrz = defineModel<string>('mrz');
const visaExpiryDate = defineModel<Date | null | string>('visaExpiryDate');
const visaIssuingPlace = defineModel<string>('visaIssuingPlace');
const visaStayUntilDate = defineModel<Date | null | string>(
'visaStayUntilDate',
);
const entryCount = defineModel<number>('entryCount'); const entryCount = defineModel<number>('entryCount');
const issuePlace = defineModel<string>('issuePlace');
const issueCountry = defineModel<string>('issueCountry'); const issueCountry = defineModel<string>('issueCountry');
const issueDate = defineModel<Date | null | string>('visaIssueDate');
const tm6Number = defineModel<string>('tm6Number'); const type = defineModel<string>('visaType');
const entryDate = defineModel<Date | null | string>('entryDate'); const expireDate = defineModel<Date>('expireDate');
const remark = defineModel<string>('remark');
const workerType = defineModel<string>('workerType'); const workerType = defineModel<string>('workerType');
const dayNext = defineModel<Date>('dayNext'); const number = defineModel<string>('visaNumber');
const tmNo = defineModel<string>('tmNo');
const enteredCheckpoint = defineModel<string>('enteredCheckpoint'); const calculatedVisaDate = computed(() => {
if (!issueDate.value) return undefined;
return calculate90DayNext(issueDate.value);
});
defineProps<{ defineProps<{
title?: string; title?: string;
@ -51,18 +51,22 @@ defineProps<{
separator?: boolean; separator?: boolean;
typeCustomer?: string; typeCustomer?: string;
prefixId: string; prefixId: string;
hideTitle?: boolean;
ocr?: boolean; ocr?: boolean;
}>(); }>();
async function calculate90DayNext(currentDate: Date) { function calculate90DayNext(currentDate: Date | null | string) {
const futureDate = new Date(currentDate); if (currentDate === null) return null;
// Add 90 days to the current date const date =
futureDate.setDate(currentDate.getDate() + 90); typeof currentDate === 'string' ? new Date(currentDate) : currentDate;
return futureDate; date.setDate(date.getDate() + 90);
return date;
} }
async function fetchProvince() { async function fetchProvince() {
const result = await addressStore.fetchProvince(); const result = await addressStore.fetchProvince();
@ -118,192 +122,25 @@ watch(
</script> </script>
<template> <template>
<template v-if="!!ocr"> {{ type }}
<div class="row">
<div class="col-12 row q-col-gutter-sm">
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-value="value"
option-label="label"
class="col-6"
:dense="dense"
:readonly="readonly"
:options="visaTypeOptions"
:hide-dropdown-icon="readonly"
:for="`${prefixId}-select-visa-type`"
:label="$t('customerEmployee.form.visaType')"
@filter="visaTypeFilter"
:model-value="readonly ? visaType || '-' : visaType"
@update:model-value="
(v) => (typeof v === 'string' ? (visaType = v) : '')
"
@clear="visaType = ''"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<!-- :rules="[
(val: string) =>
!!val || $t('selectValidate') + $t('formDialogInputVisaType'),
]" -->
<q-input
:for="`${prefixId}-input-visa-no`"
:dense="dense"
outlined
:readonly="readonly"
hide-bottom-space
class="col-6"
:label="$t('customerEmployee.form.visaNo')"
:model-value="readonly ? visaNumber || '-' : visaNumber"
@update:model-value="
(v) => (typeof v === 'string' ? (visaNumber = v) : '')
"
/>
<!-- :rules="[
(val: string) =>
!!val || $t('inputValidate') + $t('formDialogInputVisaNo'),
]" -->
<DatePicker
class="col-6"
:id="`${prefixId}-date-picker-visa-issuance`"
:readonly="readonly"
:label="$t('customerEmployee.form.visaIssuance')"
v-model="visaIssueDate"
clearable
/>
<DatePicker
class="col-6"
:id="`${prefixId}-date-picker-visa-expire`"
:readonly="readonly"
:label="$t('customerEmployee.form.visaExpire')"
v-model="visaExpiryDate"
clearable
/>
<q-input <div class="row col-12">
:for="`${prefixId}-input-visa-place`" <div v-if="!hideTitle" class="col-12 q-pb-sm text-weight-bold text-body1">
:dense="dense" <q-icon
outlined flat
:readonly="readonly" size="xs"
hide-bottom-space class="q-pa-sm rounded q-mr-xs"
class="col-6" color="info"
:label="$t('customerEmployee.form.visaPlace')" name="mdi-passport"
:model-value="readonly ? visaIssuingPlace || '-' : visaIssuingPlace" style="background-color: var(--surface-3)"
@update:model-value="
(v) => (typeof v === 'string' ? (visaIssuingPlace = v) : '')
"
/>
<!-- :rules="[
(val: string) =>
!!val || $t('selectValidate') + $t('formDialogInputVisaPlace'),
]" -->
<DatePicker
class="col-6"
:id="`${prefixId}-date-picker-visa-until`"
:readonly="readonly"
:label="$t('customerEmployee.form.visaStayUntil')"
v-model="visaStayUntilDate"
clearable
/>
<q-input
:for="`${prefixId}-input-tm6`"
:dense="dense"
outlined
:readonly="readonly"
hide-bottom-space
class="col-6"
:label="$t('customerEmployee.form.visaTM6')"
:model-value="readonly ? tm6Number || '-' : tm6Number"
@update:model-value="
(v) => (typeof v === 'string' ? (tm6Number = v) : '')
"
@clear="tm6Number = ''"
/>
<!-- :rules="[
(val: string) =>
!!val || $t('inputValidate') + $t('formDialogInputVisaTM6'),
]" -->
<DatePicker
class="col-6"
:id="`${prefixId}-date-picker-visa-enter`"
:readonly="readonly"
:label="$t('customerEmployee.form.visaEnter')"
v-model="entryDate"
clearable
/>
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-value="value"
option-label="label"
class="col-6"
:dense="dense"
:readonly="readonly"
:options="visaTypeOptions"
:hide-dropdown-icon="readonly"
:for="`${prefixId}-select-issue-country`"
:label="$t('customerEmployee.form.issueCountry')"
@filter="visaTypeFilter"
:model-value="readonly ? issueCountry || '-' : issueCountry"
@update:model-value="
(v) => (typeof v === 'string' ? (issueCountry = v) : '')
"
@clear="visaType = ''"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-input
style="height: 60px"
:for="`${prefixId}-input-entry-count`"
:dense="dense"
outlined
:readonly="readonly"
hide-bottom-space
class="col-6"
:label="$t('customerEmployee.form.entryCount')"
v-model="entryCount"
type="number"
min="0"
/> />
{{ title }}
</div> </div>
</div>
</template>
<template v-if="!ocr">
<div class="column full-width" style="height: 150px; margin-bottom: 80px">
<div <div
class="col-3 row item-center justify-between text-weight-bold app-text-muted" class="col-12 row justify-between items-center q-pb-sm text-weight-bold"
> >
<div> <div class="app-text-muted">
<slot name="expiryDate" /> <slot name="expiryDate" />
</div> </div>
@ -311,8 +148,8 @@ watch(
<slot name="button"></slot> <slot name="button"></slot>
</div> </div>
</div> </div>
<div class="col row"> <div class="row">
<div class="col row justify-center" style="max-height: 50%"> <div v-if="!ocr" class="col row justify-center" style="max-height: 50%">
<div style="border: 1px dashed"> <div style="border: 1px dashed">
<q-avatar <q-avatar
square square
@ -324,7 +161,10 @@ watch(
/> />
</div> </div>
</div> </div>
<div class="col-10 row q-col-gutter-sm"> <div
class="row q-col-gutter-sm"
:class="{ 'col-10': !ocr, 'col-12': ocr }"
>
<q-select <q-select
outlined outlined
clearable clearable
@ -337,7 +177,7 @@ watch(
input-debounce="0" input-debounce="0"
option-value="value" option-value="value"
option-label="label" option-label="label"
class="col-4" :class="{ 'col-4': !ocr, 'col-6': ocr }"
:dense="dense" :dense="dense"
:readonly="readonly" :readonly="readonly"
:options="workerTypeOptions" :options="workerTypeOptions"
@ -366,11 +206,11 @@ watch(
outlined outlined
:readonly="readonly" :readonly="readonly"
hide-bottom-space hide-bottom-space
class="col-4" :class="{ 'col-4': !ocr, 'col-6': ocr }"
:label="$t('customerEmployee.form.visaNo')" :label="$t('customerEmployee.form.visaNo')"
:model-value="readonly ? visaNumber || '-' : visaNumber" :model-value="readonly ? number || '-' : number"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (visaNumber = v) : '') (v) => (typeof v === 'string' ? (number = v) : '')
" "
/> />
@ -380,16 +220,16 @@ watch(
outlined outlined
:readonly="readonly" :readonly="readonly"
hide-bottom-space hide-bottom-space
class="col-4" :class="{ 'col-4': !ocr, 'col-6': ocr }"
:label="$t('customerEmployee.form.visaPlace')" :label="$t('customerEmployee.form.visaPlace')"
:model-value="readonly ? visaIssuingPlace || '-' : visaIssuingPlace" :model-value="readonly ? issuePlace || '-' : issuePlace"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (visaIssuingPlace = v) : '') (v) => (typeof v === 'string' ? (issuePlace = v) : '')
" "
/> />
<div class="row q-col-gutter-sm">
<q-select <q-select
v-if="ocr"
outlined outlined
clearable clearable
use-input use-input
@ -401,7 +241,7 @@ watch(
input-debounce="0" input-debounce="0"
option-value="value" option-value="value"
option-label="label" option-label="label"
class="col-4" :class="{ 'col-4': !ocr, 'col-6': ocr }"
:dense="dense" :dense="dense"
:readonly="readonly" :readonly="readonly"
:options="visaTypeOptions" :options="visaTypeOptions"
@ -409,11 +249,46 @@ watch(
:for="`${prefixId}-select-visa-type`" :for="`${prefixId}-select-visa-type`"
:label="$t('customerEmployee.form.visaType')" :label="$t('customerEmployee.form.visaType')"
@filter="visaTypeFilter" @filter="visaTypeFilter"
:model-value="readonly ? visaType || '-' : visaType" :model-value="readonly ? type || '-' : type"
@update:model-value="(v) => (typeof v === 'string' ? (type = v) : '')"
@clear="type = ''"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<div class="row q-col-gutter-sm">
<q-select
v-if="!ocr"
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-value="value"
option-label="label"
:class="{ 'col-4': !ocr, 'col-6': ocr }"
:dense="dense"
:readonly="readonly"
:options="visaTypeOptions"
:hide-dropdown-icon="readonly"
:for="`${prefixId}-select-visa-type`"
:label="$t('customerEmployee.form.visaType')"
@filter="visaTypeFilter"
:model-value="readonly ? type || '-' : type"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (visaType = v) : '') (v) => (typeof v === 'string' ? (type = v) : '')
" "
@clear="visaType = ''" @clear="type = ''"
> >
<template v-slot:no-option> <template v-slot:no-option>
<q-item> <q-item>
@ -429,7 +304,7 @@ watch(
:id="`${prefixId}-date-picker-visa-issuance`" :id="`${prefixId}-date-picker-visa-issuance`"
:readonly="readonly" :readonly="readonly"
:label="$t('customerEmployee.form.visaIssuance')" :label="$t('customerEmployee.form.visaIssuance')"
v-model="visaIssueDate" v-model="issueDate"
clearable clearable
/> />
</div> </div>
@ -439,19 +314,20 @@ watch(
:id="`${prefixId}-date-picker-visa-expire`" :id="`${prefixId}-date-picker-visa-expire`"
:readonly="readonly" :readonly="readonly"
:label="$t('customerEmployee.form.visaExpire')" :label="$t('customerEmployee.form.visaExpire')"
v-model="visaExpiryDate" v-model="expireDate"
clearable clearable
/> />
</div> </div>
<div class="col">
<DatePicker <DatePicker
class="col-3"
:id="`${prefixId}-date-picker-visa-issuance`" :id="`${prefixId}-date-picker-visa-issuance`"
:readonly="readonly" :readonly="readonly"
:label="$t('customerEmployee.form.visa90Day')" :label="$t('customerEmployee.form.visa90Day')"
v-model="dayNext" :model-value="calculatedVisaDate"
clearable clearable
/> />
</div> </div>
</div>
<q-input <q-input
:for="`${prefixId}-input-visa-no`" :for="`${prefixId}-input-visa-no`"
@ -461,9 +337,9 @@ watch(
hide-bottom-space hide-bottom-space
class="col-4" class="col-4"
:label="$t('customerEmployee.form.arrivalCardNo')" :label="$t('customerEmployee.form.arrivalCardNo')"
:model-value="readonly ? tmNo || '-' : tmNo" :model-value="readonly ? arrivalTMNo || '-' : arrivalTMNo"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (tmNo = v) : '') (v) => (typeof v === 'string' ? (arrivalTMNo = v) : '')
" "
/> />
@ -472,7 +348,7 @@ watch(
:id="`${prefixId}-date-picker-visa-enter`" :id="`${prefixId}-date-picker-visa-enter`"
:readonly="readonly" :readonly="readonly"
:label="$t('customerEmployee.form.visaEnter')" :label="$t('customerEmployee.form.visaEnter')"
v-model="entryDate" v-model="arrivalTM"
clearable clearable
/> />
@ -484,11 +360,9 @@ watch(
hide-bottom-space hide-bottom-space
class="col-4" class="col-4"
:label="$t('customerEmployee.form.visaCheckpoint')" :label="$t('customerEmployee.form.visaCheckpoint')"
:model-value=" :model-value="readonly ? arrivalAt || '-' : arrivalAt"
readonly ? enteredCheckpoint || '-' : enteredCheckpoint
"
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (enteredCheckpoint = v) : '') (v) => (typeof v === 'string' ? (arrivalAt = v) : '')
" "
/> />
@ -516,7 +390,7 @@ watch(
@update:model-value=" @update:model-value="
(v) => (typeof v === 'string' ? (issueCountry = v) : '') (v) => (typeof v === 'string' ? (issueCountry = v) : '')
" "
@clear="visaType = ''" @clear="type = ''"
> >
<template v-slot:no-option> <template v-slot:no-option>
<q-item> <q-item>
@ -543,6 +417,5 @@ watch(
</div> </div>
</div> </div>
</template> </template>
</template>
<style scoped></style> <style scoped></style>