แก้ไข paginationApi รายการลงเวลาพิเศษ

This commit is contained in:
AnandaTon 2023-11-30 17:11:03 +07:00
parent e635a3be33
commit 2e904a95b8
4 changed files with 78 additions and 61 deletions

View file

@ -104,6 +104,7 @@ const approveData = async () => {
hideLoader(); hideLoader();
}) })
.finally(async () => { .finally(async () => {
SpecialTimeStore.fetchData();
hideLoader(); hideLoader();
}); });
}; };

View file

@ -13,4 +13,9 @@ interface ListData {
checkOut: string; checkOut: string;
checkIn: string; checkIn: string;
} }
export type { ListData };
interface DataDateMonthObject {
month: number;
year: number;
}
export type { ListData, DataDateMonthObject };

View file

@ -2,12 +2,14 @@ import { defineStore } from "pinia";
import { ref, watch, defineEmits } from "vue"; import { ref, watch, defineEmits } from "vue";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import type { DataRows } from "@/modules/09_leave/interface/response/specialTime"; import type { DataRows } from "@/modules/09_leave/interface/response/specialTime";
import type { ListData } from "@/modules/09_leave/interface/request/specialTime"; import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import type { DataOption } from "@/modules/09_leave/interface/index/Main"; import type { DataOption } from "@/modules/09_leave/interface/index/Main";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { mount } from "@vue/test-utils";
const $q = useQuasar(); const $q = useQuasar();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
@ -45,32 +47,6 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
const pageSize = ref<number>(10); const pageSize = ref<number>(10);
const filter = ref<string>(""); //search data table const filter = ref<string>(""); //search data table
const maxPage = ref<number>(0); const maxPage = ref<number>(0);
// Pagination - update rowsPerPage
// async function updatePagination(newPagination: any) {
// initialPagination.value = newPagination;
// // currentPage.value = 1;
// console.log("updatePagination");
// }
// Pagination - initial pagination
const initialPagination = ref<any>({
sortBy: null,
descending: false,
page: 1,
// rowsPerPage: pageSize,
});
/**
* api
* @param pageVal page
* @param pageSizeVal pagesize
*/
async function changePage(pageVal: number, pageSizeVal: number) {
page.value = await pageVal;
pageSize.value = await pageSizeVal;
console.log("changePage");
fetchData();
}
/** /**
* *
@ -126,6 +102,19 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
}); });
}; };
/**
* api
* @param pageVal page
* @param pageSizeVal pagesize
*/
async function changePage(pageVal: number, pageSizeVal: number) {
page.value = await pageVal;
pageSize.value = await pageSizeVal;
console.log(pageSize.value);
fetchData();
}
//--------------|ฟิลเตอร์|--------------------------------------// //--------------|ฟิลเตอร์|--------------------------------------//
const searchFilterTable = async (searchDate: any) => { const searchFilterTable = async (searchDate: any) => {
rows.value = []; rows.value = [];
@ -268,5 +257,7 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
page, page,
pageSize, pageSize,
month, month,
filter,
// changeMonth,
}; };
}); });

View file

