diff --git a/src/api/06_retirement/api.retirement.ts b/src/api/06_retirement/api.retirement.ts index 7d1b8731d..756927995 100644 --- a/src/api/06_retirement/api.retirement.ts +++ b/src/api/06_retirement/api.retirement.ts @@ -27,14 +27,20 @@ export default { listResign: () => `${retirement}/resign`, resignReport: `${retirement}/resign/report`, resingByid: (id: string) => `${retirement}/resign/${id}`, - resignConfirm: (role: String, id: string) => `${retirement}/resign/${role}/confirm/${id}`, - resignReject: (role: String, id: string) => `${retirement}/resign/${role}/reject/${id}`, + resignConfirm: (role: String, id: string) => + `${retirement}/resign/${role}/confirm/${id}`, + resignReject: (role: String, id: string) => + `${retirement}/resign/${role}/reject/${id}`, listExitInterview: () => `${retirement}/resign/questionnaire`, - commentExitInterview: (id:string) => `${retirement}/resign/questionnaire/comment/${id}`, + commentExitInterview: (id: string) => + `${retirement}/resign/questionnaire/comment/${id}`, questionExitInterview: () => `${retirement}/resign/questionnaire/question`, ExitInterviewByid: (id: string) => `${retirement}/resign/questionnaire/${id}`, ExitInterviewReport: `${retirement}/resign/questionnaire/report`, - AppointInterview: (id: string) => `${retirement}/resign/questionnaire/appoint/${id}`, + AppointInterview: (id: string) => + `${retirement}/resign/questionnaire/appoint/${id}`, + resignConditions: (id: string) => `${retirement}/resign/debt/${id}`, + // ปลดออก retirementDischarge, listDischarge: () => `${retirement}/discharge`, @@ -58,8 +64,5 @@ export default { editDetail: (retireId: string) => `${retirement}/detail/${retireId}`, // ตำถาม Exit interview - questionnaireList: () => `${retirement}/resign/questionnaire/question` - - - + questionnaireList: () => `${retirement}/resign/questionnaire/question`, }; diff --git a/src/modules/06_retirement/components/resign/ResignByid.vue b/src/modules/06_retirement/components/resign/ResignByid.vue index 1b0720fdc..46cfa8e53 100644 --- a/src/modules/06_retirement/components/resign/ResignByid.vue +++ b/src/modules/06_retirement/components/resign/ResignByid.vue @@ -9,6 +9,8 @@ import { useRetirementDataStore } from "@/modules/06_retirement/store"; import CurrencyInput from "@/components/CurruncyInput.vue"; import http from "@/plugins/http"; import config from "@/app.config"; +import axios from "axios"; + import keycloak from "@/plugins/keycloak"; import type { TypeFile, @@ -23,7 +25,6 @@ import type { DataProfile } from "@/modules/05_placement/interface/index/Main"; /** importComponents*/ import CardProfile from "@/components/CardProfile.vue"; -const avatar = ref(""); const modalPersonal = ref(false); const personId = ref(""); /** Use */ @@ -38,7 +39,7 @@ const { showLoader, hideLoader, success, - dialogMessage, + dialogConfirm, dialogRemove, } = mixin; @@ -133,16 +134,21 @@ const checkboxGroup = ref([]); const checkboxOp = ref([ { label: "ไม่เป็นหนี้สหกรณ์", value: "debt" }, ]); + /** Hook */ onMounted(async () => { fetchData(id.value); + fetchFile(); if (keycloak.tokenParsed !== undefined) { const commander = await keycloak.tokenParsed.role.includes("commander"); const oligarch = await keycloak.tokenParsed.role.includes("oligarch"); + const officer = await keycloak.tokenParsed.role.includes("officer"); if (commander) { roleUser.value = "commander"; } else if (oligarch) { roleUser.value = "oligarch"; + } else if (officer) { + roleUser.value = "officer"; } else { roleUser.value = "admin"; } @@ -154,7 +160,6 @@ const diffDate = () => { const time = dateLeave.value.getTime() - date.value.getTime(); //วันที่ขอลาออกจากราชการ - วันที่ยื่นขอลาออกจากราชการ const day = time / (1000 * 3600 * 24); - if (day < 30) { return true; } @@ -163,9 +168,7 @@ const diffDate = () => { return false; }; -/** - * นำข้อมูลมาจาก API - */ +/** นำข้อมูลมาจาก API*/ const fetchData = async (id: string) => { showLoader(); await http @@ -196,7 +199,6 @@ const fetchData = async (id: string) => { location.value = data.location ?? ""; status.value = data.status ?? ""; remarkHorizontal.value = data.remarkHorizontal ?? "-"; - // getAvatar(data.profileId); }) .catch((e) => { messageError($q, e); @@ -206,30 +208,6 @@ const fetchData = async (id: string) => { }); }; -// function getAvatar(id: string) { -// if (id) { -// http -// .get(config.API.profileAvaId(id)) -// .then((res) => { -// console.log(res); -// const dataList = res.data.result; -// avatar.value = dataList.avatar; -// }) -// .catch((e) => {}) -// .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); -// }; - /**Pop up */ const popUp = (action: "pass" | "passNot") => { reasonReign.value = ""; @@ -237,6 +215,7 @@ const popUp = (action: "pass" | "passNot") => { actionPass.value = action === "pass"; openModal(); }; + //เงื่อนไขpop up const conditionPopup = () => { if (myFormConfirm.value !== null) { @@ -311,6 +290,7 @@ const rejectpopUp = async () => { const clickCancel = async () => { await fetchData(id.value); edit.value = false; + myForm.value?.resetValidation(); }; /** * กดยกเลิก @@ -320,86 +300,60 @@ const clickCancelConditions = async () => { conditions.value = false; }; -const saveConditions = () => { - if (myForm.value !== null) { - myForm.value.validate().then((success) => { - if (success) { - dialogConfirm($q, () => { - dataSave(); - }); - // dialogMessage( - // $q, - // "ต้องการแก้ไขข้อมูลหรือไม่?", - // "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย", - // "mdi-help-circle-outline", - // "ตกลง", - // "public", - // async () => await dataSave(), - // undefined - // ); - } - }); - } +/** Function บันทึก รายการตรวจสอบเงื่อนไขต่าง ๆ*/ +const onSubmitConditions = () => { + dialogConfirm($q, () => { + showLoader(); + http + .put(config.API.resignConditions(id.value), { + IsNoDebt: checkboxGroup.value[0] ? true : false, + }) + .then(() => { + fetchData(id.value); + success($q, "บันทึกเงื่อนไขต่าง ๆ สำเร็จ"); + conditions.value = false; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); + }); }; -//Save จาก Api -const dataSave = async () => {}; - -/** - * Functionบันทึก - */ -const conditionSave = () => { - if (myForm.value !== null) { - myForm.value.validate().then((success) => { - if (success) { - dialogConfirm($q, () => { - saveData(); - }); - // dialogMessage( - // $q, - // "ต้องการแก้ไขข้อมูลหรือไม่?", - // "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย", - // "mdi-help-circle-outline", - // "ตกลง", - // "public", - // async () => , - // undefined - // ); - } - }); - } -}; - -//Save จาก Api -const saveData = async () => { - const formData = new FormData(); - const send = date.value !== null ? new Date(date.value).toUTCString() : ""; - const activeDate = - dateLeave.value !== null ? new Date(dateLeave.value).toUTCString() : ""; - formData.append("Location", location.value); - formData.append("SendDate", send); - formData.append("ActiveDate", activeDate); - formData.append("Reason", reason.value); - formData.append("OrganizationPositionOld", organizationPositionOld.value); - formData.append("PositionTypeOld", positionTypeOld.value); - formData.append("PositionLevelOld", positionLevelOld.value); - formData.append("PositionNumberOld", posNo.value); - formData.append("AmountOld", salary.value.toString()); - formData.append("remarkHorizontal", remarkHorizontal.value); - showLoader(); - await http - .put(config.API.resingByid(id.value), formData) - .then(() => { - success($q, "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้ายสำเร็จ"); - edit.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(id.value); - hideLoader(); - }); +/** Function บันทึก ,แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย*/ +const onSubmitAttached = () => { + dialogConfirm($q, () => { + const formData = new FormData(); + const send = date.value !== null ? new Date(date.value).toUTCString() : ""; + const activeDate = + dateLeave.value !== null ? new Date(dateLeave.value).toUTCString() : ""; + formData.append("Location", location.value); + formData.append("SendDate", send); + formData.append("ActiveDate", activeDate); + formData.append("Reason", reason.value); + formData.append("OrganizationPositionOld", organizationPositionOld.value); + formData.append("PositionTypeOld", positionTypeOld.value); + formData.append("PositionLevelOld", positionLevelOld.value); + formData.append("PositionNumberOld", posNo.value); + formData.append("AmountOld", salary.value.toString()); + formData.append("remarkHorizontal", remarkHorizontal.value); + showLoader(); + http + .put(config.API.resingByid(id.value), formData) + .then(() => { + edit.value = false; + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(id.value); + await hideLoader(); + }); + }); }; /** @@ -464,52 +418,117 @@ function updatemodalPersonal(modal: boolean) { modalPersonal.value = modal; } +async function fetchFile() { + showLoader(); + await http + .get(config.API.file("พ้นจากราชการ", "หลักฐานลาออก", id.value)) + .then((res) => { + fileList.value = res.data; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); +} + function uploadFiles() { + showLoader(); + http + .post(config.API.file("พ้นจากราชการ", "หลักฐานลาออก", id.value), { + replace: true, + fileList: [ + { + fileName: file.value.name, + }, + ], + }) + .then(async (res) => { + const foundKey: string | undefined = Object.keys(res.data).find( + (key) => + res.data[key]?.fileName !== undefined && + res.data[key]?.fileName !== "" + ); + foundKey && uploadFileURL(res.data[foundKey]?.uploadUrl); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +async function uploadFileURL(uploadUrl: string) { const Data = new FormData(); Data.append("file", file.value); showLoader(); - http - .put(config.API.investigateRelevantUploadFile(id.value), Data) + await axios + .put(uploadUrl, file.value, { + headers: { + "Content-Type": file.value.type, + }, + }) .then(() => { success($q, "อัปโหลดไฟล์สำเร็จ"); + fetchFile(); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + file.value = null; + }); +} + +function downloadFiles(fileName: string) { + showLoader(); + http + .get( + config.API.fileByFile("พ้นจากราชการ", "หลักฐานลาออก", id.value, fileName) + ) + .then((res) => { + const data = res.data.downloadUrl; + window.open(data, "_blank"); }) .catch((e) => { messageError($q, e); }) .finally(async () => { hideLoader(); - file.value = null; }); } -function downloadFiles(link: string) { - window.open(link, "_blank"); -} - /** * ลบไฟล์ * @param id id file */ -function removeFile(id: string) { - dialogRemove($q, () => confirmRemove(id)); -} - -/** - * ยืนยัน ลบ ไฟล์ - * @param id id file - */ -function confirmRemove(fileId: string) { - showLoader(); - http - .delete(config.API.investigateRelevantFileDelete(id.value, fileId)) - .then((res) => { - success($q, `ลบไฟล์สำเร็จ`); - fetchData(id.value); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => {}); +function removeFile(fileName: string) { + dialogRemove($q, () => { + showLoader(); + http + .delete( + config.API.fileByFile( + "พ้นจากราชการ", + "หลักฐานลาออก", + id.value, + fileName + ) + ) + .then(() => { + success($q, `ลบไฟล์สำเร็จ`); + setTimeout(() => { + fetchFile(); + hideLoader(); + }, 1000); + }) + .catch((e) => { + messageError($q, e); + hideLoader(); + }); + }); }