fix: employee history date picker

This commit is contained in:
puriphatt 2024-07-01 03:51:05 +00:00
parent dcbc1b7080
commit 571942d48f
2 changed files with 55 additions and 12 deletions

View file

@ -55,6 +55,7 @@ const columns: QTableColumn[] = [
const currentDate = ref(); const currentDate = ref();
const currentData = ref(); const currentData = ref();
const currentIndex = ref(0); const currentIndex = ref(0);
const isHistoryData = ref(false);
const formatList = ref<NewEmployeeHistory[]>([]); const formatList = ref<NewEmployeeHistory[]>([]);
const fieldName = [ const fieldName = [
@ -201,6 +202,19 @@ const fieldName = [
}, },
]; ];
function nextDate(pre: boolean = false) {
const date = new Date(currentDate.value);
pre ? date.setDate(date.getDate() - 1) : date.setDate(date.getDate() + 1);
const dateKey = formatDate(date.toString());
currentDate.value = dateKey;
}
function formatDate(date: string) {
const updatedAt = new Date(date);
const dateKey = `${updatedAt.getFullYear()}-${updatedAt.getMonth() + 1}-${updatedAt.getDate()}`;
return dateKey;
}
function isValidDate(dateString: string): boolean { function isValidDate(dateString: string): boolean {
if (typeof dateString !== 'string' || dateString.length < 24) { if (typeof dateString !== 'string' || dateString.length < 24) {
return false; return false;
@ -294,10 +308,12 @@ onMounted(async () => {
}); });
watch( watch(
() => currentIndex.value, () => currentDate.value,
(i) => { (i) => {
currentDate.value = formatList.value[i].date; const dateKey = formatDate(i);
currentData.value = formatList.value[i].data; isHistoryData.value = formatList.value.some(
(item) => item.date === dateKey,
);
}, },
); );
</script> </script>
@ -308,31 +324,49 @@ watch(
class="row full-width justify-center q-py-sm header-border" class="row full-width justify-center q-py-sm header-border"
style="background: hsla(var(--info-bg) / 0.1)" style="background: hsla(var(--info-bg) / 0.1)"
> >
<div class="surface-1 q-py-sm q-px-sm row items-center"> <div class="surface-1 q-py-sm q-px-sm row items-center no-wrap">
<q-btn <q-btn
flat flat
:disable="currentIndex === formatList.length - 1"
color="info" color="info"
padding="0" padding="0"
icon="mdi-chevron-left" icon="mdi-chevron-left"
@click="currentIndex++" @click="nextDate(true)"
/> />
<VueDatePicker
id="input-birth-date"
for="input-birth-date"
class="date-picker"
utc
autoApply
:teleport="true"
v-model="currentDate"
:locale="$i18n.locale === 'th-th' ? 'th' : 'en'"
:enableTimePicker="false"
>
<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>
<span class="text-weight-medium q-px-xl"> <span class="text-weight-medium q-px-xl">
{{ dateFormat(currentDate) }} {{ dateFormat(currentDate) }}
</span> </span>
</template>
</VueDatePicker>
<q-btn <q-btn
flat flat
:disable="currentIndex === 0"
color="info" color="info"
padding="0" padding="0"
icon="mdi-chevron-right" icon="mdi-chevron-right"
@click="currentIndex--" @click="nextDate()"
/> />
</div> </div>
</div> </div>
<q-table <q-table
v-if="currentData?.length > 0" v-if="isHistoryData && currentData?.length > 0"
flat flat
class="table-border" class="table-border"
table-header-class="surface-2" table-header-class="surface-2"
@ -454,4 +488,9 @@ watch(
:deep(.q-stepper__dot.row.flex-center.q-stepper__line.relative-position) { :deep(.q-stepper__dot.row.flex-center.q-stepper__line.relative-position) {
color: hsl(var(--info-bg)) !important; color: hsl(var(--info-bg)) !important;
} }
.date-picker {
cursor: pointer;
font-family: 'Noto Sans Thai', sans-serif;
}
</style> </style>

View file

@ -74,6 +74,10 @@ div.fullscreen.q-drawer__backdrop {
font-family: 'Noto Sans Thai', sans-serif; font-family: 'Noto Sans Thai', sans-serif;
} }
.dp__overlay_cell.dp__overlay_cell_pad {
font-family: 'Noto Sans Thai', sans-serif;
}
.disabled, .disabled,
.disabled *, .disabled *,
[disabled], [disabled],