194 lines
6.2 KiB
TypeScript
194 lines
6.2 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { reactive, ref } from "vue";
|
|
|
|
/** importType*/
|
|
import type {
|
|
DataActive,
|
|
SumPosition,
|
|
PosMaster,
|
|
} from "@/modules/02_organization/interface/response/organizational";
|
|
|
|
export const useOrganizational = defineStore("organizationalStore", () => {
|
|
const typeOrganizational = ref<string>("current"); // ประเภทโครงสร้าง
|
|
const statusView = ref<string>("list"); // การแสดงผล รายการ,map
|
|
|
|
const rootId = ref<string>("");
|
|
const isOfficer = ref<boolean | null>(null);
|
|
const isStaff = ref<boolean | null>(null);
|
|
const remark = ref<string>("");
|
|
|
|
const dataActive = ref<DataActive>(); //ข้อมูลโครงสร้าง
|
|
const activeId = ref<string>(); // id โครงสร้างปัจจุบัน
|
|
const draftId = ref<string>(); // id แบบร่างโครงสร้าง
|
|
const historyId = ref<string>(); // id ประวัติโครงสร้าง
|
|
const isPublic = ref<boolean>(false); // การเผยแพร่
|
|
const treeId = ref<string>(); // id โหนด
|
|
const level = ref<number>(); // ระดับโหนด
|
|
const orgPublishDate = ref<Date | null>(null); // วันเผยแพร่
|
|
const isLosck = ref<boolean>(false);
|
|
const sumPosition = reactive({
|
|
total: 0,
|
|
use: 0,
|
|
vacant: 0,
|
|
totalRoot: 0,
|
|
useRoot: 0,
|
|
vacantRoot: 0,
|
|
});
|
|
|
|
/**
|
|
* ฟังก์ชันกำหนดจำนวนข้อมูลตำแหน่ง
|
|
* @param data ข้อมุลจำนวนตำแหน่ง
|
|
*/
|
|
function getSumPosition(data: SumPosition) {
|
|
sumPosition.total = data.totalPosition;
|
|
sumPosition.totalRoot = data.totalRootPosition ? data.totalRootPosition : 0;
|
|
|
|
if (typeOrganizational.value == "draft") {
|
|
sumPosition.use = data.totalPositionNextUse;
|
|
sumPosition.useRoot = data.totalRootPositionNextUse
|
|
? data.totalRootPositionNextUse
|
|
: 0;
|
|
|
|
sumPosition.vacant = data.totalPositionNextVacant;
|
|
sumPosition.vacantRoot = data.totalRootPositionNextVacant
|
|
? data.totalRootPositionNextVacant
|
|
: 0;
|
|
} else {
|
|
sumPosition.use = data.totalPositionCurrentUse;
|
|
sumPosition.useRoot = data.totalRootPositionCurrentUse
|
|
? data.totalRootPositionCurrentUse
|
|
: 0;
|
|
|
|
sumPosition.vacant = data.totalPositionCurrentVacant;
|
|
sumPosition.vacantRoot = data.totalRootPositionCurrentVacant
|
|
? data.totalRootPositionCurrentVacant
|
|
: 0;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันกำหนดข้อมูลโครงสร้าง
|
|
* @param data ข้อมูลโครงสร้าง
|
|
*/
|
|
async function fetchDataActive(data: DataActive) {
|
|
dataActive.value = data;
|
|
activeId.value = data.activeId;
|
|
draftId.value = data.draftId;
|
|
isPublic.value = data.isPublic;
|
|
orgPublishDate.value = data.orgPublishDate;
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันประมวลผลข้อมูลตำแหน่ง
|
|
* @param data ข้อมูลตำแหน่ง
|
|
* @returns ข้อมูลตำแหน่งที่ผ่านการประมวลผลแล้ว
|
|
*/
|
|
function fetchPosMaster(data: PosMaster[]) {
|
|
const newPosMaster = data.map((e: PosMaster) => ({
|
|
...e,
|
|
positionIsSelected:
|
|
typeOrganizational.value === "draft" && e.fullNameNextHolder !== null
|
|
? e.fullNameNextHolder
|
|
: typeOrganizational.value !== "draft" &&
|
|
e.fullNameCurrentHolder !== null
|
|
? e.fullNameCurrentHolder
|
|
: "ว่าง",
|
|
posMasterNo:
|
|
e.orgShortname +
|
|
(e.posMasterNoPrefix ? e.posMasterNoPrefix : "") +
|
|
(e.posMasterNo ? e.posMasterNo : "") +
|
|
(e.posMasterNoSuffix ? e.posMasterNoSuffix : ""),
|
|
positionName: e.isSit ? e.profilePosition : e.positionName,
|
|
posTypeName: e.isSit ? e.profilePostype : e.posTypeName,
|
|
posLevelName: e.isSit ? e.profilePoslevel : e.posLevelName,
|
|
posExecutiveName: e.posExecutiveName,
|
|
isSit: e.isSit,
|
|
}));
|
|
|
|
return newPosMaster;
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันตรวจสอบและแปลงค่าประเภทระดับ
|
|
* @param type ประเภทระดับ
|
|
* @returns ชื่อประเภทระดับ
|
|
*/
|
|
async function checkLevel(type: number) {
|
|
switch (type) {
|
|
case 0:
|
|
return "Root";
|
|
case 1:
|
|
return "Child1";
|
|
case 2:
|
|
return "Child2";
|
|
case 3:
|
|
return "Child3";
|
|
default:
|
|
return "Child4";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันตรวจสอบและแปลงค่าระดับหน่วยงาน
|
|
* @param type ระดับหน่วยงาน
|
|
* @returns ชื่อประระดับหน่วยงาน
|
|
*/
|
|
function convertType(type: string) {
|
|
switch (type) {
|
|
case "DEPARTMENT":
|
|
return "ระดับสำนัก";
|
|
case "OFFICE":
|
|
return "ระดับกอง/สำนักงาน/ส่วนราชการ/โรงพยาบาล/เทียบเท่ากอง";
|
|
case "DIVISION":
|
|
return "ระดับส่วน/กลุ่มภารกิจ";
|
|
case "SECTION":
|
|
return "ระดับฝ่าย/กลุ่มงาน";
|
|
default:
|
|
return "-";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชันแปลงค่าสถานะรายละเอียดโครงสร้าง
|
|
* @param type สถานะ
|
|
* @returns ชือสถานะ
|
|
*/
|
|
function convertStatus(type: string) {
|
|
switch (type) {
|
|
case "current":
|
|
return "ปกติ";
|
|
case "draft":
|
|
return "แบบร่าง";
|
|
case "old":
|
|
return "ยุบเลิก";
|
|
default:
|
|
return "-";
|
|
}
|
|
}
|
|
|
|
return {
|
|
typeOrganizational,
|
|
statusView,
|
|
|
|
//
|
|
fetchDataActive,
|
|
checkLevel,
|
|
convertType,
|
|
draftId,
|
|
activeId,
|
|
historyId,
|
|
treeId,
|
|
level,
|
|
isPublic,
|
|
orgPublishDate,
|
|
fetchPosMaster,
|
|
sumPosition,
|
|
getSumPosition,
|
|
isOfficer,
|
|
isStaff,
|
|
rootId,
|
|
isLosck,
|
|
remark,
|
|
convertStatus,
|
|
};
|
|
});
|