hrms-checkin/src/views/HistoryView.vue

173 lines
4.9 KiB
Vue
Raw Normal View History

2023-11-14 17:47:43 +07:00
<script setup lang="ts">
import { ref, onMounted } from 'vue'
2023-11-20 12:11:34 +07:00
import { useQuasar } from 'quasar'
2023-11-14 17:47:43 +07:00
import { useRouter } from 'vue-router'
import Table from '@/components/TableHistory.vue'
import ToolBar from '@/components/ToolBar.vue'
2023-11-20 12:11:34 +07:00
import http from '@/plugins/http'
import config from '@/app.config'
import { useCounterMixin } from '@/stores/mixin'
2023-11-14 17:47:43 +07:00
// importStores
import { useChekIn } from '@/stores/chekin'
2023-11-20 12:11:34 +07:00
const mixin = useCounterMixin()
2023-11-14 17:47:43 +07:00
const router = useRouter()
const stores = useChekIn()
2023-11-20 12:11:34 +07:00
const { showLoader, hideLoader, messageError } = mixin
const { fetchHistoryList } = stores
const $q = useQuasar() //ใช้ noti quasar
2023-11-14 17:47:43 +07:00
const tab = ref<string>('1')
// paging
const page = ref<number>(1)
const year = ref<number>(new Date().getFullYear())
const pageSize = ref<number>(10)
const total = ref<number>(0)
const maxPage = ref<number>(1)
const filter = ref<string>('') //search data table
/**
* งก api เปลยนหน
* @param pageVal page
* @param pageSizeVal pagesize
* @param loading loading
*/
async function changePage(
pageVal: number,
pageSizeVal: number,
2023-11-24 18:12:56 +07:00
loading: false,
key: string
) {
page.value = await pageVal
pageSize.value = await pageSizeVal
2023-11-24 18:12:56 +07:00
filter.value = await key
fetchlistHistory(loading)
}
/**
* งกนดงขอมลรายการประวการลงเวลาจาก api มาแสดง
* @param loading แสดง loading ไหม true อแสดง, false อไมแสดง
*/
async function fetchlistHistory(loading = true) {
loading === true && showLoader()
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) => {
const data = res.data.result.data
total.value = res.data.result.total
maxPage.value = await Math.ceil(total.value / pageSize.value)
2023-11-24 18:12:56 +07:00
fetchHistoryList(data) // ปิดกรณีมี total
2023-11-20 12:11:34 +07:00
})
.catch((err) => {
messageError($q, err)
})
.finally(() => {
hideLoader()
})
2023-11-14 17:47:43 +07:00
}
/**
* function updateYear
* @param y ปเดท
*/
async function updateYear(y: number) {
year.value = y
y && fetchlistHistory(true)
}
/** Hook*/
onMounted(() => {
2023-11-24 18:12:56 +07:00
fetchlistHistory(true)
})
2023-11-14 17:47:43 +07:00
</script>
<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"
>
<div class="col-2">
<q-btn
icon="arrow_back"
2023-11-14 17:47:43 +07:00
round
dense
flat
color="white"
@click="router.go(-1)"
/>
</div>
<q-space />
<span class="text-body1 text-weight-bold col-8 text-center"
>ประวการลงเวลา</span
>
<div class="col-2"></div>
</div>
<div class="col-12 q-pa-md text-grey-9">
<ToolBar :fetchData="fetchlistHistory" @update:year="updateYear" />
<q-card bordered flat>
<q-tabs
v-model="tab"
dense
align="left"
inline-label
class="rounded-borders"
indicator-color="primary"
active-bg-color="teal-1"
active-class="text-primary"
>
<q-tab name="1" label="ประวัติการลงเวลา" />
<q-tab name="2" label="รายการลงเวลากรณีพิเศษ" />
</q-tabs>
<q-separator />
<q-tab-panels v-model="tab" animated>
<q-tab-panel name="1">
<Table
:fetchData="fetchlistHistory"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
/>
</q-tab-panel>
<q-tab-panel name="2">
<Table
:fetchData="fetchlistHistory"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
/>
</q-tab-panel>
</q-tab-panels>
<!-- </q-card> -->
</q-card>
<!-- <Table
:fetchData="fetchlistHistory"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
/> -->
2023-11-14 17:47:43 +07:00
</div>
</q-card>
</div>
</div>
</template>