hrms-mgt/src/modules/04_registryPerson/store.ts

266 lines
8.5 KiB
TypeScript
Raw Normal View History

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";
2024-08-01 12:12:28 +07:00
import type { DataOption } from "@/modules/04_registryPerson/interface/index/Main";
import type {
DataType,
DataLevel,
2024-08-01 12:12:28 +07:00
} 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();
2025-05-02 13:52:17 +07:00
const tab = ref<string>("1");
const routerName = ref<any>();
const searchTypeOption = computed<DataOption[]>(() => {
return [
{ id: "fullName", name: "ชื่อ-นามสกุล" },
{ id: "citizenId", name: "เลขประจำตัวประชาชน" },
{ id: "position", name: "ตำแหน่งในสายงาน" },
{
id: "posNo",
name:
route.name === "registryNew" ||
route.name === "registryRetireOfficer"
? "เลขที่ตำแหน่ง"
: "ตำแหน่งเลขที่",
},
];
});
const employeeClassOps = ref<DataOption[]>([
{ id: "officer", name: "ข้าราชการ กทม.สามัญ" },
{ id: "perm", name: "ลูกจ้างประจำ" },
// { id: "temp", name: "ลูกจ้างชั่วคราว" },
]);
2025-02-19 13:10:35 +07:00
const citizenId = ref<string>("");
const posTypeOps = ref<DataOption[]>([]);
const posTypeMain = ref<DataType[]>([]);
const posLevelOps = ref<DataOption[]>([]);
const yearOps = ref<DataOption[]>([]);
2024-06-24 17:54:53 +07:00
const mode = ref<string>("table");
2024-10-29 14:41:01 +07:00
const isLeave = ref<boolean>(false);
const tabs = ref<string>("Main");
const tabsManu = ref<DataOption[]>([
{ name: "ข้อมูลส่วนตัว", id: "Main" },
{ name: "ข้อมูลการพัฒนารายบุคคล (IDP)", id: "IDP" },
]);
function fetchType(data: DataType[]) {
posTypeMain.value = data;
2024-11-22 18:04:12 +07:00
const list: DataOption[] = data.map((e: DataType) => ({
id: e.id,
name: e.posTypeName,
}));
posTypeOps.value = list;
}
2024-11-22 18:04:12 +07:00
function fetchLevel(data: DataLevel[], shortName: string = "") {
const list: DataOption[] = data.map((e: DataLevel) => ({
id: e.id,
2024-11-29 10:11:38 +07:00
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<FormFilter>({
page: 1,
pageSize: 12,
keyword: "",
type: "officer",
posType: "",
posLevel: "",
retireYear: "",
rangeYear: { min: 0, max: 60 },
isShowRetire: false,
isProbation: false,
2024-09-04 12:21:51 +07:00
isAll: true,
2024-09-04 14:37:39 +07:00
nodeId: null,
node: null,
2024-09-05 10:07:52 +07:00
searchType: "fullName",
retireType: null,
2025-02-19 13:10:35 +07:00
dateAppoint: "",
});
const labelOption = reactive({
type: "ข้าราชการ กทม.สามัญ",
posType: "ทั้งหมด",
posLevel: "ทั้งหมด",
retireYear: "",
node: "เลือกหน่วยงาน",
retireType: "ทั้งหมด",
sortName: "ลำดับการแสดงผล",
});
function convertTypeRetired(val: string) {
const newVal = val?.toLocaleUpperCase();
switch (newVal) {
case "RETIRE":
2025-02-20 17:31:15 +07:00
return "เกษียณ";
case "RETIRE_RESIGN":
2025-02-20 17:31:15 +07:00
return "ลาออกจากราชการ";
case "RETIRE_DECEASED":
return "ถึงแก่กรรม ";
case "RETIRE_OUT":
2025-02-20 17:31:15 +07:00
return "ให้ออกจากราชการ";
case "DISCIPLINE_RESULT_REMOVE":
2025-02-20 17:31:15 +07:00
return "ปลดออกจากราชการ";
case "DISCIPLINE_RESULT_DISMISS":
2025-02-20 17:31:15 +07:00
return "ไล่ออกจากราชการ";
case "DISCIPLINE_SUSPEND":
2025-02-20 17:31:15 +07:00
return "ถูกพักจากราชการ";
case "PROBATION_REPORT":
2025-02-20 17:31:15 +07:00
return "ผลการทดลองฯ ต่ำกว่ามาตรฐานที่กำหนด";
case "PLACEMENT_TRANSFER":
2025-02-20 17:31:15 +07:00
return "โอนออก";
case "RETIRE_RESIGN_EMP":
2025-02-20 17:31:15 +07:00
return "ลาออกจากราชการ";
2025-02-20 16:30:52 +07:00
case "RETIRE_OUT_EMP":
2025-02-20 17:31:15 +07:00
return "ให้ออกจากราชการ";
case "DISCIPLINE_TEMP_SUSPEND":
return "ให้ออกจากราชการไว้ก่อน";
default:
return "";
}
}
const retireTypeOps = ref<DataOption[]>([
{ id: "RETIRE", name: "เกษียณ" },
{ id: "RETIRE_DECEASED", name: "ถึงแก่กรรม" },
2025-02-20 17:31:15 +07:00
{ id: "RETIRE_RESIGN", name: "ลาออกจากราชการ" },
{ id: "RETIRE_OUT", name: "ให้ออกจากราชการ" },
{ id: "DISCIPLINE_RESULT_REMOVE", name: "ปลดออกจากราชการ" },
{ id: "DISCIPLINE_RESULT_DISMISS", name: "ไล่ออกจากราชการ" },
{ id: "DISCIPLINE_SUSPEND", name: "ถูกพักจากราชการ" },
2025-02-20 17:31:15 +07:00
{ id: "PROBATION_REPORT", name: "ผลการทดลองฯ ต่ำกว่ามาตรฐานที่กำหนด" },
{ id: "PLACEMENT_TRANSFER", name: "โอนออก" },
{ id: "DISCIPLINE_TEMP_SUSPEND", name: "ให้ออกจากราชการไว้ก่อน" },
]);
const retireTypeEmpOps = ref<DataOption[]>([
{ id: "RETIRE", name: "เกษียณ" },
{ id: "RETIRE_DECEASED", name: "ถึงแก่กรรม" },
2025-02-20 17:31:15 +07:00
{ id: "RETIRE_RESIGN_EMP", name: "ลาออกจากราชการ" },
2025-02-20 16:30:52 +07:00
{ id: "RETIRE_OUT_EMP", name: "ให้ออกจากราชการ" },
]);
2025-02-19 13:10:35 +07:00
const displayOrderOps = ref<DataOption[]>([
2025-02-19 17:39:45 +07:00
{ id: "DESC", name: "เรียงตามวันที่บรรจุแต่งตั้ง (ล่าสุด-เก่า)" },
{ id: "ASC", name: "เรียงตามวันที่บรรจุแต่งตั้ง (เก่า-ล่าสุด)" },
2025-02-19 13:10:35 +07:00
]);
/**
* 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) {
2025-06-05 15:11:23 +07:00
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) {
2025-06-05 15:11:23 +07:00
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) {
2025-06-05 15:11:23 +07:00
console.log(err);
}
}
return {
fetchType,
fetchLevel,
posTypeMain,
searchTypeOption,
employeeClassOps,
posTypeOps,
posLevelOps,
yearOps,
mode,
formFilter,
labelOption,
2024-10-29 14:41:01 +07:00
isLeave,
tabs,
tabsManu,
convertTypeRetired,
retireTypeOps,
retireTypeEmpOps,
2025-02-19 13:10:35 +07:00
citizenId,
displayOrderOps,
routerName,
createPathUploadFlie,
getPathUploadFlie,
uploadFile,
2025-06-05 15:11:23 +07:00
tab,
};
});