fix(history): search year

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-10-02 16:58:45 +07:00
parent c966e1d961
commit d03c7f35fe
2 changed files with 23 additions and 26 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue' import { onMounted, ref, watch } from 'vue'
import { useCounterMixin } from '@/stores/mixin' import { useCounterMixin } from '@/stores/mixin'
import { useChekIn } from '@/stores/chekin' import { useChekIn } from '@/stores/chekin'
@ -27,14 +27,11 @@ const props = defineProps({
}) })
const emit = defineEmits(['update:year']) const emit = defineEmits(['update:year'])
const filterYear = ref<number>( const filterYear = ref<number>(calculateFiscalYear(new Date())) //
stores.year ? stores.year : calculateFiscalYear(new Date())
) //
const titleName = ref<string>('เพิ่มรายการลงเวลากรณีพิเศษ') // popup const titleName = ref<string>('เพิ่มรายการลงเวลากรณีพิเศษ') // popup
const dateMonth = ref<DataDateMonthObject>({ const dateMonth = ref<DataDateMonthObject>({
month: new Date().getMonth(), month: new Date().getMonth(),
year: year: new Date().getFullYear(),
stores.year && !isNaN(stores.year) ? stores.year : new Date().getFullYear(),
}) })
const modalPopup = ref<boolean>(false) // modal const modalPopup = ref<boolean>(false) // modal
@ -46,6 +43,8 @@ function filterYearFn(type: string) {
const year = type === 'year' ? filterYear.value : dateMonth.value.year const year = type === 'year' ? filterYear.value : dateMonth.value.year
const month = dateMonth.value.month const month = dateMonth.value.month
console.log(year, month)
// //
if (isNaN(Number(year)) || isNaN(Number(month))) { if (isNaN(Number(year)) || isNaN(Number(month))) {
console.warn('Invalid year or month value:', { year, month }) console.warn('Invalid year or month value:', { year, month })
@ -91,15 +90,19 @@ const monthYearThai = (val: DataDateMonthObject) => {
return monthYear2Thai(month, year) return monthYear2Thai(month, year)
} }
/** onMounted(() => {
* watch การเปลยนแปลงของ stores.year filterYearFn(props.tab === 'history' ? 'year' : 'month')
*/ })
watch(
() => stores.year, // /**
(newYear) => { // * watch stores.year
dateMonth.value.year = newYear // */
} // watch(
) // () => stores.year,
// (newYear) => {
// dateMonth.value.year = newYear
// }
// )
</script> </script>
<template> <template>
<div class="items-center col-12 row q-pb-sm"> <div class="items-center col-12 row q-pb-sm">

View file

@ -7,6 +7,7 @@ import http from '@/plugins/http'
import config from '@/app.config' import config from '@/app.config'
import { useChekIn } from '@/stores/chekin' import { useChekIn } from '@/stores/chekin'
import { useCounterMixin } from '@/stores/mixin' import { useCounterMixin } from '@/stores/mixin'
import { calculateFiscalYear } from '@/utils/function'
import TableHistory from '@/components/TableHistory.vue' // import TableHistory from '@/components/TableHistory.vue' //
import ToolBar from '@/components/ToolBar.vue' // Herder import ToolBar from '@/components/ToolBar.vue' // Herder
@ -17,8 +18,9 @@ const stores = useChekIn()
const { showLoader, hideLoader, messageError } = useCounterMixin() const { showLoader, hideLoader, messageError } = useCounterMixin()
const { fetchHistoryList } = stores const { fetchHistoryList } = stores
const year = ref<number>(new Date().getFullYear()) // const year = ref<number>(calculateFiscalYear(new Date())) //
const month = ref<number>(new Date().getMonth()) // const month = ref<number>(new Date().getMonth()) //
const year2 = ref<number>(new Date().getFullYear()) //
const page = ref<number>(1) // const page = ref<number>(1) //
const pageSize = ref<number>(10) // const pageSize = ref<number>(10) //
const total = ref<number>(0) // const total = ref<number>(0) //
@ -81,7 +83,7 @@ async function fetchlistTime() {
await http await http
.get( .get(
config.API.historyTime() + config.API.historyTime() +
`?year=${year.value}&month=${month.value + 1}&page=${ `?year=${year2.value}&month=${month.value + 1}&page=${
page.value page.value
}&pageSize=${pageSize.value}&keyword=${ }&pageSize=${pageSize.value}&keyword=${
filter.value ? filter.value : '' filter.value ? filter.value : ''
@ -111,9 +113,8 @@ async function fetchlistTime() {
* @param m เดอนทองการอปเดต * @param m เดอนทองการอปเดต
*/ */
async function updateYear(y: number, m: number) { async function updateYear(y: number, m: number) {
year.value = y stores.tab === 'history' ? (year.value = y) : (year2.value = y)
month.value = m month.value = m
stores.year = y
await functionFetch() // functionFetch await functionFetch() // functionFetch
} }
@ -127,15 +128,8 @@ watch(
() => { () => {
page.value = 1 page.value = 1
filter.value = '' filter.value = ''
functionFetch()
} }
) )
/**
* Hook
*/
onMounted(() => {
functionFetch()
})
</script> </script>
<template> <template>