hrms-checkin/src/components/ToolBar.vue

177 lines
4.7 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'
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'])
2024-09-02 17:37:08 +07:00
const filterYear = ref<number>(stores.year) //ปีงบประมาณ
const titleName = ref<string>('เพิ่มรายการลงเวลากรณีพิเศษ') //หัว popup
const dateMonth = ref<DataDateMonthObject>({
month: new Date().getMonth(),
year: 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
2024-09-02 17:37:08 +07:00
//ส่งค่า ปีงบประมาณ กลับ
emit('update:year', year, dateMonth.value.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 == null) return ''
else return monthYear2Thai(val.month, val.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')"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
:model-value="filterYear + 543"
: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('mount')"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
dense
lazy-rules
outlined
:model-value="monthYearThai(dateMonth)"
: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
<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>