import { defineStore } from "pinia"; import { ref } from "vue"; /**import Type */ import type { OptionReport, OptionData, DataManageList, OptionRound, } from "@/modules/07_insignia/interface/index/Main"; import type { ResponseManageList, ResponseInsigniaType, ResponseDataInsignia, } from "@/modules/07_insignia/interface/response/Main"; /**import Stores */ import { useCounterMixin } from "@/stores/mixin"; /**use Stroe */ const mixin = useCounterMixin(); const { date2Thai } = mixin; export const useInsigniaDataStore = defineStore("insignia", () => { const roundId = ref(""); const optionRound = ref([]); const isLock = ref(false); const roleUser = ref(""); const requestId = ref(""); const requestStatus = ref(""); const optionsTypeOc = ref([]); const typeOc = ref(""); const agency = ref(""); const rows = ref([]); const listinsignia = ref([]); const typeinsignia = ref("all"); const typeinsigniaOptions = ref([ { id: "all", name: "ทั้งหมด" }, ]); const employeeClass = ref("all"); const employeeClassOps = ref([ { name: "ทั้งหมด", id: "all" }, { name: "ข้าราชการ กทม.สามัญ", id: "officer" }, { name: "ลูกจ้างประจำ", id: "perm" }, ]); const isOfficer = ref(false); const isStaff = ref(false); const isDirector = ref(false); /** option รายงาน */ const optionReport = ref([ { id: "45", title: "บัญชีรายชื่อข้าราชการผู้ขอพระราชทานเครื่องราชอิสริยาภรณ์", }, { id: "43", title: "บัญชีระดับผลการประเมินผลการปฏิบัติราชการในรอบ 5 ปี" }, { id: "44", title: "บัญชีแสดงจำนวนชั้นตราเครื่องราชฯ" }, ]); const mainTab = ref("pending"); const dataInsigniaType = ref([]); /** * Funtioin เรียกข้อมูลรายชื่อข้าราชการสามัญ * @param data ข้อมูลรายชื่อข้าราชการสามัญ */ async function fetchData(data: ResponseManageList[]) { if (data !== null) { let datalist = data.map((e: ResponseManageList) => ({ id: e.id, citizenId: e.citizenId, profileId: e.profileId, name: e.fullName, position: e.position, level: e.rank, salary: e.salary, salary2: Number(e.salary).toLocaleString(), insigniaType: e.lastInsignia ? `${e.lastInsignia} (${ dataInsigniaType.value.find( (item: ResponseInsigniaType) => item.name === e.lastInsignia )?.shortName || "" })` : "-", insigniaCheck: e.requestInsignia, insigniaSend: e.requestInsignia ? `${e.requestInsignia} (${ dataInsigniaType.value.find( (item: ResponseInsigniaType) => item.name === e.requestInsignia )?.shortName || "" })` : "", insigniaLevel: e.level ? e.level : "", dateSend: e.requestDate ? date2Thai(e.requestDate) : null, requestNote: e.requestNote ? e.requestNote : "", employeeType: profileType(e.profileType) || null, reason: e.reason ? e.reason : "", markDiscipline: e.markDiscipline, markLeave: e.markLeave, markRate: e.markRate, isApprove: e.isApprove, statusMark: e.markDiscipline === true || e.markLeave === true || e.markRate === true ? true : false, })); const item = datalist; for (let j = 0; j < item.length; j++) { const data = item[j]; const filteredData = dataInsigniaType.value.find( (item: ResponseInsigniaType) => item.name === data.insigniaType ); if (filteredData) { data.insigniaType = `${data.insigniaType} (${filteredData.shortName})`; } else { data.insigniaType = data.insigniaType; } } rows.value = datalist; listinsignia.value = item; searchDataTable(typeinsignia.value, employeeClass.value); filtertypeInsignia(); } else rows.value = []; } /** * function เรียกข้อมูลรอบการเสนอขอ * @param data ข้อมูลราบการเสนอขอ */ async function fetchDataInsignia(data: ResponseDataInsignia) { isLock.value = data.isLock; // สถานะล็อกข้อมูล requestId.value = data.requestId; requestStatus.value = data.requestStatus; // สถานะของรอบการเสนอขอ } /** * funntoin หา option หน่วยงสานทั้งหมด * @param op */ async function fetchOption(op: OptionData[]) { const aId = agency.value ?? "00000000-0000-0000-0000-000000000000"; const hasID = op.find((e: OptionData) => e.id === agency.value); if (aId !== "00000000-0000-0000-0000-000000000000" && hasID) { typeOc.value = agency.value; optionsTypeOc.value = op; } else { (optionsTypeOc.value = op), (typeOc.value = op[0].id.toString()); } } /** * funcion หาประเภทเครื่องราชทั้งหมดที่อยู่ในรายชื่อข้าราชการสามัญฯ */ async function filtertypeInsignia() { typeinsignia.value = "all"; if (listinsignia.value.length !== 0) { // หาประเภทเครื่องราชที่ขอที่ชื่อซ้ำกัน const double_name = [ ...new Set( listinsignia.value.map((item: DataManageList) => item.insigniaCheck) ), ]; typeinsigniaOptions.value = [{ id: "all", name: "ทั้งหมด" }]; for (let i = 1; i <= double_name.length; i++) { const type = double_name[i - 1]; const filterShortName = dataInsigniaType.value.find( (item: ResponseInsigniaType) => item.name === type ); const listtype = { id: type ? type.toString() : "", name: `${type} (${filterShortName ? filterShortName.shortName : ""})`, }; typeinsigniaOptions.value.push(listtype); } } else typeinsigniaOptions.value = [{ id: "all", name: "ทั้งหมด" }]; } /** * function ค้นหาข้อมมูลรายชื่อ ตาม ประเภทและสถานภาพ * @param type ประเภท * @param employeeClasstype สถานภาพ */ async function searchDataTable(type: string, employeeClasstype: string) { typeinsignia.value = type; employeeClass.value = employeeClasstype; if (type !== "all" && employeeClasstype !== "all") { rows.value = listinsignia.value.filter( (e: DataManageList) => e.insigniaCheck === type && e.employeeType === profileType(employeeClasstype) ); } else if (type !== "all" && employeeClasstype === "all") { rows.value = listinsignia.value.filter( (e: DataManageList) => e.insigniaCheck === type ); } else if (type === "all" && employeeClasstype !== "all") { rows.value = listinsignia.value.filter( (e: DataManageList) => e.employeeType === profileType(employeeClasstype) ); } else if (type === "all" && employeeClasstype === "all") { rows.value = listinsignia.value; } } /** * function เรียกประเภทเครื่องราช * @param data ประเภทเครื่องราชทั้งหมด */ function fetchInsigniaType(data: ResponseInsigniaType[]) { dataInsigniaType.value = data; } /** * Function convert ประเภทลูกจ้าง * @param val ประเภทลูกจ้าง */ function profileType(val: string) { switch (val) { case "officer": return "ข้าราชการ กทม.สามัญ"; case "employee": return "ลูกจ้างประจำ"; case "perm": return "ลูกจ้างประจำ"; case "temp": return "ลูกจ้างประจำ"; } } /** * function convert สถานะ * @param val สถานะ */ function convertStatus(val: string) { switch (val) { case "WAITTING": return "สร้างรอบ"; case "PENDING": return "กำลังดำเนินการ"; case "DONE": return "เสร็จสิ้น"; } } return { roundId, optionRound, optionsTypeOc, mainTab, typeOc, rows, typeinsigniaOptions, typeinsignia, agency, fetchData, fetchOption, searchDataTable, employeeClass, employeeClassOps, fetchDataInsignia, fetchInsigniaType, isLock, requestId, roleUser, requestStatus, optionReport, convertStatus, dataInsigniaType, isStaff, isOfficer, isDirector, }; });