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(""); const insigniaOp = ref([ { name: "ทั้งหมด", id: "", type: "" }, ]); const insigniaType = ref(); const rows = ref([]); const listInsignia = ref([]); const employeeClass = ref("all"); const employeeClassOps = ref([ { name: "ทั้งหมด", id: "all" }, { name: "ข้าราชการ กทม.สามัญ", id: "officer" }, { name: "ลูกจ้างประจำ", id: "employee" }, ]); const type = ref([]); /** * 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 ? e.citizenId : "-", prefix: e.prefix ? e.prefix : "", position: e.position ? e.position : "-", status: e.status ? status(e.status) : "-", name: e.fullName ? e.fullName : "-", type: `${e.requestInsignia} (${ type.value.find((item) => item.name === e.requestInsignia)?.shortName || "-" })`, requestInsigniaId: e.requestInsigniaId ? e.requestInsigniaId : "-", employeeType: e.profileType ? profileType(e.profileType) : "-", profileType: e.profileType ? e.profileType : "-", dateReceive: e.dateReceive ? date2Thai(e.dateReceive) : "-", date: e.date ? date2Thai(e.date) : "-", volumeNo: e.volumeNo ? e.volumeNo : "-", section: e.section ? e.section : "-", page: e.page ? e.page : "-", number: e.no ? e.no : "-", vatnumber: e.number ? e.number : "-", datepay: e.datePayment ? date2Thai(e.datePayment) : "-", typepay: e.typePayment ? e.typePayment : "-", address: e.address ? e.address : "-", borrowOrganization: e.borrowOrganization ? e.borrowOrganization : "-", borrowDate: e.borrowDate !== null ? date2Thai(e.borrowDate) : "-", returnOrganization: e.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) { const newVal = val.toLocaleLowerCase(); switch (newVal) { case "officer": return "ข้าราชการ กทม.สามัญ"; case "employee": return "ลูกจ้างประจำ"; default: return "-"; } } return { rows, listInsignia, insignia, insigniaOp, insigniaType, employeeClass, employeeClassOps, fetchDatainsigniaType, fetchDataInsignia, profileType, fetchlistinsignia, searchDatatable, type, }; });