@ -8,7 +8,7 @@ import DialogReason from "@/components/Dialogs/PopupReason.vue";
import DialogApprove from "@/modules/09_leave/components/4_specialTime/DialogApprove.vue"; import DialogApprove from "@/modules/09_leave/components/4_specialTime/DialogApprove.vue";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import type { DataDateMonthObject } from "@/modules/09_leave/interface/request/specialTime";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { identity } from "@fullcalendar/core/internal"; import { identity } from "@fullcalendar/core/internal";
@ -28,6 +28,7 @@ const name = ref<string>("");
const id = ref<string>(""); const id = ref<string>("");
const dateDialog = ref<string>(""); const dateDialog = ref<string>("");
const dateFixDialog = ref<string>(""); const dateFixDialog = ref<string>("");
const dateYear = ref<number>(new Date().getFullYear());
/**ฟังก์ชั่นไม่อนุมัติ */ /**ฟังก์ชั่นไม่อนุมัติ */
const unapprove = async (fullname: string, personId: string) => { const unapprove = async (fullname: string, personId: string) => {
@ -35,6 +36,7 @@ const unapprove = async (fullname: string, personId: string) => {
dialogTitle.value = " ไม่อนุมัติการลงเวลาพิเศษของ" + fullname; dialogTitle.value = " ไม่อนุมัติการลงเวลาพิเศษของ" + fullname;
name.value = fullname; name.value = fullname;
modalUnapprove.value = true; modalUnapprove.value = true;
// rejectData(); // rejectData();
}; };
@ -79,35 +81,20 @@ const clickSave = async (reason: string) => {
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
}) })
.finally(async () => {}); .finally(async () => {
dataSpecialTime.fetchData();
});
console.log(reason); console.log(reason);
}; };
//
const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null);
const resetFilter = () => {
filterKeyword.value = "";
if (filterRef.value) {
filterRef.value.focus();
}
};
// paging // paging
const page = ref<number>(1);
const pageSize = ref<number>(10); const pageSize = ref<number>(10);
const filter = ref<string>(""); //search data table
/** /**
* งก api เปลยนหน * งก api เปลยนหน
* @param pageVal page * @param pageVal page
* @param pageSizeVal pagesize * @param pageSizeVal pagesize
*/ */
async function changePage(pageVal: number, pageSizeVal: number) {
// page.value = await pageVal;
// pageSize.value = await pageSizeVal;
// dataSpecialTime.fetchData();
console.log("test");
}
// Pagination - initial pagination // Pagination - initial pagination
const initialPagination = ref<any>({ const initialPagination = ref<any>({
sortBy: null, sortBy: null,
@ -123,21 +110,36 @@ watch(
async () => { async () => {
dataSpecialTime.page = currentPage.value; dataSpecialTime.page = currentPage.value;
await dataSpecialTime.fetchData(); await dataSpecialTime.fetchData();
// emit(
// "update:change-page",
// currentPage.value,
// initialPagination.value.rowsPerPage,
// true
// );
} }
); );
// Pagination - update rowsPerPage // Pagination - update rowsPerPage
async function updatePagination(newPagination: any) { async function updatePagination(initialPagination: any) {
currentPage.value = 1; currentPage.value = 1;
dataSpecialTime.pageSize = initialPagination.value.rowsPerPage; dataSpecialTime.pageSize = initialPagination.rowsPerPage;
dataSpecialTime.page = 1; // set current page 1 per row dataSpecialTime.page = 1; // set current page 1 per row
} }
//
const filterKeyword = ref<string>("");
const filterRef = ref<HTMLInputElement | null>(null);
const resetFilter = () => {
filterKeyword.value = "";
dataSpecialTime.filter = filterKeyword.value;
dataSpecialTime.fetchData();
if (filterRef.value) {
filterRef.value.focus();
}
};
/** function ค้นหาข้อมูลแล้วอัปเดท*/
function filterFn() {
updatePagination(filterKeyword.value);
console.log(filterKeyword.value);
dataSpecialTime.filter = filterKeyword.value;
dataSpecialTime.pageSize = pageSize.value;
dataSpecialTime.fetchData();
}
/**Hook */ /**Hook */
onMounted(async () => { onMounted(async () => {
console.log("test"); console.log("test");
@ -145,11 +147,23 @@ onMounted(async () => {
}); });
/** Function Date */ /** Function Date */
const selectedDate = ref<string>("");
const dateMonth = ref<any>({ const dateMonth = ref<any>({
month: new Date().getMonth(), month: new Date().getMonth(),
year: new Date().getFullYear(), year: new Date().getFullYear(),
}); });
const updateMonth = async (e: DataDateMonthObject) => {
// console.log(dateMonth.value);
if (e != null) {
dateYear.value = e.year;
dateYear.value = dataSpecialTime.year;
dataSpecialTime.month = dateMonth.value.month + 1;
dataSpecialTime.year = dateMonth.value.year;
// filterKeyword.value = "";
}
await dataSpecialTime.fetchData();
};
//
const monthYearThai = (val: any) => { const monthYearThai = (val: any) => {
if (val == null) return ""; if (val == null) return "";
else return monthYear2Thai(val.month, val.year); else return monthYear2Thai(val.month, val.year);
@ -164,11 +178,12 @@ const monthYearThai = (val: any) => {
<div class="row col-12 q-col-gutter-sm q-mb-sm"> <div class="row col-12 q-col-gutter-sm q-mb-sm">
<div class="q-gutter-sm"> <div class="q-gutter-sm">
<datepicker <datepicker
v-model="selectedDate" v-model="dateMonth"
:locale="'th'" :locale="'th'"
autoApply autoApply
month-picker month-picker
:enableTimePicker="false" :enableTimePicker="false"
@update:modelValue="updateMonth"
> >
<template #year="{ year }">{{ year + 543 }}</template> <template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{ <template #year-overlay-value="{ value }">{{
@ -205,7 +220,8 @@ const monthYearThai = (val: any) => {
ref="filterRef" ref="filterRef"
outlined outlined
debounce="300" debounce="300"
placeholder="ค้นหา" placeholder="ค้นหาชื่อ-นามสกุล"
@keydown.enter.prevent="filterFn"
> >
<template v-slot:append> <template v-slot:append>
<q-icon v-if="filterKeyword == ''" name="search" /> <q-icon v-if="filterKeyword == ''" name="search" />
@ -246,7 +262,7 @@ const monthYearThai = (val: any) => {
:paging="false" :paging="false"
dense dense
:visible-columns="dataSpecialTime.visibleColumns" :visible-columns="dataSpecialTime.visibleColumns"
:rows-per-page-options="[5, 10, 25, 50, 100]" :rows-per-page-options="[10, 25, 50, 100]"
v-model:pagination="initialPagination" v-model:pagination="initialPagination"
@update:pagination="updatePagination" @update:pagination="updatePagination"
> >
@ -275,7 +291,11 @@ const monthYearThai = (val: any) => {
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'no'"> <div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }} {{
(dataSpecialTime.page - 1) * dataSpecialTime.pageSize +
props.rowIndex +
1
}}
</div> </div>
<div v-else> <div v-else>
{{ col.value }} {{ col.value }}