[Fix การลา] แก้ไขการยิง api ไป get ข้อมูลประเภทการลาและ position ในหน้ารายละเอียดการการลา และยกเลิกการลาให้เก็บใน store

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-07-14 14:56:21 +07:00
parent 6f7bdb91ee
commit 2d6e42170b
5 changed files with 264 additions and 188 deletions

View file

@ -1,17 +1,20 @@
import { defineStore } from "pinia";
import { ref, reactive } from "vue";
import type { QTableProps } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { DataProfilePosition } from "@/interface/response/main";
import type { DateFilter } from "@/modules/09_leave/interface/request/leave";
import type { QTableProps } from "quasar";
import type {
DataRows,
ListLeave,
LeaveType,
} from "@/modules/09_leave/interface/response/leave";
import type { FremData } from "@/modules/09_leave/interface/request/leave";
import http from "@/plugins/http";
import config from "@/app.config";
import type { FormData } from "@/modules/09_leave/interface/request/leave";
const mixin = useCounterMixin();
const { date2Thai } = mixin;
@ -32,12 +35,13 @@ export const useLeavelistDataStore = defineStore("leave", () => {
});
/**ข้อมูลใน Table*/
const mainData = ref<any>([]);
const mainData = ref<any[]>([]);
const rows = ref<DataRows[]>([]);
const columns = ref<QTableProps["columns"]>([]);
const visibleColumns = ref<string[]>([]);
const profilePositionData = ref<DataProfilePosition>();
const leaveType = ref<any>([]);
const leaveType = ref<LeaveType[]>([]);
/**
* fetchListLeave
@ -101,7 +105,7 @@ export const useLeavelistDataStore = defineStore("leave", () => {
* @param data Page
*/
async function fetchListLeaveReject(data: any[]) {
let datalist = data.map((e: FremData) => ({
let datalist = data.map((e: FormData) => ({
id: e.id,
profileType: e.profileType ?? "-",
leaveTypeName: e.leaveTypeName,
@ -171,52 +175,72 @@ export const useLeavelistDataStore = defineStore("leave", () => {
/** function ข้อมูลประเภทการลา*/
async function leaveTypeList() {
if (leaveType.value.length == 0) {
await http.get(config.API.leaveType()).then((res) => {
try {
const res = await http.get(config.API.leaveType());
leaveType.value = res.data.result;
leaveTypeOption(res.data.result);
leaveTypeOption();
return res.data.result;
});
} catch (error) {
throw error; // re-throw ถ้าต้องการให้ caller handle error
}
} else {
return leaveType.value;
}
}
function colorType(val: string) {
const dataType = leaveType.value.find((item: any) => item.id === val);
switch (dataType.code) {
case "LV-001":
return "#FFD1D1"; // Light Red
case "LV-002":
return "#C8E6C9"; // Light Green
case "LV-003":
return "#BBDEFB"; // Light Blue
case "LV-004":
return "#E1BEE7"; // Light Purple
case "LV-005":
return "#DCEDC8"; // Light Lime
case "LV-006":
return "#FFE0B2"; // Light Orange
case "LV-007":
return "#FFECB3"; // Light Amber
case "LV-008":
return "#CFD8DC"; // Light Blue Grey
case "LV-009":
return "#FFCCBC"; // Light Deep Orange
case "LV-010":
return "#FFF9C4"; // Light Amber Lighten
case "LV-011":
return "#B2DFDB"; // Light Teal
const dataType = leaveType.value.find((item: LeaveType) => item.id === val);
if (dataType) {
switch (dataType.code) {
case "LV-001":
return "#FFD1D1"; // Light Red
case "LV-002":
return "#C8E6C9"; // Light Green
case "LV-003":
return "#BBDEFB"; // Light Blue
case "LV-004":
return "#E1BEE7"; // Light Purple
case "LV-005":
return "#DCEDC8"; // Light Lime
case "LV-006":
return "#FFE0B2"; // Light Orange
case "LV-007":
return "#FFECB3"; // Light Amber
case "LV-008":
return "#CFD8DC"; // Light Blue Grey
case "LV-009":
return "#FFCCBC"; // Light Deep Orange
case "LV-010":
return "#FFF9C4"; // Light Amber Lighten
case "LV-011":
return "#B2DFDB"; // Light Teal
}
}
}
function leaveTypeOption(val: any) {
dataToobar.value = leaveType.value.map((e: any) => ({
function leaveTypeOption() {
dataToobar.value = leaveType.value.map((e: LeaveType) => ({
id: e.id,
name: e.name,
code: e.code,
}));
}
/** ฟังก์ชั่นดึงข้อมูลตำแหน่งจาก Keycloak */
async function fetchKeycloakPosition() {
if (!profilePositionData.value) {
try {
const res = await http.get(config.API.keycloakPosition());
profilePositionData.value = res.data.result;
return res.data.result;
} catch (error) {
throw error;
}
} else {
return profilePositionData.value; // Return cached data if available
}
}
return {
dataToobar,
tabMenu,
@ -234,5 +258,6 @@ export const useLeavelistDataStore = defineStore("leave", () => {
converstType,
leaveTypeOption,
leaveTypeList,
fetchKeycloakPosition,
};
});