hrms-checkin/src/views/HistoryView.vue

215 lines
6 KiB
Vue
Raw Normal View History

2023-11-14 17:47:43 +07:00
<script setup lang="ts">
import { ref, onMounted, computed, watch } 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 TableHistory from '@/components/TableHistory.vue'
2023-11-14 17:47:43 +07:00
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>('history')
// paging
const page = ref<number>(1)
const year = ref<number>(new Date().getFullYear())
const month = ref<number>(new Date().getMonth())
2023-11-29 15:30:07 +07:00
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
*
*/
async function changePage(pageVal: number, pageSizeVal: number, key: string) {
page.value = await pageVal
pageSize.value = await pageSizeVal
2023-11-24 18:12:56 +07:00
filter.value = await key
functionFetch()
}
function functionFetch() {
stores.tab === 'history' ? fetchlistHistory() : fetchlistTime()
}
/**
* งกนดงขอมลรายการประวการลงเวลาจาก api มาแสดง
* @param loading แสดง loading ไหม true อแสดง, false อไมแสดง
*/
async function fetchlistHistory() {
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)
fetchHistoryList(data) // ปิดกรณีมี total
})
.catch((err) => {
messageError($q, err)
})
.finally(() => {
hideLoader()
})
}
2023-11-24 18:12:56 +07:00
async function fetchlistTime() {
showLoader()
await http
.get(
config.API.historyTime() +
`?year=${year.value}&month=${month.value + 1}&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)
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, m: number) {
year.value = y
month.value = m
stores.year = y
functionFetch()
}
/** Hook*/
onMounted(async () => {
await functionFetch()
})
watch(
() => stores.tab,
() => {
page.value = 1
filter.value = ''
functionFetch()
}
)
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"
>
<q-btn
icon="arrow_back"
2023-11-14 17:47:43 +07:00
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">
2024-01-19 15:34:09 +07:00
<ToolBar
:fetchData="functionFetch"
@update:year="updateYear"
:tab="stores.tab"
/>
<TableHistory
:fetchData="functionFetch"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
:tab="stores.tab"
/>
</q-tab-panel>
<q-tab-panel name="time">
2024-01-19 15:34:09 +07:00
<ToolBar
:fetchData="functionFetch"
@update:year="updateYear"
:tab="stores.tab"
/>
<TableHistory
:fetchData="functionFetch"
:page-size="pageSize"
:total="total"
:page="page"
:paging="true"
@update:change-page="changePage"
:max-page="maxPage"
:tab="stores.tab"
/>
</q-tab-panel>
</q-tab-panels>
<!-- </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>