264 lines
8.6 KiB
TypeScript
264 lines
8.6 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref, reactive, computed } from "vue";
|
|
import { useQuasar } from "quasar";
|
|
import axios from "axios";
|
|
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
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";
|
|
|
|
const $q = useQuasar();
|
|
const { messageError } = useCounterMixin();
|
|
|
|
export const useRegistryNewDataStore = defineStore("registryNew", () => {
|
|
const route = useRoute();
|
|
const routerName = ref<any>();
|
|
const searchTypeOption = computed<DataOption[]>(() => {
|
|
return [
|
|
{ id: "fullName", name: "ชื่อ-นามสกุล" },
|
|
{ id: "citizenId", name: "เลขประจำตัวประชาชน" },
|
|
{ id: "position", name: "ตำแหน่งในสายงาน" },
|
|
{
|
|
id: "posNo",
|
|
name: route.name === "registryNew" ? "เลขที่ตำแหน่ง" : "ตำแหน่งเลขที่",
|
|
},
|
|
];
|
|
});
|
|
const employeeClassOps = ref<DataOption[]>([
|
|
{ id: "officer", name: "ข้าราชการ กทม.สามัญ" },
|
|
{ id: "perm", name: "ลูกจ้างประจำ" },
|
|
// { id: "temp", name: "ลูกจ้างชั่วคราว" },
|
|
]);
|
|
const citizenId = ref<string>("");
|
|
const posTypeOps = ref<DataOption[]>([]);
|
|
const posTypeMain = ref<DataType[]>([]);
|
|
const posLevelOps = ref<DataOption[]>([]);
|
|
const yearOps = ref<DataOption[]>([]);
|
|
const mode = ref<string>("table");
|
|
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;
|
|
|
|
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<FormFilter>({
|
|
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<DataOption[]>([
|
|
{ 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<DataOption[]>([
|
|
{ id: "RETIRE", name: "เกษียณ" },
|
|
{ id: "RETIRE_DECEASED", name: "ถึงแก่กรรม" },
|
|
{ id: "RETIRE_RESIGN_EMP", name: "ลาออกจากราชการ" },
|
|
{ id: "RETIRE_OUT_EMP", name: "ให้ออกจากราชการ" },
|
|
]);
|
|
|
|
const displayOrderOps = ref<DataOption[]>([
|
|
{ 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) {
|
|
messageError($q, 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) {
|
|
messageError($q, 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) {
|
|
messageError($q, 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,
|
|
};
|
|
});
|