ผูก API ลงเวลากรณีพิเศษ

This commit is contained in:
AnandaTon 2023-11-27 16:31:45 +07:00
parent 22688d40d0
commit 8cecc1e596
7 changed files with 296 additions and 98 deletions

View file

@ -185,7 +185,6 @@ export const useChangeRoundDataStore = defineStore(
}
async function fetchDatainHistory() {
console.log("tes");
console.log(profileId.value);
showLoader();
await http
@ -232,6 +231,7 @@ export const useChangeRoundDataStore = defineStore(
fetchDataForCardId,
checkCilck,
setProfileId,
changePage,
};
}
);

View file

@ -1,45 +1,58 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { ref, watch, defineEmits } from "vue";
import type { QTableProps } from "quasar";
import type { DataRows } from "@/modules/09_leave/interface/response/specialTime";
import type { ListData } from "@/modules/09_leave/interface/request/specialTime";
import { useCounterMixin } from "@/stores/mixin";
import type { DataOption } from "@/modules/09_leave/interface/index/Main";
import http from "@/plugins/http";
import config from "@/app.config";
import { useQuasar } from "quasar";
const $q = useQuasar();
const mixin = useCounterMixin();
const { date2Thai } = mixin;
const {
date2Thai,
messageError,
showLoader,
dialogMessageNotify,
dialogConfirm,
success,
hideLoader,
} = mixin;
export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
const rows = ref<any[]>([]);
const selectDate = ref<Date | null>(new Date());
const fiscalYear = ref<string | null>("0");
const DataMainOrig = ref<DataRows[]>([]); // ข้อมูลหลักดั้งเดิม
async function fecthList(data: ListData[]) {
let datalist: DataRows[] = data.map((e: ListData) => ({
id: e.id,
fullname: e.fullname,
date: date2Thai(new Date(e.date), false, true),
dateFix: date2Thai(new Date(e.dateFix)),
timeMorning:
e.startTimeMorning == null
? "-"
: e.startTimeMorning + " - " + e.endTimeMorning,
timeAfternoon:
e.startTimeAfternoon == null
? "-"
: e.startTimeAfternoon + " - " + e.endTimeAfternoon,
startTimeMorning: e.startTimeMorning,
endTimeMorning: e.endTimeMorning,
startTimeAfternoon: e.startTimeAfternoon,
endTimeAfternoon: e.endTimeAfternoon,
checkIn: e.checkOut,
checkOut: e.checkOut,
status: e.status,
checkInStatus: convertStatus(e.checkInStatus),
checkOutStatus: convertStatus(e.checkOutStatus),
}));
rows.value = datalist;
DataMainOrig.value = datalist;
}
// async function fecthList(data: ListData[]) {
// let datalist: DataRows[] = data.map((e: ListData) => ({
// id: e.id,
// fullname: e.fullname,
// date: date2Thai(new Date(e.date), false, true),
// dateFix: date2Thai(new Date(e.dateFix)),
// timeMorning:
// e.startTimeMorning == null
// ? "-"
// : e.startTimeMorning + " - " + e.endTimeMorning,
// timeAfternoon:
// e.startTimeAfternoon == null
// ? "-"
// : e.startTimeAfternoon + " - " + e.endTimeAfternoon,
// startTimeMorning: e.startTimeMorning,
// endTimeMorning: e.endTimeMorning,
// startTimeAfternoon: e.startTimeAfternoon,
// endTimeAfternoon: e.endTimeAfternoon,
// checkIn: e.checkOut,
// checkOut: e.checkOut,
// status: e.status,
// checkInStatus: convertStatus(e.checkInStatus),
// checkOutStatus: convertStatus(e.checkOutStatus),
// }));
// rows.value = datalist;
// DataMainOrig.value = datalist;
// }
const DataMainUpdate = ref<DataRows[]>([]); // ข้อมูลเปลี่ยนแปลง
const DataMain = (val: DataRows[]) => (DataMainOrig.value = val);
const DataUpdate = (filterYear: string) => {
@ -51,6 +64,105 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
const checkInStatus = ref<String>("ปกติ");
const checkOutStatus = ref<String>("ปกติ");
// paging
const year = ref<number>(2023);
const month = ref<number>(11);
const page = ref<number>(1);
const pageSize = ref<number>(10);
const filter = ref<string>(""); //search data table
// 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,
});
// Pagination - page & change page & get new data
// const currentPage = ref<number>(1);
// watch(
// [() => currentPage.value, () => initialPagination.value.rowsPerPage],
// () => {
// emit(
// "update:change-page",
// currentPage.value,
// initialPagination.value.rowsPerPage,
// true
// );
// }
// );
// const emit = defineEmits(["update:change-page"]);
/**
* 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();
}
/**
*
*/
const fetchData = async () => {
showLoader();
await http
.get(
config.API.specialTime() +
`?year=${year.value}&month=${month.value}&page=${page.value}&pageSize=${pageSize.value}&keyword=${filter.value}`
)
.then((res) => {
let data = res.data.result;
data.map((e: any) => {
rows.value.push({
id: e.id,
fullname: e.fullname,
date: date2Thai(new Date(e.checkDate), false, true),
dateFix: date2Thai(new Date(e.createdAt)),
timeMorning:
e.startTimeMorning == null
? "-"
: e.startTimeMorning + " - " + e.endTimeMorning,
timeAfternoon:
e.startTimeAfternoon == null
? "-"
: e.startTimeAfternoon + " - " + e.endTimeAfternoon,
startTimeMorning: e.startTimeMorning,
endTimeMorning: e.endTimeMorning,
startTimeAfternoon: e.startTimeAfternoon,
endTimeAfternoon: e.endTimeAfternoon,
checkIn: e.checkInTime,
checkOut: e.checkOutTime,
status: e.status,
checkInStatus: convertStatus(e.checkInStatus),
checkOutStatus: convertStatus(e.checkOutStatus),
reason: e.reason,
description: e.description,
checkInEdit: e.checkInEdit,
checkOutEdit: e.checkOutEdit,
});
});
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
//--------------|ฟิลเตอร์|--------------------------------------//
const searchFilterTable = async (searchDate: any) => {
rows.value = [];
@ -175,7 +287,7 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
}
return {
fecthList,
// fecthList,
rows,
visibleColumns,
columns,
@ -185,5 +297,9 @@ export const useSpecialTimeStore = defineStore("LeaveSpecialTime", () => {
checkInStatus,
checkOutStatus,
optionStatus,
fetchData,
changePage,
initialPagination,
updatePagination,
};
});