hrms-checkin/src/components/ToolBar.vue

204 lines
5.6 KiB
Vue
Raw Normal View History

2023-11-14 17:47:43 +07:00
<script setup lang="ts">
import { ref, watch } from 'vue'
2024-09-02 17:37:08 +07:00
import { useCounterMixin } from '@/stores/mixin'
import { useChekIn } from '@/stores/chekin'
2025-10-02 13:13:53 +07:00
import { calculateFiscalYear } from '@/utils/function'
2024-09-02 17:37:08 +07:00
import type { DataDateMonthObject } from '@/interface/index/Main'
2023-11-14 17:47:43 +07:00
import Popup from '@/components/PopUp.vue'
const stores = useChekIn()
2024-09-02 17:37:08 +07:00
const { monthYear2Thai } = useCounterMixin()
2023-11-14 17:47:43 +07:00
2024-09-02 17:37:08 +07:00
/**
* props จาก components HistoryView
*/
const props = defineProps({
fetchData: {
type: Function,
require: true,
},
tab: {
type: String,
require: true,
},
})
const emit = defineEmits(['update:year'])
2025-07-16 10:08:15 +07:00
const filterYear = ref<number>(
2025-10-02 13:13:53 +07:00
stores.year ? stores.year : calculateFiscalYear(new Date())
2025-07-16 10:08:15 +07:00
) //ปีงบประมาณ
2024-09-02 17:37:08 +07:00
const titleName = ref<string>('เพิ่มรายการลงเวลากรณีพิเศษ') //หัว popup
const dateMonth = ref<DataDateMonthObject>({
month: new Date().getMonth(),
year:
stores.year && !isNaN(stores.year) ? stores.year : new Date().getFullYear(),
})
2024-09-02 17:37:08 +07:00
const modalPopup = ref<boolean>(false) // modal เพิ่มรายการลงเวลากรณีพิเศษ
2023-11-14 17:47:43 +07:00
2024-09-02 17:37:08 +07:00
/**
* งกนอปเดทปงบประมาณ
* @param type ประเภท year,mount
*/
function filterYearFn(type: string) {
const year = type === 'year' ? filterYear.value : dateMonth.value.year
const month = dateMonth.value.month
// ตรวจสอบค่าก่อนส่ง
if (isNaN(Number(year)) || isNaN(Number(month))) {
console.warn('Invalid year or month value:', { year, month })
return
}
2024-09-02 17:37:08 +07:00
//ส่งค่า ปีงบประมาณ กลับ
emit('update:year', Number(year), Number(month))
}
2024-09-02 17:37:08 +07:00
/**
* เป popup เพมรายการลงเวลากรณเศษ
*/
2023-11-14 17:47:43 +07:00
function onClickopen() {
modalPopup.value = true
}
2024-09-02 17:37:08 +07:00
/**
* popup เพมรายการลงเวลากรณเศษ
*/
2023-11-14 17:47:43 +07:00
function onClickClose() {
modalPopup.value = false
}
2024-09-02 17:37:08 +07:00
/**
* แปลงวนเดอนปเปนเดอนและปในภาษาไทย
* @param val นเดอนป
* @returns เดอนและปในภาษาไทย
*/
const monthYearThai = (val: DataDateMonthObject) => {
if (!val || !val.year || val.month === undefined || val.month === null) {
return ''
}
// ตรวจสอบว่าค่าเป็น number ที่ถูกต้อง
const year = Number(val.year)
const month = Number(val.month)
if (isNaN(year) || isNaN(month) || year < 1900 || month < 0 || month > 11) {
return ''
}
return monthYear2Thai(month, year)
}
2024-09-02 17:37:08 +07:00
/**
* watch การเปลยนแปลงของ stores.year
*/
watch(
() => stores.year,
(newYear) => {
dateMonth.value.year = newYear
}
)
2023-11-14 17:47:43 +07:00
</script>
<template>
2024-01-19 15:34:09 +07:00
<div class="items-center col-12 row q-pb-sm">
<datepicker
v-if="tab === 'history'"
menu-class-name="modalfix"
v-model="filterYear"
class="col-xs-5 col-sm-3 col-md-2"
:locale="'th'"
autoApply
year-picker
:transitions="false"
2024-01-19 15:34:09 +07:00
:enableTimePicker="false"
@update:modelValue="filterYearFn('year')"
>
2025-07-16 10:08:15 +07:00
<template #year="{ year }">{{
Number.isFinite(year) ? year + 543 : ''
}}</template>
2024-01-19 15:34:09 +07:00
<template #year-overlay-value="{ value }">{{
2025-07-16 10:08:15 +07:00
Number.isFinite(parseInt(value)) ? parseInt(value) + 543 : ''
2024-01-19 15:34:09 +07:00
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
2025-07-16 10:08:15 +07:00
:model-value="filterYear ? filterYear + 543 : ''"
2024-01-19 15:34:09 +07:00
:label="`${'ปีงบประมาณ'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
2024-01-19 15:34:09 +07:00
<datepicker
v-else-if="tab === 'time'"
menu-class-name="modalfix"
v-model="dateMonth"
class="col-xs-5 col-sm-3 col-md-2"
:locale="'th'"
autoApply
month-picker
:transitions="false"
2024-01-19 15:34:09 +07:00
:enableTimePicker="false"
@update:modelValue="filterYearFn('month')"
2024-01-19 15:34:09 +07:00
>
2025-07-16 10:08:15 +07:00
<template #year="{ year }">{{
Number.isFinite(year) ? year + 543 : ''
}}</template>
2024-01-19 15:34:09 +07:00
<template #year-overlay-value="{ value }">{{
2025-07-16 10:08:15 +07:00
Number.isFinite(parseInt(value)) ? parseInt(value) + 543 : ''
2024-01-19 15:34:09 +07:00
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
:model-value="monthYearThai(dateMonth) || 'เลือกเดือน/ปี'"
:label="`${'เดือน/ปีงบประมาณ'}`"
2024-01-19 15:34:09 +07:00
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
2024-01-19 15:34:09 +07:00
<q-space />
<q-btn
v-if="tab === 'time'"
2024-01-19 15:34:09 +07:00
unelevated
icon="add"
:dense="$q.screen.lt.sm"
color="secondary"
:label="$q.screen.gt.xs ? 'เพิ่มรายการลงเวลากรณีพิเศษ' : ''"
@click="onClickopen"
/>
2023-11-14 17:47:43 +07:00
</div>
<Popup
:modal="modalPopup"
:title="titleName"
:clickClose="onClickClose"
:fetchData="props.fetchData"
action="special"
/>
2023-11-14 17:47:43 +07:00
</template>
<style scoped></style>