2023-11-23 13:40:48 +07:00
|
|
|
import { defineStore } from "pinia";
|
2023-11-30 14:21:53 +07:00
|
|
|
import { ref } from "vue";
|
|
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
import type { QTableProps } from "quasar";
|
|
|
|
|
import type {
|
|
|
|
|
OptionData,
|
2023-11-30 13:36:01 +07:00
|
|
|
TypeLeave,
|
2023-11-23 13:40:48 +07:00
|
|
|
} from "@/modules/05_leave/interface/index/main";
|
2023-11-30 14:21:53 +07:00
|
|
|
import type {
|
|
|
|
|
ListLeave,
|
|
|
|
|
ListLeaveTable,
|
|
|
|
|
} from "@/modules/05_leave/interface/response/leave";
|
|
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2023-11-30 14:21:53 +07:00
|
|
|
const mixin = useCounterMixin();
|
|
|
|
|
const { date2Thai } = mixin;
|
2023-10-27 09:32:57 +07:00
|
|
|
|
|
|
|
|
export const useLeaveStore = defineStore("Leave", () => {
|
2023-11-23 13:40:48 +07:00
|
|
|
const tabValue = ref<string>("calendar");
|
|
|
|
|
const typeLeave = ref<string | undefined>("");
|
2023-11-30 14:21:53 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
const LeaveType = ref<string | null>("0");
|
|
|
|
|
const LeaveStatus = ref<string | null>("0");
|
|
|
|
|
const fiscalYearyear = ref<Number | null>(new Date().getFullYear());
|
2023-11-30 14:21:53 +07:00
|
|
|
const rows = ref<ListLeaveTable[]>([]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function เรียกข้อมูลรายการลา Table
|
|
|
|
|
* @param data ข้อมูลรายการลา Table
|
|
|
|
|
*/
|
|
|
|
|
async function fetchListLeave(data: ListLeave[]) {
|
|
|
|
|
let datalist: ListLeaveTable[] = data.map((e: ListLeave) => ({
|
|
|
|
|
id: e.id,
|
|
|
|
|
leaveTypeName: e.leaveTypeName,
|
|
|
|
|
leaveTypeId: e.leaveTypeId,
|
|
|
|
|
fullname: e.fullname,
|
|
|
|
|
dateSendLeave: e.dateSendLeave && date2Thai(e.dateSendLeave),
|
|
|
|
|
status: e.status,
|
|
|
|
|
isDelete: e.isDelete,
|
|
|
|
|
}));
|
|
|
|
|
rows.value = datalist;
|
|
|
|
|
}
|
2023-10-27 09:32:57 +07:00
|
|
|
|
2023-11-30 13:36:01 +07:00
|
|
|
/** ประเภทการลา */
|
|
|
|
|
const typeOptions = ref<OptionData[]>([]);
|
|
|
|
|
const typeOptionsMain = ref<OptionData[]>([]);
|
2023-11-30 14:21:53 +07:00
|
|
|
/**
|
|
|
|
|
* function เรียกข้อมูลประเภทการลา
|
|
|
|
|
* @param data ประเภทการลา
|
|
|
|
|
*/
|
2023-11-30 13:36:01 +07:00
|
|
|
async function fetchLeaveType(data: TypeLeave[]) {
|
|
|
|
|
typeOptionsMain.value = [
|
|
|
|
|
{ id: "00000000-0000-0000-0000-000000000000", name: "ทั้งหมด" },
|
|
|
|
|
];
|
|
|
|
|
const optionType = data.map((e: TypeLeave) => ({
|
|
|
|
|
id: e.id,
|
|
|
|
|
name: e.name,
|
|
|
|
|
}));
|
|
|
|
|
typeOptionsMain.value.push(...optionType);
|
|
|
|
|
typeOptions.value = typeOptionsMain.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** สถานะของการลา */
|
|
|
|
|
const statusOptionsMain = ref<OptionData[]>([
|
|
|
|
|
{ id: "ALL", name: "ทั้งหมด" },
|
|
|
|
|
{ id: "NEW ", name: "ใหม่" },
|
|
|
|
|
{ id: "PENDING ", name: "กำลังดำเนินการ" },
|
|
|
|
|
{ id: "APPROVE ", name: "อนุมัติ " },
|
|
|
|
|
{ id: "REJECT ", name: "ไม่อนุมัติ" },
|
|
|
|
|
{ id: "DELETE ", name: "ยกเลิก" },
|
|
|
|
|
]);
|
|
|
|
|
const statusOptions = ref<OptionData[]>(statusOptionsMain.value);
|
|
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/**
|
2023-11-30 14:21:53 +07:00
|
|
|
* function ต้นหาข้อมูลของ Option
|
2023-11-23 13:40:48 +07:00
|
|
|
* @param val ค่าที่ต้องการฟิลเตอร์
|
|
|
|
|
* @param update อัพเดทค่า
|
|
|
|
|
* @param refData ดาต้าที่ต้องการฟิลเตอร์
|
|
|
|
|
*/
|
2023-11-30 14:21:53 +07:00
|
|
|
function filterOption(val: any, update: Function, refData: string) {
|
2023-11-23 13:40:48 +07:00
|
|
|
switch (refData) {
|
|
|
|
|
case "LeaveTypeOption":
|
|
|
|
|
update(() => {
|
2023-11-30 13:36:01 +07:00
|
|
|
typeOptions.value = typeOptionsMain.value.filter(
|
2023-11-23 13:40:48 +07:00
|
|
|
(v: any) => v.name.indexOf(val) > -1
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "LeaveStatusOption":
|
|
|
|
|
update(() => {
|
2023-11-30 13:36:01 +07:00
|
|
|
statusOptions.value = statusOptionsMain.value.filter(
|
2023-11-23 13:40:48 +07:00
|
|
|
(v: any) => v.name.indexOf(val) > -1
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/** รายการประเภทการลาของ ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน*/
|
|
|
|
|
const optionsSpecific = ref([
|
|
|
|
|
{ id: "s0", name: "ลาไปศึกษาต่อ" },
|
|
|
|
|
{ id: "s1", name: "ลาฝึกอบรม" },
|
|
|
|
|
{ id: "s2", name: "ลาปฎิบัติการวิจัย" },
|
|
|
|
|
{ id: "s3", name: "ลาดูงาน" },
|
|
|
|
|
]);
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/** รายการประเภทการลาของ ลาอุปสมบทหรือลาประกอบพิธีฮัจย์ฯ*/
|
|
|
|
|
const optionsOrdination = ref([
|
|
|
|
|
{ id: "0", name: "ลาอุปสมบท" },
|
|
|
|
|
{ id: "1", name: "ลาประกอบพิธีฮัจย์ฯ" },
|
|
|
|
|
]);
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/** รายการข้อมูลประเภทใบลา */
|
|
|
|
|
const options = ref<OptionData[]>([
|
|
|
|
|
{ id: "1", name: "ลาป่วย" },
|
|
|
|
|
{ id: "2", name: "ลากิจส่วนตัว" },
|
|
|
|
|
{ id: "3", name: "ลาคลอดบุตร" },
|
|
|
|
|
{ id: "4", name: "ลาไปช่วยเหลือภริยาที่คลอดบุตร" },
|
|
|
|
|
{ id: "5", name: "ลาพักผ่อน" },
|
|
|
|
|
{ id: "6", name: "ลาอุปสมบทหรือลาประกอบพิธีฮัจย์ฯ" },
|
|
|
|
|
{ id: "7", name: "ลาเข้ารับการตรวจเลือกหรือเข้ารับการเตรียมพล" },
|
|
|
|
|
{ id: "8", name: "ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน" },
|
|
|
|
|
{ id: "9", name: "ลาไปปฎิบัติงานในองค์การระหว่างประเทศ" },
|
|
|
|
|
{ id: "10", name: "ลาติดตามคู่สมรส" },
|
|
|
|
|
{ id: "11", name: "ลาไปฟื้นฟูสมรรถภาพด้านอาชีพ" },
|
|
|
|
|
]);
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/** data table filter & column ของรายการลา */
|
2023-11-30 14:21:53 +07:00
|
|
|
const visibleColumns = ref<String[]>([
|
|
|
|
|
"no",
|
|
|
|
|
"leaveTypeName",
|
|
|
|
|
"dateSendLeave",
|
|
|
|
|
"status",
|
|
|
|
|
]);
|
2023-11-23 13:40:48 +07:00
|
|
|
const columns = ref<QTableProps["columns"]>([
|
|
|
|
|
{
|
|
|
|
|
name: "no",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "ลำดับ",
|
|
|
|
|
sortable: true,
|
|
|
|
|
field: "no",
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px; width:5%;",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-30 14:21:53 +07:00
|
|
|
name: "leaveTypeName",
|
2023-11-23 13:40:48 +07:00
|
|
|
align: "left",
|
|
|
|
|
label: "ประเภทการลา",
|
|
|
|
|
sortable: true,
|
2023-11-30 14:21:53 +07:00
|
|
|
field: "leaveTypeName",
|
2023-11-23 13:40:48 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px; width:15%;",
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-11-30 14:21:53 +07:00
|
|
|
name: "dateSendLeave",
|
2023-11-23 13:40:48 +07:00
|
|
|
align: "left",
|
|
|
|
|
label: "วันที่ยื่นใบลา",
|
|
|
|
|
sortable: true,
|
2023-11-30 14:21:53 +07:00
|
|
|
field: "dateSendLeave",
|
2023-11-23 13:40:48 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px; width:15%;",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "status",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "สถานะ",
|
|
|
|
|
sortable: true,
|
|
|
|
|
field: "status",
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px; width:10%;",
|
|
|
|
|
},
|
|
|
|
|
]);
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/**
|
|
|
|
|
*ฟังก์ชั่นแปลงประเภทแบบฟอร์มลา
|
|
|
|
|
* @param item ประเภทแบบฟอร์ม
|
|
|
|
|
* @param subitem ประเภทแบบฟอร์มย่อย
|
|
|
|
|
*/
|
|
|
|
|
function typeConvert(item: string, subitem: any) {
|
|
|
|
|
// console.log('first',item)
|
|
|
|
|
if (item !== "6" && item !== "8") {
|
|
|
|
|
typeLeave.value = convertSubtitle(item);
|
|
|
|
|
} else if (item === "6") {
|
|
|
|
|
typeLeave.value = convertSubtitleInfo(subitem);
|
|
|
|
|
} else if (item === "8") {
|
|
|
|
|
typeLeave.value = convertSubtitleInfo2(subitem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/**
|
|
|
|
|
*ฟังก์ชั่นแปลงประเภทแบบฟอร์มลา ลาอุปสมบท/ลาประกอบพิธีฮัจย์
|
|
|
|
|
* @param val ค่า string
|
|
|
|
|
* @returns ส่งค่าที่แปลงแล้ว
|
|
|
|
|
*/
|
|
|
|
|
function convertSubtitle(val: string) {
|
|
|
|
|
return options.value.find((x) => x.id == val)?.name;
|
|
|
|
|
}
|
2023-11-21 15:59:14 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
/**
|
|
|
|
|
*ฟังก์ชั่นแปลงประเภทแบบฟอร์มลา ลาอุปสมบท/ลาประกอบพิธีฮัจย์ ย่อย
|
|
|
|
|
* @param val ค่า string
|
|
|
|
|
* @returns ส่งค่าที่แปลงแล้ว
|
|
|
|
|
*/
|
|
|
|
|
function convertSubtitleInfo(val: string) {
|
|
|
|
|
return optionsOrdination.value.find((x) => x.id == val)?.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*ฟังก์ชั่นแปลง ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน
|
|
|
|
|
* @param val ค่า string
|
|
|
|
|
* @returns ส่งค่าที่แปลงแล้ว
|
|
|
|
|
*/
|
|
|
|
|
function convertSubtitleInfo2(val: string) {
|
|
|
|
|
return optionsSpecific.value.find((x) => x.id == val)?.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
tabValue,
|
|
|
|
|
typeOptions,
|
|
|
|
|
optionsSpecific,
|
|
|
|
|
statusOptions,
|
2023-11-30 14:21:53 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
visibleColumns,
|
|
|
|
|
columns,
|
|
|
|
|
rows,
|
|
|
|
|
LeaveType,
|
|
|
|
|
LeaveStatus,
|
2023-11-30 13:36:01 +07:00
|
|
|
|
2023-11-23 13:40:48 +07:00
|
|
|
fiscalYearyear,
|
|
|
|
|
options,
|
|
|
|
|
optionsOrdination,
|
|
|
|
|
typeConvert,
|
|
|
|
|
typeLeave,
|
2023-11-30 13:36:01 +07:00
|
|
|
|
2023-11-30 14:21:53 +07:00
|
|
|
fetchListLeave,
|
2023-11-30 13:36:01 +07:00
|
|
|
fetchLeaveType,
|
|
|
|
|
filterOption,
|
2023-11-23 13:40:48 +07:00
|
|
|
};
|
|
|
|
|
});
|