hrms-checkin/src/views/HistoryView.vue

221 lines
7.2 KiB
Vue
Raw Normal View History

2023-11-14 17:47:43 +07:00
<script setup lang="ts">
import { ref, onMounted, watch } from 'vue'
2023-11-20 12:11:34 +07:00
import { useQuasar } from 'quasar'
2024-09-02 17:37:08 +07:00
2023-11-14 17:47:43 +07:00
import { useRouter } from 'vue-router'
import http from '@/plugins/http'
import config from '@/app.config'
2026-04-27 19:21:23 +07:00
import { useCheckIn } from '@/stores/checkin'
import { useCounterMixin } from '@/stores/mixin'
2025-10-02 16:58:45 +07:00
import { calculateFiscalYear } from '@/utils/function'
2023-11-14 17:47:43 +07:00
2024-09-02 17:37:08 +07:00
import TableHistory from '@/components/TableHistory.vue' //ตารางประวัติการลงเวลา
import ToolBar from '@/components/ToolBar.vue' // เมนู Herder
const $q = useQuasar() //ใช้ noti quasar
2023-11-14 17:47:43 +07:00
const router = useRouter()
2026-04-27 19:21:23 +07:00
const stores = useCheckIn()
2024-09-02 17:37:08 +07:00
const { showLoader, hideLoader, messageError } = useCounterMixin()
2023-11-20 12:11:34 +07:00
const { fetchHistoryList } = stores
2023-11-14 17:47:43 +07:00
2025-10-02 16:58:45 +07:00
const year = ref<number>(calculateFiscalYear(new Date())) // ปีงบปรมาณ
2024-09-02 17:37:08 +07:00
const month = ref<number>(new Date().getMonth()) // เดือน
2025-10-02 16:58:45 +07:00
const year2 = ref<number>(new Date().getFullYear()) // ปีงบปรมาณ
2024-09-02 17:37:08 +07:00
const page = ref<number>(1) // หน้าปัจจุบัน
const pageSize = ref<number>(10) // จำนวนแถวต่อหน้า
const total = ref<number>(0) // จำนวนทั้งหมด
const maxPage = ref<number>(1) // จำนวนวหน้าทั้งหมด
const filter = ref<string>('') //search data table
2025-08-05 17:46:43 +07:00
const isLoading = ref<boolean>(false) // ตัวแปรสำหรับเช็คการโหลดข้อมูล
/**
* งก api เปลยนหน
* @param pageVal page
* @param pageSizeVal pagesize
*
*/
async function changePage(pageVal: number, pageSizeVal: number, key: string) {
2024-09-02 17:37:08 +07:00
page.value = pageVal
pageSize.value = pageSizeVal
filter.value = key
await functionFetch()
}
2025-08-05 17:46:43 +07:00
/** ฟังก์ชันสำหรับดึงข้อมูลตามประเภทแท็บที่เลือก*/
2024-09-02 17:37:08 +07:00
async function functionFetch() {
2025-05-15 09:57:13 +07:00
stores.rows = []
2024-09-02 17:37:08 +07:00
stores.tab === 'history' ? await fetchlistHistory() : await fetchlistTime()
}
2025-08-05 17:46:43 +07:00
/** ฟังก์ชั่นดึงข้อมูลรายการประวัติการลงเวลา*/
async function fetchlistHistory() {
2025-08-05 17:46:43 +07:00
isLoading.value = true
2023-11-20 12:11:34 +07:00
await http
.get(
config.API.history() +
`?year=${year.value}&page=${page.value}&pageSize=${
pageSize.value
}&keyword=${filter.value ? filter.value : ''}`
)
.then(async (res) => {
2024-09-02 17:37:08 +07:00
// ดึงข้อมูลและจำนวนทั้งหมด
const data = await res.data.result.data
total.value = await res.data.result.total
// คำนวณจำนวนหน้า
maxPage.value = Math.ceil(total.value / pageSize.value)
await fetchHistoryList(data)
})
.catch((err) => {
messageError($q, err)
})
.finally(() => {
2025-08-05 17:46:43 +07:00
isLoading.value = false
})
}
2023-11-24 18:12:56 +07:00
2024-09-02 17:37:08 +07:00
/**
* งกนดงรายการลงเวลากรณเศษ
*/
async function fetchlistTime() {
2025-08-05 17:46:43 +07:00
isLoading.value = true
await http
.get(
config.API.historyTime() +
2025-10-02 16:58:45 +07:00
`?year=${year2.value}&month=${month.value + 1}&page=${
page.value
}&pageSize=${pageSize.value}&keyword=${
filter.value ? filter.value : ''
}`
)
.then(async (res) => {
2024-09-02 17:37:08 +07:00
// ดึงข้อมูลและจำนวนทั้งหมด
const data = await res.data.result.data
total.value = await res.data.result.total
// คำนวณจำนวนหน้า
maxPage.value = Math.ceil(total.value / pageSize.value)
await fetchHistoryList(data)
2023-11-20 12:11:34 +07:00
})
.catch((err) => {
messageError($q, err)
})
.finally(() => {
2025-08-05 17:46:43 +07:00
isLoading.value = false
2023-11-20 12:11:34 +07:00
})
2023-11-14 17:47:43 +07:00
}
/**
2024-09-02 17:37:08 +07:00
* งกนสำหรบอปเดตปและเดอน
* @param y องการอปเดต
* @param m เดอนทองการอปเดต
*/
async function updateYear(y: number, m: number) {
2025-10-02 16:58:45 +07:00
stores.tab === 'history' ? (year.value = y) : (year2.value = y)
month.value = m
2024-09-02 17:37:08 +07:00
await functionFetch() // เรียกใช้งานฟังก์ชัน functionFetch เพื่อดึงข้อมูลใหม่
}
2024-09-02 17:37:08 +07:00
/**
* การเปลยนแปลงใน stores.tab เม stores.tab เปลยนไป
* จะรเซตค page , filter เปนสถานะเรมต
* แลวเรยก functionFetch เพอดงประวการลงเวลาใหม
*/
watch(
() => stores.tab,
() => {
page.value = 1
filter.value = ''
}
)
2023-11-14 17:47:43 +07:00
</script>
2023-11-14 17:47:43 +07:00
<template>
<div class="col-12 row justify-center">
<div class="col-xs-12 col-sm-12 col-md-12">
<q-card flat class="row col-12 cardNone">
<div
class="bg-secondary text-white col-12 row items-center q-px-md q-py-sm"
>
<q-btn
icon="arrow_back"
round
dense
flat
color="white"
@click="router.go(-1)"
/>
2024-01-19 15:34:09 +07:00
<span class="text-body1 text-weight-bold q-pl-md"
>ประวการลงเวลา
</span>
2023-11-14 17:47:43 +07:00
</div>
2024-01-19 15:34:09 +07:00
<div class="col-12 text-grey-9">
<q-tabs
v-model="stores.tab"
dense
align="left"
inline-label
class="rounded-borders"
indicator-color="primary"
active-bg-color="teal-1"
active-class="text-primary"
>
<q-tab name="history" label="ประวัติการลงเวลา" />
<q-tab name="time" label="รายการลงเวลากรณีพิเศษ" />
</q-tabs>
<q-separator />
<q-tab-panels v-model="stores.tab" animated>
<q-tab-panel name="history">
<ToolBar
2024-09-02 17:37:08 +07:00
:fetch-data="functionFetch"
@update:year="updateYear"
:tab="stores.tab"
/>
<TableHistory
2024-09-02 17:37:08 +07:00
:fetch-data="functionFetch"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
:tab="stores.tab"
2025-08-05 17:46:43 +07:00
:is-loading="isLoading"
/>
</q-tab-panel>
<q-tab-panel name="time">
<ToolBar
2024-09-02 17:37:08 +07:00
:fetch-data="functionFetch"
@update:year="updateYear"
:tab="stores.tab"
/>
<TableHistory
2026-04-27 19:21:23 +07:00
:fetch-data="functionFetch"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
:tab="stores.tab"
2025-08-05 17:46:43 +07:00
:is-loading="isLoading"
/>
</q-tab-panel>
</q-tab-panels>
2023-11-14 17:47:43 +07:00
</div>
</q-card>
</div>
</div>
</template>
<style scoped>
.q-tab-panel {
min-height: 400px;
}
</style>