ผูก API และปรับหน้าประวัติการลงเวลาในระบบ checkin

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2023-11-29 15:28:11 +07:00
parent 7dfc17dcbb
commit 3ea348f779
5 changed files with 98 additions and 76 deletions

View file

@ -4,5 +4,6 @@ const TimeStamp = `${env.API_URI}/leave`
export default { export default {
history: () => `${history}`, history: () => `${history}`,
historyTime: () => `${TimeStamp}/edit/history`,
createTimeStamp: () => `${TimeStamp}/user/edit`, createTimeStamp: () => `${TimeStamp}/user/edit`,
} }

View file

@ -17,10 +17,6 @@ const props = defineProps({
type: Boolean, type: Boolean,
defualt: false, defualt: false,
}, },
// selected: {
// type: Array,
// defualt: [],
// },
pageSize: { pageSize: {
type: Number, type: Number,
defualt: 10, defualt: 10,
@ -37,6 +33,11 @@ const props = defineProps({
type: Number, type: Number,
defualt: 0, defualt: 0,
}, },
tab: {
type: String,
defualt: '',
required: true,
},
nornmalData: { nornmalData: {
type: Boolean, type: Boolean,
defualt: false, defualt: false,
@ -77,7 +78,8 @@ const props = defineProps({
}, },
}) })
const keyword = ref<string>() const keyword = ref<string>('')
const tab = ref<string>(props.tab?.toString())
const emit = defineEmits(['update:change-page']) const emit = defineEmits(['update:change-page'])
@ -98,7 +100,6 @@ watch(
'update:change-page', 'update:change-page',
currentPage.value, currentPage.value,
initialPagination.value.rowsPerPage, initialPagination.value.rowsPerPage,
true,
keyword.value keyword.value
) )
} }
@ -115,7 +116,6 @@ async function filterFn() {
'update:change-page', 'update:change-page',
1, 1,
initialPagination.value.rowsPerPage, initialPagination.value.rowsPerPage,
true,
keyword.value keyword.value
) )
} }
@ -222,17 +222,6 @@ function classStatus(status: string) {
break break
} }
} }
const checkRequestEdit = (checkInStatus: string, checkOutStatus: string) => {
if (
checkInStatus === 'ขาด' ||
checkInStatus === 'สาย' ||
checkOutStatus === 'ขาด' ||
checkOutStatus === 'สาย'
)
return true
else false
}
</script> </script>
<template> <template>
@ -313,14 +302,9 @@ const checkRequestEdit = (checkInStatus: string, checkOutStatus: string) => {
{{ col.value }} {{ col.value }}
</div> </div>
</q-td> </q-td>
<q-td> <q-td v-if="tab === 'history'">
<q-btn <q-btn
v-if=" v-if="!props.row.isEdit"
checkRequestEdit(
props.row.checkInStatus,
props.row.checkOutStatus
)
"
style="min-width: 110px" style="min-width: 110px"
outline outline
icon="edit" icon="edit"
@ -329,8 +313,9 @@ const checkRequestEdit = (checkInStatus: string, checkOutStatus: string) => {
color="cyan-6" color="cyan-6"
@click="openPopup(props.row)" @click="openPopup(props.row)"
/> />
</q-td>
<q-td v-else-if="tab === 'time'">
<q-chip <q-chip
v-else-if="props.row.editStatus != ''"
:color="`${stores.classColorStatus(props.row.editStatus)}-2`" :color="`${stores.classColorStatus(props.row.editStatus)}-2`"
:text-color="`${stores.classColorStatus(props.row.editStatus)}-7`" :text-color="`${stores.classColorStatus(props.row.editStatus)}-7`"
>{{ props.row.editStatus }}</q-chip >{{ props.row.editStatus }}</q-chip
@ -369,16 +354,8 @@ const checkRequestEdit = (checkInStatus: string, checkOutStatus: string) => {
</q-item> </q-item>
</q-list> </q-list>
<q-card-section> <q-card-section>
<div class="row"> <div class="row" v-if="tab === 'history'">
<div <div class="col" v-if="!props.row.isEdit">
class="col"
v-if="
checkRequestEdit(
props.row.checkInStatus,
props.row.checkOutStatus
)
"
>
<q-btn <q-btn
class="full-width text-cen" class="full-width text-cen"
outline outline
@ -389,7 +366,10 @@ const checkRequestEdit = (checkInStatus: string, checkOutStatus: string) => {
@click="openPopup(props.row)" @click="openPopup(props.row)"
/> />
</div> </div>
<div class="col" v-else> </div>
<div class="row" v-else-if="tab === 'time'">
<div>
<q-chip <q-chip
:color="`${stores.classColorStatus(props.row.editStatus)}-2`" :color="`${stores.classColorStatus(props.row.editStatus)}-2`"
:text-color="`${stores.classColorStatus( :text-color="`${stores.classColorStatus(

View file

@ -16,6 +16,7 @@ interface FormData {
checkOutLocation: string checkOutLocation: string
editStatus: string editStatus: string
editReason: string editReason: string
isEdit: boolean
} }
interface Datalist { interface Datalist {
checkInId: string checkInId: string
@ -29,6 +30,7 @@ interface Datalist {
checkOutLocation: string checkOutLocation: string
editStatus: string editStatus: string
editReason: string editReason: string
isEdit: boolean
} }
interface FormTimeStemp { interface FormTimeStemp {

View file

@ -15,6 +15,7 @@ export const useChekIn = defineStore('checkin', () => {
*/ */
async function fetchHistoryList(data: FormData[]) { async function fetchHistoryList(data: FormData[]) {
rows.value = [] rows.value = []
const dataList: Datalist[] = await data.map((e: FormData) => ({ const dataList: Datalist[] = await data.map((e: FormData) => ({
checkInId: e.checkInId, checkInId: e.checkInId,
checkInDate: e.checkInDate ? date2Thai(e.checkInDate) : null, checkInDate: e.checkInDate ? date2Thai(e.checkInDate) : null,
@ -28,6 +29,7 @@ export const useChekIn = defineStore('checkin', () => {
checkOutLocation: e.checkOutLocation != '' ? e.checkOutLocation : '-', checkOutLocation: e.checkOutLocation != '' ? e.checkOutLocation : '-',
editStatus: e.editStatus != '' ? convertEditStatus(e.editStatus) : '', editStatus: e.editStatus != '' ? convertEditStatus(e.editStatus) : '',
editReason: e.editReason, editReason: e.editReason,
isEdit: e.isEdit,
})) }))
rows.value = dataList rows.value = dataList
} }

View file

@ -1,9 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue' import { ref, onMounted, computed, watch } from 'vue'
import { useQuasar } from 'quasar' import { useQuasar } from 'quasar'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import Table from '@/components/TableHistory.vue'
import TableHistory from '@/components/TableHistory.vue'
import ToolBar from '@/components/ToolBar.vue' import ToolBar from '@/components/ToolBar.vue'
import http from '@/plugins/http' import http from '@/plugins/http'
import config from '@/app.config' import config from '@/app.config'
import { useCounterMixin } from '@/stores/mixin' import { useCounterMixin } from '@/stores/mixin'
@ -17,12 +19,13 @@ const { showLoader, hideLoader, messageError } = mixin
const { fetchHistoryList } = stores const { fetchHistoryList } = stores
const $q = useQuasar() // noti quasar const $q = useQuasar() // noti quasar
const tab = ref<string>('1') const tab = ref<string>('history')
// paging // paging
const page = ref<number>(1) const page = ref<number>(1)
const year = ref<number>(new Date().getFullYear()) const year = ref<number>(new Date().getFullYear())
const pageSize = ref<number>(10) const month = ref<number>(new Date().getMonth())
const pageSize = ref<number>(3)
const total = ref<number>(0) const total = ref<number>(0)
const maxPage = ref<number>(1) const maxPage = ref<number>(1)
const filter = ref<string>('') //search data table const filter = ref<string>('') //search data table
@ -31,26 +34,26 @@ const filter = ref<string>('') //search data table
* งก api เปลยนหน * งก api เปลยนหน
* @param pageVal page * @param pageVal page
* @param pageSizeVal pagesize * @param pageSizeVal pagesize
* @param loading loading *
*/ */
async function changePage( async function changePage(pageVal: number, pageSizeVal: number, key: string) {
pageVal: number,
pageSizeVal: number,
loading: false,
key: string
) {
page.value = await pageVal page.value = await pageVal
pageSize.value = await pageSizeVal pageSize.value = await pageSizeVal
filter.value = await key filter.value = await key
fetchlistHistory(loading) functionFetch.value
} }
const functionFetch = computed(() => {
const result = tab.value === 'history' ? fetchlistHistory() : fetchlistTime()
return result
})
/** /**
* งกนดงขอมลรายการประวการลงเวลาจาก api มาแสดง * งกนดงขอมลรายการประวการลงเวลาจาก api มาแสดง
* @param loading แสดง loading ไหม true อแสดง, false อไมแสดง * @param loading แสดง loading ไหม true อแสดง, false อไมแสดง
*/ */
async function fetchlistHistory(loading = true) { async function fetchlistHistory() {
loading === true && showLoader() showLoader()
await http await http
.get( .get(
config.API.history() + config.API.history() +
@ -62,7 +65,31 @@ async function fetchlistHistory(loading = true) {
const data = res.data.result.data const data = res.data.result.data
total.value = res.data.result.total total.value = res.data.result.total
maxPage.value = await Math.ceil(total.value / pageSize.value) maxPage.value = await Math.ceil(total.value / pageSize.value)
fetchHistoryList(data) // total
})
.catch((err) => {
messageError($q, err)
})
.finally(() => {
hideLoader()
})
}
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 fetchHistoryList(data) // total
}) })
.catch((err) => { .catch((err) => {
@ -79,13 +106,21 @@ async function fetchlistHistory(loading = true) {
*/ */
async function updateYear(y: number) { async function updateYear(y: number) {
year.value = y year.value = y
y && fetchlistHistory(true) y && functionFetch.value
} }
/** Hook*/ /** Hook*/
onMounted(() => { onMounted(async () => {
fetchlistHistory(true) await functionFetch.value
}) })
watch(
() => tab.value,
() => {
page.value = 1
functionFetch.value
}
)
</script> </script>
<template> <template>
<div class="col-12 row justify-center"> <div class="col-12 row justify-center">
@ -123,35 +158,37 @@ onMounted(() => {
active-bg-color="teal-1" active-bg-color="teal-1"
active-class="text-primary" active-class="text-primary"
> >
<q-tab name="1" label="ประวัติการลงเวลา" /> <q-tab name="history" label="ประวัติการลงเวลา" />
<q-tab name="2" label="รายการลงเวลากรณีพิเศษ" /> <q-tab name="time" label="รายการลงเวลากรณีพิเศษ" />
</q-tabs> </q-tabs>
<q-separator /> <q-separator />
<q-tab-panels v-model="tab" animated> <q-tab-panels v-model="tab" animated>
<q-tab-panel name="1"> <q-tab-panel name="history">
<Table <TableHistory
:fetchData="fetchlistHistory" :fetchData="fetchlistHistory"
:page-size="pageSize" :page-size="pageSize"
:total="total" :total="total"
:page="page" :page="page"
:paging="true" :paging="true"
@update:change-page="changePage" @update:change-page="changePage"
:max-page="maxPage" :max-page="maxPage"
/> :tab="tab"
/>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="2"> <q-tab-panel name="time">
<Table <TableHistory
:fetchData="fetchlistHistory" :fetchData="fetchlistHistory"
:page-size="pageSize" :page-size="pageSize"
:total="total" :total="total"
:page="page" :page="page"
:paging="true" :paging="true"
@update:change-page="changePage" @update:change-page="changePage"
:max-page="maxPage" :max-page="maxPage"
/> :tab="tab"
/>
</q-tab-panel> </q-tab-panel>
</q-tab-panels> </q-tab-panels>
<!-- </q-card> --> <!-- </q-card> -->