import { defineStore } from "pinia"; import { ref, reactive, computed } from "vue"; import axios from "axios"; import http from "@/plugins/http"; import config from "@/app.config"; import { useRoute } from "vue-router"; import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main"; import type { DataType, DataLevel, } from "@/modules/04_registryPerson/interface/response/Main"; import type { FormFilter } from "@/modules/04_registryPerson/interface/request/Main"; export const useRegistryNewDataStore = defineStore("registryNew", () => { const route = useRoute(); const tab = ref("1"); const routerName = ref(); const searchTypeOption = computed(() => { return [ { id: "fullName", name: "ชื่อ-นามสกุล" }, { id: "citizenId", name: "เลขประจำตัวประชาชน" }, { id: "position", name: "ตำแหน่งในสายงาน" }, { id: "posNo", name: route.name === "registryNew" || route.name === "registryRetireOfficer" ? "เลขที่ตำแหน่ง" : "ตำแหน่งเลขที่", }, ]; }); const employeeClassOps = ref([ { id: "officer", name: "ข้าราชการ กทม.สามัญ" }, { id: "perm", name: "ลูกจ้างประจำ" }, // { id: "temp", name: "ลูกจ้างชั่วคราว" }, ]); const citizenId = ref(""); const posTypeOps = ref([]); const posTypeMain = ref([]); const posLevelOps = ref([]); const yearOps = ref([]); const mode = ref("table"); const isLeave = ref(false); const tabs = ref("Main"); const tabsManu = ref([ { name: "ข้อมูลส่วนตัว", id: "Main" }, { name: "ข้อมูลการพัฒนารายบุคคล (IDP)", id: "IDP" }, ]); function fetchType(data: DataType[]) { posTypeMain.value = data; const list: DataOption[] = data.map((e: DataType) => ({ id: e.id, name: e.posTypeName, })); posTypeOps.value = list; } function fetchLevel(data: DataLevel[], shortName: string = "") { const list: DataOption[] = data.map((e: DataLevel) => ({ id: e.id, name: shortName ? `${shortName} ${e.posLevelName}` : e.posLevelName, })); const seen = new Set(); posLevelOps.value = list.filter((item: DataOption) => { if (seen.has(item.name)) { return false; } else { seen.add(item.name); return true; } }); } const formFilter = reactive({ page: 1, pageSize: 12, keyword: "", type: "officer", posType: "", posLevel: "", retireYear: "", rangeYear: { min: 0, max: 60 }, isShowRetire: false, isProbation: false, isAll: true, nodeId: null, node: null, searchType: "fullName", retireType: null, dateAppoint: "", }); const labelOption = reactive({ type: "ข้าราชการ กทม.สามัญ", posType: "ทั้งหมด", posLevel: "ทั้งหมด", retireYear: "", node: "เลือกหน่วยงาน", retireType: "ทั้งหมด", sortName: "ลำดับการแสดงผล", }); function convertTypeRetired(val: string) { const newVal = val?.toLocaleUpperCase(); switch (newVal) { case "RETIRE": return "เกษียณ"; case "RETIRE_RESIGN": return "ลาออกจากราชการ"; case "RETIRE_DECEASED": return "ถึงแก่กรรม "; case "RETIRE_OUT": return "ให้ออกจากราชการ"; case "DISCIPLINE_RESULT_REMOVE": return "ปลดออกจากราชการ"; case "DISCIPLINE_RESULT_DISMISS": return "ไล่ออกจากราชการ"; case "DISCIPLINE_SUSPEND": return "ถูกพักจากราชการ"; case "PROBATION_REPORT": return "ผลการทดลองฯ ต่ำกว่ามาตรฐานที่กำหนด"; case "PLACEMENT_TRANSFER": return "โอนออก"; case "RETIRE_RESIGN_EMP": return "ลาออกจากราชการ"; case "RETIRE_OUT_EMP": return "ให้ออกจากราชการ"; case "DISCIPLINE_TEMP_SUSPEND": return "ให้ออกจากราชการไว้ก่อน"; default: return ""; } } const retireTypeOps = ref([ { id: "RETIRE", name: "เกษียณ" }, { id: "RETIRE_DECEASED", name: "ถึงแก่กรรม" }, { id: "RETIRE_RESIGN", name: "ลาออกจากราชการ" }, { id: "RETIRE_OUT", name: "ให้ออกจากราชการ" }, { id: "DISCIPLINE_RESULT_REMOVE", name: "ปลดออกจากราชการ" }, { id: "DISCIPLINE_RESULT_DISMISS", name: "ไล่ออกจากราชการ" }, { id: "DISCIPLINE_SUSPEND", name: "ถูกพักจากราชการ" }, { id: "PROBATION_REPORT", name: "ผลการทดลองฯ ต่ำกว่ามาตรฐานที่กำหนด" }, { id: "PLACEMENT_TRANSFER", name: "โอนออก" }, { id: "DISCIPLINE_TEMP_SUSPEND", name: "ให้ออกจากราชการไว้ก่อน" }, ]); const retireTypeEmpOps = ref([ { id: "RETIRE", name: "เกษียณ" }, { id: "RETIRE_DECEASED", name: "ถึงแก่กรรม" }, { id: "RETIRE_RESIGN_EMP", name: "ลาออกจากราชการ" }, { id: "RETIRE_OUT_EMP", name: "ให้ออกจากราชการ" }, ]); const displayOrderOps = ref([ { id: "DESC", name: "เรียงตามวันที่บรรจุแต่งตั้ง (ล่าสุด-เก่า)" }, { id: "ASC", name: "เรียงตามวันที่บรรจุแต่งตั้ง (เก่า-ล่าสุด)" }, ]); /** * ฟังก์ชันสร้าง Path อัพโหลดไฟล์ * @param group กลุ่มไฟล์ * @param profileId id * @param id subId * @returns Path อัพโหลดไฟล์ */ async function createPathUploadFlie( group: string, profileId: string, id: string ) { try { const res = await http.post( config.API.subFile("ทะเบียนประวัติ", group, profileId, id), { replace: true, fileList: [ { fileName: "เอกสารหลักฐาน", }, ], } ); return res.data["เอกสารหลักฐาน"].uploadUrl; } catch (err) { console.log(err); } } /** * ฟังก์ชันเรียก Path อัพโหลดไฟล์ * @param group กลุ่มไฟล์ * @param profileId id * @param id subId * @returns ข้อมูลไฟล์ */ async function getPathUploadFlie( group: string, profileId: string, id: string ) { try { const res = await http.get( config.API.subFileByFileName( "ทะเบียนประวัติ", group, profileId, id, "เอกสารหลักฐาน" ) ); return res.data; } catch (err) { console.log(err); } } /** * ฟังก์ชันอัพโหลดไฟล์ * @param uploadUrl Path อัพโหลดไฟล์ * @param file ไฟล์ */ async function uploadFile(uploadUrl: string, file: any) { try { await axios.put(uploadUrl, file, { headers: { "Content-Type": file.type, }, }); } catch (err) { console.log(err); } } return { fetchType, fetchLevel, posTypeMain, searchTypeOption, employeeClassOps, posTypeOps, posLevelOps, yearOps, mode, formFilter, labelOption, isLeave, tabs, tabsManu, convertTypeRetired, retireTypeOps, retireTypeEmpOps, citizenId, displayOrderOps, routerName, createPathUploadFlie, getPathUploadFlie, uploadFile, tab, }; });