hrms-mgt/src/modules/07_insignia/storeBrrow.ts
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 0d5db9160e fix
2024-10-04 16:44:30 +07:00

173 lines
5.2 KiB
TypeScript

import { defineStore } from "pinia";
import { ref } from "vue";
/** import Type*/
import type {
OptionData,
OptionDataInsignia,
InsigniaType,
} from "@/modules/07_insignia/interface/index/Main";
/** import Stores */
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const mixin = useCounterMixin();
const { date2Thai } = mixin;
export const useBrrowDataStore = defineStore("insigniaBrrow", () => {
const insignia = ref<string>("");
const insigniaOp = ref<OptionDataInsignia[]>([
{ name: "ทั้งหมด", id: "", type: "" },
]);
const insigniaType = ref<InsigniaType[]>();
const rows = ref<any[]>([]);
const listInsignia = ref<any>([]);
const employeeClass = ref<string>("all");
const employeeClassOps = ref<OptionData[]>([
{ name: "ทั้งหมด", id: "all" },
{ name: "ข้าราชการ กทม.สามัญ", id: "officer" },
{ name: "ลูกจ้างประจำ", id: "perm" },
]);
const type = ref<any[]>([]);
/**
* function เรียกข้อมุลรายชื่อเครื่อง
* @param data ข้อมูลเครื่องราช
*/
async function fetchDataInsignia(data: any) {
insignia.value = "";
insigniaOp.value = [{ name: "ทั้งหมด", id: "", type: "" }];
data.forEach((e: any) => {
insigniaOp.value.push({
name: `${e.name} (${e.shortName})`,
id: e.id,
type: e.insigniaTypeId,
});
});
data.forEach((e: any) => {
type.value.push({
name: e.name,
shortName: e.shortName,
});
});
}
/**
* function เรียกข้อมูลขั้นเครื่องราช
* @param data ข้อมูลขั้นเครื่องราช
*/
async function fetchDatainsigniaType(data: any) {
insigniaType.value = data.map((e: any) => ({ name: e.id, label: e.name }));
}
/**
* function เรียกข้อมูล ยืม-คืนเครื่องราชฯ
* @param data ข้อมูล ยืม-คืนเครื่องราชฯ
*/
async function fetchlistinsignia(data: any) {
rows.value = [];
let list = await data.map((e: any) => ({
id: e.id,
citizenId: e.citizenId,
prefix: e.prefix,
position: e.position,
status: status(e.status),
name: e.fullName,
type: `${e.requestInsignia} (${
type.value.find((item) => item.name === e.requestInsignia)?.shortName ||
""
})`,
requestInsigniaId: e.requestInsigniaId,
employeeType: profileType(e.profileType),
profileType: e.profileType,
dateReceive: date2Thai(e.dateReceive),
date: date2Thai(e.date),
volumeNo: e.volumeNo,
section: e.section,
page: e.page,
number: e.no,
vatnumber: e.number,
datepay: date2Thai(e.datePayment),
typepay: e.typePayment,
address: e.address,
borrowOrganization: e.borrowOrganization,
borrowDate: e.borrowDate !== null ? date2Thai(e.borrowDate) : "-",
returnOrganization: e.returnOrganization,
returnDate: e.returnDate !== null ? date2Thai(e.returnDate) : "-",
returnReason: e.returnReason !== null ? e.returnReason : "-",
}));
rows.value = list;
listInsignia.value = list;
searchDatatable(insignia.value, employeeClass.value);
}
/**
* function ค้นหาข้อมูล Table
* @param type ประเภทเครื่องราช
* @param employeeClass สถานภาพ
*/
function searchDatatable(type: string, employeeClass: string) {
if (type !== "" && employeeClass !== "all") {
rows.value = listInsignia.value.filter(
(e: any) =>
e.requestInsigniaId == type && e.profileType == employeeClass
);
} else if (type !== "" && employeeClass == "all") {
rows.value = listInsignia.value.filter(
(e: any) => e.requestInsigniaId == type
);
} else if (type == "" && employeeClass !== "all") {
rows.value = listInsignia.value.filter(
(e: any) => e.profileType == employeeClass
);
} else if (type === "" && employeeClass === "all") {
rows.value = listInsignia.value;
}
}
/**
* function convert สถานะ
* @param val สถานะ
*/
const status = (val: string) => {
switch (val) {
case "PENDING":
return "รอบันทึกข้อมูล";
case "REJECT":
return "ยกเลิก";
case "DELETE":
return "ลบ";
case "DONE":
return "บันทึกลง ก.พ. 7 แล้ว";
}
};
/**
* function convert สถานภาพ
* @param val สถานภาพ
*/
function profileType(val: string) {
switch (val) {
case "officer":
return "ข้าราชการ กทม.สามัญ";
case "employee":
return "ลูกจ้างประจำ";
}
}
return {
rows,
listInsignia,
insignia,
insigniaOp,
insigniaType,
employeeClass,
employeeClassOps,
fetchDatainsigniaType,
fetchDataInsignia,
profileType,
fetchlistinsignia,
searchDatatable,
type,
};
});