การลา >> ช่องประเภทใบลา (user)

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2023-12-25 14:18:29 +07:00
parent 58cd5b57de
commit b9ece25920

View file

@ -1,324 +1,344 @@
import { defineStore } from "pinia" import { defineStore } from "pinia";
import { ref } from "vue" import { ref } from "vue";
import { useQuasar } from "quasar" import { useQuasar } from "quasar";
import type { QTableProps } from "quasar" import type { QTableProps } from "quasar";
import type { OptionData, TypeLeave } from "@/modules/05_leave/interface/index/main" import type {
import type { ListLeave, ListLeaveTable } from "@/modules/05_leave/interface/response/leave" OptionData,
import http from "@/plugins/http" TypeLeave,
import config from "@/app.config" } from "@/modules/05_leave/interface/index/main";
import type {
ListLeave,
ListLeaveTable,
} from "@/modules/05_leave/interface/response/leave";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin" import { useCounterMixin } from "@/stores/mixin";
const mixin = useCounterMixin() const mixin = useCounterMixin();
const { date2Thai, messageError } = mixin const { date2Thai, messageError } = mixin;
const $q = useQuasar() const $q = useQuasar();
export const useLeaveStore = defineStore("Leave", () => { export const useLeaveStore = defineStore("Leave", () => {
const tabValue = ref<string>("calendar") const tabValue = ref<string>("calendar");
const typeLeave = ref<string | undefined>("") const typeLeave = ref<string | undefined>("");
const LeaveType = ref<string | null>("0") const LeaveType = ref<string | null>("0");
const LeaveStatus = ref<string | null>("0") const LeaveStatus = ref<string | null>("0");
const fiscalYearyear = ref<Number | null>(new Date().getFullYear()) const fiscalYearyear = ref<Number | null>(new Date().getFullYear());
const rows = ref<ListLeaveTable[]>([]) const rows = ref<ListLeaveTable[]>([]);
/** /**
* function Table * function Table
* @param data Table * @param data Table
*/ */
async function fetchListLeave(data: ListLeave[]) { async function fetchListLeave(data: ListLeave[]) {
let datalist: ListLeaveTable[] = data.map((e: ListLeave) => ({ let datalist: ListLeaveTable[] = data.map((e: ListLeave) => ({
id: e.id, id: e.id,
leaveTypeName: e.leaveTypeName, leaveTypeName: e.leaveTypeName,
leaveTypeId: e.leaveTypeId, leaveTypeId: e.leaveTypeId,
fullName: e.fullName, fullName: e.fullName,
dateSendLeave: e.dateSendLeave && date2Thai(e.dateSendLeave), dateSendLeave: e.dateSendLeave && date2Thai(e.dateSendLeave),
status: e.status, status: e.status,
statusConvert: convertStatud(e.status), statusConvert: convertStatud(e.status),
isDelete: e.isDelete, isDelete: e.isDelete,
})) }));
rows.value = datalist rows.value = datalist;
} }
//ฟังก์ชั่นแปลง Status //ฟังก์ชั่นแปลง Status
function convertStatud(val: string) { function convertStatud(val: string) {
switch (val) { switch (val) {
case "NEW": case "NEW":
return "ใหม่" return "ใหม่";
case "PENDING": case "PENDING":
return "กำลังดำเนินการ" return "กำลังดำเนินการ";
case "APPROVE": case "APPROVE":
return "อนุมัติ" return "อนุมัติ";
case "REJECT": case "REJECT":
return "ไม่อนุมัติ" return "ไม่อนุมัติ";
case "DELETE": case "DELETE":
return "ยกเลิก" return "ยกเลิก";
} }
} }
/** ประเภทการลา */ /** ประเภทการลา */
const typeOptions = ref<OptionData[]>([]) const typeOptions = ref<OptionData[]>([]);
const typeId = ref<string | undefined>("") const typeId = ref<string | undefined>("");
const typeOptionsMain = ref<OptionData[]>([]) const typeOptionsMain = ref<OptionData[]>([]);
const typeOptionsAdd = ref<OptionData[]>([]) const typeOptionsAdd = ref<OptionData[]>([]);
/** รายการข้อมูลประเภทใบลา */ /** รายการข้อมูลประเภทใบลา */
const options = ref<OptionData[]>([]) const options = ref<OptionData[]>([]);
/** /**
* function * function
* @param data * @param data
*/ */
async function fetchLeaveType(data: TypeLeave[]) { async function fetchLeaveType(data: TypeLeave[]) {
typeOptionsMain.value = [ typeOptionsMain.value = [
{ {
id: "00000000-0000-0000-0000-000000000000", id: "00000000-0000-0000-0000-000000000000",
name: "ทั้งหมด", name: "ทั้งหมด",
code: "LV-000", code: "LV-000",
}, },
] ];
const optionType = data.map((e: TypeLeave) => ({ console.log(typeOptionsMain.value);
id: e.id,
name: e.name,
code: e.code,
}))
typeOptionsMain.value = []
typeOptionsMain.value.push(...optionType)
typeOptions.value = typeOptionsMain.value
typeOptionsAdd.value = [] const optionType = data.map((e: TypeLeave) => ({
typeOptionsAdd.value.push(...optionType) id: e.id,
options.value = typeOptionsAdd.value name: e.name,
} code: e.code,
}));
/** สถานะของการลา */ typeOptionsMain.value.push(...optionType);
const statusOptionsMain = ref<any[]>([ typeOptions.value = typeOptionsMain.value;
{ id: "ALL", name: "ทั้งหมด" },
{ id: "NEW", name: "ใหม่" },
{ id: "PENDING", name: "กำลังดำเนินการ" },
{ id: "APPROVE", name: "อนุมัติ " },
{ id: "REJECT", name: "ไม่อนุมัติ" },
{ id: "DELETE", name: "ยกเลิก" },
])
const statusOptions = ref<any[]>(statusOptionsMain.value)
/** typeOptionsAdd.value = [];
* function Option typeOptionsAdd.value.push(...optionType);
* @param val options.value = typeOptionsAdd.value;
* @param update }
* @param refData
*/
function filterOption(val: any, update: Function, refData: string) {
switch (refData) {
case "LeaveTypeOption":
update(() => {
typeOptions.value = typeOptionsMain.value.filter((v: any) => v.name.indexOf(val) > -1)
})
break
case "LeaveStatusOption":
update(() => {
statusOptions.value = statusOptionsMain.value.filter((v: any) => v.name.indexOf(val) > -1)
})
break
default:
break
}
}
/** รายการประเภทการลาของ ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน*/
const optionsSpecific = ref([
{ id: "s0", name: "ลาไปศึกษาต่อ", code: "s0" },
{ id: "s1", name: "ลาฝึกอบรม", code: "s1" },
{ id: "s2", name: "ลาปฎิบัติการวิจัย", code: "s2" },
{ id: "s3", name: "ลาดูงาน", code: "s3" },
])
/** รายการประเภทการลาของ ลาอุปสมบทหรือลาประกอบพิธีฮัจญ์*/ /** สถานะของการลา */
const optionsOrdination = ref([ const statusOptionsMain = ref<any[]>([
{ id: "0", name: "ลาอุปสมบท", code: "0" }, { id: "ALL", name: "ทั้งหมด" },
{ id: "1", name: "ลาประกอบพิธีฮัจญ์", code: "1" }, { id: "NEW", name: "ใหม่" },
]) { id: "PENDING", name: "กำลังดำเนินการ" },
{ id: "APPROVE", name: "อนุมัติ " },
{ id: "REJECT", name: "ไม่อนุมัติ" },
{ id: "DELETE", name: "ยกเลิก" },
]);
const statusOptions = ref<any[]>(statusOptionsMain.value);
/** data table filter & column ของรายการลา */ /**
const visibleColumns = ref<String[]>(["no", "leaveTypeName", "dateSendLeave", "status"]) * function Option
const columns = ref<QTableProps["columns"]>([ * @param val
{ * @param update
name: "no", * @param refData
align: "left", */
label: "ลำดับ", function filterOption(val: any, update: Function, refData: string) {
sortable: true, switch (refData) {
field: "no", case "LeaveTypeOption":
headerStyle: "font-size: 14px", update(() => {
style: "font-size: 14px; width:5%;", typeOptions.value = typeOptionsMain.value.filter(
}, (v: any) => v.name.indexOf(val) > -1
{ );
name: "leaveTypeName", });
align: "left", break;
label: "ประเภทการลา", case "LeaveStatusOption":
sortable: true, update(() => {
field: "leaveTypeName", statusOptions.value = statusOptionsMain.value.filter(
headerStyle: "font-size: 14px", (v: any) => v.name.indexOf(val) > -1
style: "font-size: 14px; width:15%;", );
}, });
{ break;
name: "dateSendLeave", default:
align: "left", break;
label: "วันที่ยื่นใบลา", }
sortable: true, }
field: "dateSendLeave", /** รายการประเภทการลาของ ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน*/
headerStyle: "font-size: 14px", const optionsSpecific = ref([
style: "font-size: 14px; width:15%;", { id: "s0", name: "ลาไปศึกษาต่อ", code: "s0" },
}, { id: "s1", name: "ลาฝึกอบรม", code: "s1" },
{ { id: "s2", name: "ลาปฎิบัติการวิจัย", code: "s2" },
name: "status", { id: "s3", name: "ลาดูงาน", code: "s3" },
align: "left", ]);
label: "สถานะ",
sortable: true,
field: "status",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:10%;",
},
])
/**
*
* @param item
* @param subitem
*/
function typeConvert(item: string, subitem: any) {
// console.log('first',item)
if (item !== "LV-006" && item !== "LV-008") {
typeLeave.value = convertSubtitle(item)
} else if (item === "LV-006") {
typeLeave.value = convertSubtitleInfo(subitem)
} else if (item === "LV-008") {
typeLeave.value = convertSubtitleInfo2(subitem)
}
typeId.value = convertId(item)
}
/** /** รายการประเภทการลาของ ลาอุปสมบทหรือลาประกอบพิธีฮัจญ์*/
* / const optionsOrdination = ref([
* @param val string { id: "0", name: "ลาอุปสมบท", code: "0" },
* @returns { id: "1", name: "ลาประกอบพิธีฮัจญ์", code: "1" },
*/ ]);
function convertSubtitle(val: string) {
return options.value.find(x => x.code == val)?.name
}
/** /** data table filter & column ของรายการลา */
* / const visibleColumns = ref<String[]>([
* @param val string "no",
* @returns "leaveTypeName",
*/ "dateSendLeave",
function convertSubtitleInfo(val: string) { "status",
return optionsOrdination.value.find(x => x.id == val)?.name ]);
} const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:5%;",
},
{
name: "leaveTypeName",
align: "left",
label: "ประเภทการลา",
sortable: true,
field: "leaveTypeName",
headerStyle: "font-size: 14px",
style: "font-size: 14px; width:15%;",
},
{
name: "dateSendLeave",
align: "left",
label: "วันที่ยื่นใบลา",
sortable: true,
field: "dateSendLeave",
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%;",
},
]);
/**
*
* @param item
* @param subitem
*/
function typeConvert(item: string, subitem: any) {
// console.log('first',item)
if (item !== "LV-006" && item !== "LV-008") {
typeLeave.value = convertSubtitle(item);
} else if (item === "LV-006") {
typeLeave.value = convertSubtitleInfo(subitem);
} else if (item === "LV-008") {
typeLeave.value = convertSubtitleInfo2(subitem);
}
typeId.value = convertId(item);
}
/** /**
* * /
* @param val string * @param val string
* @returns * @returns
*/ */
function convertSubtitleInfo2(val: string) { function convertSubtitle(val: string) {
return optionsSpecific.value.find(x => x.id == val)?.name return options.value.find((x) => x.code == val)?.name;
} }
/** /**
* id api * /
* @param val string * @param val string
* @returns * @returns
*/ */
function convertId(val: string) { function convertSubtitleInfo(val: string) {
return options.value.find(x => x.code == val)?.id return optionsOrdination.value.find((x) => x.id == val)?.name;
} }
/** /**
* profile *
*/ * @param val string
const dateSendLeave = ref<Date>() //วันที่ยื่นใบลา * @returns
const leaveTypeName = ref<string>("") //Name ประเภทการลา */
const dear = ref<string>("") //เรียน function convertSubtitleInfo2(val: string) {
const fullName = ref<string>("") //คำนำหน้า ชื่อ นามสกุล ผู้ยื่นขอ return optionsSpecific.value.find((x) => x.id == val)?.name;
const positionName = ref<string>("") //ตำแหน่งผู้ยื่นขอ }
const positionLevelName = ref<string>("") //ระดับผู้ยื่นขอ
const organizationName = ref<string>("") //สังกัดผู้ยื่นขอ
const leaveLimit = ref<number>(0) //โควต้าลา(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
const leaveTotal = ref<number>(0) //ลาไปแล้ว(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
const leaveRemain = ref<number>(0) //คงเหลือโควต้า(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
const restDayTotalOld = ref<number>(0) //จำนวนวันลาพักผ่อนสะสม จากปีที่ผ่านมา
const birthDate = ref<Date>() //วันเกิด
const dateAppoint = ref<Date>() //วันที่เข้ารับราชการ
const salary = ref<number>(0) //เงินเดือนปัจจุบัน
const salaryText = ref<string>("") //เงินเดือนปัจจุบัน(ภาษาไทย)
const leaveLast = ref<any>()
const restDayCurrentTotal = ref<string>("")
//ดึงข้อมูล profile จาก API
async function fetchProfile() {
await http
.post(config.API.leaveProfile(), { type: typeId.value })
.then((res: any) => {
const data = res.data.result
dateSendLeave.value = data.dateSendLeave
leaveTypeName.value = data.leaveTypeName
dear.value = data.dear
fullName.value = data.fullName
positionName.value = data.positionName
positionLevelName.value = data.positionLevelName
organizationName.value = data.organizationName
leaveLimit.value = data.leaveLimit
leaveTotal.value = data.leaveTotal
leaveRemain.value = data.leaveRemain
restDayTotalOld.value = data.restDayTotalOld
birthDate.value = data.birthDate
dateAppoint.value = data.dateAppoint
salary.value = data.salary
salaryText.value = data.salaryText
leaveLast.value = date2Thai(data.leaveLast) !== "0001-01-01T00:00:00" ? date2Thai(data.leaveLast) : "-"
restDayCurrentTotal.value = data.restDayCurrentTotal
})
.catch((e: any) => {
messageError($q, e)
})
}
return { /**
tabValue, * id api
typeOptions, * @param val string
optionsSpecific, * @returns
statusOptions, */
function convertId(val: string) {
return options.value.find((x) => x.code == val)?.id;
}
visibleColumns, /**
columns, * profile
rows, */
LeaveType, const dateSendLeave = ref<Date>(); //วันที่ยื่นใบลา
LeaveStatus, const leaveTypeName = ref<string>(""); //Name ประเภทการลา
const dear = ref<string>(""); //เรียน
const fullName = ref<string>(""); //คำนำหน้า ชื่อ นามสกุล ผู้ยื่นขอ
const positionName = ref<string>(""); //ตำแหน่งผู้ยื่นขอ
const positionLevelName = ref<string>(""); //ระดับผู้ยื่นขอ
const organizationName = ref<string>(""); //สังกัดผู้ยื่นขอ
const leaveLimit = ref<number>(0); //โควต้าลา(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
const leaveTotal = ref<number>(0); //ลาไปแล้ว(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
const leaveRemain = ref<number>(0); //คงเหลือโควต้า(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
const restDayTotalOld = ref<number>(0); //จำนวนวันลาพักผ่อนสะสม จากปีที่ผ่านมา
const birthDate = ref<Date>(); //วันเกิด
const dateAppoint = ref<Date>(); //วันที่เข้ารับราชการ
const salary = ref<number>(0); //เงินเดือนปัจจุบัน
const salaryText = ref<string>(""); //เงินเดือนปัจจุบัน(ภาษาไทย)
const leaveLast = ref<any>();
const restDayCurrentTotal = ref<string>("");
//ดึงข้อมูล profile จาก API
async function fetchProfile() {
await http
.post(config.API.leaveProfile(), { type: typeId.value })
.then((res: any) => {
const data = res.data.result;
dateSendLeave.value = data.dateSendLeave;
leaveTypeName.value = data.leaveTypeName;
dear.value = data.dear;
fullName.value = data.fullName;
positionName.value = data.positionName;
positionLevelName.value = data.positionLevelName;
organizationName.value = data.organizationName;
leaveLimit.value = data.leaveLimit;
leaveTotal.value = data.leaveTotal;
leaveRemain.value = data.leaveRemain;
restDayTotalOld.value = data.restDayTotalOld;
birthDate.value = data.birthDate;
dateAppoint.value = data.dateAppoint;
salary.value = data.salary;
salaryText.value = data.salaryText;
leaveLast.value =
date2Thai(data.leaveLast) !== "0001-01-01T00:00:00"
? date2Thai(data.leaveLast)
: "-";
restDayCurrentTotal.value = data.restDayCurrentTotal;
})
.catch((e: any) => {
messageError($q, e);
});
}
fiscalYearyear, return {
options, tabValue,
optionsOrdination, typeOptions,
typeConvert, optionsSpecific,
typeLeave, statusOptions,
typeId,
fetchListLeave, visibleColumns,
fetchLeaveType, columns,
filterOption, rows,
fetchProfile, LeaveType,
LeaveStatus,
//ส่งออกตัวแปร profileที่ได้จาก Api fiscalYearyear,
dateSendLeave, options,
leaveTypeName, optionsOrdination,
dear, typeConvert,
fullName, typeLeave,
positionName, typeId,
positionLevelName,
organizationName, fetchListLeave,
leaveLimit, //โควต้าลา(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น) fetchLeaveType,
leaveTotal, //ลาไปแล้ว(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น) filterOption,
leaveRemain, //คงเหลือโควต้า(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น) fetchProfile,
restDayTotalOld,
birthDate, //ส่งออกตัวแปร profileที่ได้จาก Api
dateAppoint, dateSendLeave,
salary, leaveTypeName,
salaryText, dear,
leaveLast, fullName,
restDayCurrentTotal, positionName,
convertStatud, positionLevelName,
} organizationName,
}) leaveLimit, //โควต้าลา(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
leaveTotal, //ลาไปแล้ว(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
leaveRemain, //คงเหลือโควต้า(แต่ละประเภท)หน่วยเป็นวัน(ภายในปีนั้น)
restDayTotalOld,
birthDate,
dateAppoint,
salary,
salaryText,
leaveLast,
restDayCurrentTotal,
convertStatud,
};
});