Refactoring code module 06_retirement

This commit is contained in:
STW_TTTY\stwtt 2024-09-18 15:18:57 +07:00
parent 1225254062
commit ea921b39b0
29 changed files with 730 additions and 823 deletions

View file

@ -1,15 +1,17 @@
<script setup lang="ts">
import axios from "axios";
import { useRouter, useRoute } from "vue-router";
import { useQuasar, QForm } from "quasar";
import { ref, onMounted } from "vue";
import DialogFooter from "@/modules/05_placement/components/PersonalList/DialogFooter.vue";
import DialogHeader from "@/components/DialogHeader.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useRetirementDataStore } from "@/modules/06_retirement/store";
import http from "@/plugins/http";
import config from "@/app.config";
import axios from "axios";
import genReport from "@/plugins/genreport";
import { tokenParsed } from "@/plugins/auth";
import { useCounterMixin } from "@/stores/mixin";
import DialogFooter from "@/modules/05_placement/components/PersonalList/DialogFooter.vue";
import DialogHeader from "@/components/DialogHeader.vue";
import type {
TypeFile,
@ -18,23 +20,17 @@ import type {
CheckBoxType,
} from "@/modules/06_retirement/interface/response/Main";
import type { QTableProps } from "quasar";
import PopupPersonal from "@/components/Dialogs/PopupPersonal.vue";
import type { DataProfile } from "@/modules/05_placement/interface/index/Main";
/** importComponents*/
import PopupPersonal from "@/components/Dialogs/PopupPersonal.vue";
import CardProfile from "@/components/CardProfile.vue";
import genReport from "@/plugins/genreport";
const modalPersonal = ref<boolean>(false);
const personId = ref<string>("");
/** Use */
const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const checkRoutePermisson = ref<boolean>(route.name == "resignDetailbyid");
const mixin = useCounterMixin();
const RetirementData = useRetirementDataStore();
const {
messageError,
date2Thai,
@ -45,9 +41,10 @@ const {
dialogConfirm,
dialogRemove,
} = mixin;
const { statusText } = RetirementData;
/** ตัวแปร */
const modalPersonal = ref<boolean>(false);
const personId = ref<string>("");
const roleUser = ref<string>("");
const dataProfile = ref<DataProfile>();
@ -78,6 +75,7 @@ const dataDetail = ref<any>({
statustext: "",
fullname: "",
});
const organizationPositionOld = ref<string>("");
const positionTypeOld = ref<string>("");
const positionLevelOld = ref<string>("");
@ -135,33 +133,16 @@ const fileList = ref<FileList[]>([]);
const isNoDebt = ref<boolean>(false);
const isNoBurden = ref<boolean>(false);
const isDiscipline = ref<boolean>(false);
const checkboxGroup = ref<CheckBoxType[]>([]);
const checkboxOp = ref<CheckBoxType[]>([
{ label: "ไม่เป็นหนี้สหกรณ์", value: "debt" },
//
const rowsFileDownload = ref<rowFile[]>([
{
fileName: "แบบฟอร์มหนังสือขอลาออกจากราชการ",
pathName: "",
},
]);
/** Hook */
onMounted(async () => {
fetchData(id.value);
fetchFile();
const user = await tokenParsed();
if (user) {
const commander = await user.role.includes("commander");
const oligarch = await user.role.includes("oligarch");
const officer = await user.role.includes("officer");
if (commander) {
roleUser.value = "commander";
} else if (oligarch) {
roleUser.value = "oligarch";
} else if (officer) {
roleUser.value = "officer";
} else {
roleUser.value = "admin";
}
}
});
const diffDate = () => {
function diffDate() {
if (date.value !== null && dateLeave.value !== null) {
const time = dateLeave.value.getTime() - date.value.getTime();
// -
@ -172,10 +153,10 @@ const diffDate = () => {
return false;
}
return false;
};
}
/** นำข้อมูลมาจาก API*/
const fetchData = async (id: string) => {
async function fetchData(id: string) {
showLoader();
await http
.get(config.API.resingByid(id))
@ -216,18 +197,18 @@ const fetchData = async (id: string) => {
.finally(() => {
hideLoader();
});
};
}
/**Pop up */
const popUp = (action: "pass" | "passNot") => {
function popUp(action: "pass" | "passNot") {
reasonReign.value = "";
dateBreak.value = null;
actionPass.value = action === "pass";
openModal();
};
}
//pop up
const conditionPopup = () => {
function conditionPopup() {
if (myFormConfirm.value !== null) {
myFormConfirm.value.validate().then(async (check) => {
if (check) {
@ -239,10 +220,10 @@ const conditionPopup = () => {
}
});
}
};
}
//pop up
const confirmpopUp = async () => {
async function confirmpopUp() {
dialogConfirm(
$q,
async () => {
@ -265,10 +246,10 @@ const confirmpopUp = async () => {
"ยืนยันการอนุญาต",
"ต้องการยืนยันการอนุญาตการลานี้หรือไม่ ?"
);
};
}
//pop up
const rejectpopUp = async () => {
async function rejectpopUp() {
dialogConfirm(
$q,
async () => {
@ -292,26 +273,26 @@ const rejectpopUp = async () => {
"ยืนยันการยับยั้ง",
"ต้องการยืนยันการยับยั้งนี้หรือไม่ ?"
);
};
}
/**
* กดยกเล
*/
const clickCancel = async () => {
async function clickCancel() {
await fetchData(id.value);
edit.value = false;
myForm.value?.resetValidation();
};
}
/**
* กดยกเล
*/
const clickCancelConditions = async () => {
async function clickCancelConditions() {
await fetchData(id.value);
conditions.value = false;
};
}
/** Function บันทึก รายการตรวจสอบเงื่อนไขต่าง ๆ*/
const onSubmitConditions = () => {
function onSubmitConditions() {
dialogConfirm($q, () => {
showLoader();
http
@ -332,10 +313,10 @@ const onSubmitConditions = () => {
hideLoader();
});
});
};
}
/** Function บันทึก ,แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย*/
const onSubmitAttached = () => {
function onSubmitAttached() {
dialogConfirm($q, () => {
const formData = new FormData();
const send = date.value !== null ? new Date(date.value).toUTCString() : "";
@ -366,39 +347,31 @@ const onSubmitAttached = () => {
await hideLoader();
});
});
};
}
/**
* Function เพ Class เวลา Edit
* @param val เมอเปนEdit จะเปลยน Class
*/
const getClass = (val: boolean) => {
function getClass(val: boolean) {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
};
}
/** แปลง StatusOrder */
const statusOrder = (val: boolean) => {
function statusOrder(val: boolean) {
switch (val) {
case true:
return "ยับยั้ง";
case false:
return "อนุญาต";
}
};
//
const rowsFileDownload = ref<rowFile[]>([
{
fileName: "แบบฟอร์มหนังสือขอลาออกจากราชการ",
pathName: "",
},
]);
}
//
const fileDownload = async (type: string, fileName: string) => {
async function fileDownload(type: string, fileName: string) {
showLoader();
await http
.get(config.API.reportResignList(type, id.value))
@ -412,18 +385,7 @@ const fileDownload = async (type: string, fileName: string) => {
hideLoader();
})
.finally(() => {});
};
//
const downloadFile = (response: any, filename: string) => {
const link = document.createElement("a");
var fileName = filename;
link.href = window.URL.createObjectURL(new Blob([response.data]));
link.setAttribute("download", fileName);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
}
function updatemodalPersonal(modal: boolean) {
modalPersonal.value = modal;
@ -541,6 +503,27 @@ function removeFile(fileName: string) {
});
});
}
/** Hook */
onMounted(async () => {
fetchData(id.value);
fetchFile();
const user = await tokenParsed();
if (user) {
const commander = await user.role.includes("commander");
const oligarch = await user.role.includes("oligarch");
const officer = await user.role.includes("officer");
if (commander) {
roleUser.value = "commander";
} else if (oligarch) {
roleUser.value = "oligarch";
} else if (officer) {
roleUser.value = "officer";
} else {
roleUser.value = "admin";
}
}
});
</script>
<template>