import CurrencyInput from "@/components/CurruncyInput.vue"; import http from "@/plugins/http"; import config from "@/app.config"; import type { ResponseItems, TypeFile, } from "@/modules/06_retirement/interface/response/Main"; import type { QTableProps } from "quasar"; const $q = useQuasar(); const route = useRoute(); const router = useRouter(); const mixin = useCounterMixin(); const RetirementData = useRetirementDataStore(); const { messageError, date2Thai, showLoader, hideLoader, success, dialogMessage, } = mixin; const { statusText } = RetirementData; const id = ref(route.params.id.toString()); const myForm = ref(null); const myFormConfirm = ref(null); const edit = ref(false); const dataDetail = ref({ datetext: "", activeDate: new Date(), createdAt: new Date(), firstName: "", id: "", isActive: true, lastName: "", location: "", organizationPositionOld: "", positionLevelOld: "", positionNumberOld: "", positionTypeOld: "", prefix: "", profileId: "", reason: "", salary: 0, sendDate: new Date(), status: "", statustext: "", fullname: "", }); const organizationPositionOld = ref(""); const positionTypeOld = ref(""); const positionLevelOld = ref(""); const posNo = ref(""); const salary = ref(0); const date = ref(null); const dateLeave = ref(null); const reason = ref(""); const location = ref(""); const status = ref(""); const modal = ref(false); const actionPass = ref(false); const reasonReign = ref(""); const dateBreak = ref(null); const rows = ref([]); const columns = ref([ { name: "no", align: "left", label: "ลำดับ", sortable: true, field: "no", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { name: "fileName", align: "left", label: "ชื่อไฟล์", sortable: true, field: "fileName", headerStyle: "font-size: 14px", style: "font-size: 14px", }, { name: "btnMicrosoft", align: "right", label: "ปุ่ม", sortable: true, field: "btnMicrosoft", headerStyle: "font-size: 14px", style: "font-size: 14px", }, ]); const rowsFileDownload = ref([ {fileName: "หนังสือลาออกจากราขการ", pathName: ""}]); const closeModal = () => (modal.value = false); const openModal = () => (modal.value = true); // const modalPass = ref(false); // const modalPassNot = ref(false); onMounted(() => { fetchData(id.value); // fetchAttachment('pdf',id.value) // fetchAttachment('docx',id.value) // downloadAttachment('pdf',id.value) }); const diffDate = () => { if (date.value !== null && dateLeave.value !== null) { const time = dateLeave.value.getTime() - date.value.getTime(); //วันที่ขอลาออกจากราชการ - วันที่ยื่นขอลาออกจากราชการ const day = time / (1000 * 3600 * 24); if (day < 30) { return true; } return false; } return false; }; const fetchData = async (id: string) => { showLoader(); await http .get(config.API.resingByid(id)) .then((res: any) => { const data = res.data.result; // console.log(data); let list: TypeFile[] = []; if (data.docs.length > 0) { data.docs.map((doc: TypeFile) => { list.push({ pathName: doc.pathName ?? "", fileName: doc.fileName ?? "", }); console.log(doc.fileName); }); } rows.value = list; dataDetail.value = data; organizationPositionOld.value = data.organizationPositionOld ?? ""; positionTypeOld.value = data.positionTypeOld ?? ""; positionLevelOld.value = data.positionLevelOld ?? ""; posNo.value = data.positionNumberOld ?? ""; salary.value = data.salary ? data.salary : 0; date.value = data.sendDate ? new Date(data.sendDate) : null; dateLeave.value = data.activeDate ? new Date(data.activeDate) : null; reason.value = data.reason ?? ""; location.value = data.location ?? ""; status.value = data.status ?? ""; }) .catch((e) => { console.log(e); messageError($q, e); }) .finally(() => { hideLoader(); }); }; const fetchAttachment = async (type:string , id: string) => { showLoader(); await http .get(config.API.reportResignList(type, id)) .then((res: any) => { const data = res.data.result; // console.log(data); let list: TypeFile[] = []; if (data.docs.length > 0) { data.docs.map((doc: TypeFile) => { list.push({ pathName: doc.pathName ?? "", fileName: doc.fileName ?? "", }); console.log(doc.fileName); }); } rowsFileDownload.value = list; }) .catch((e) => { console.log(e); messageError($q, e); }) .finally(() => { hideLoader(); }); }; const downloadAttachment = async (type:string , id: string) => { showLoader(); await http .get(config.API.reportResignList(type, id), { responseType: "blob", }) .then(async (res) => { const data = res.data.result; console.log(data); let list: TypeFile[] = []; downloadFile(res, `หนังสือลาออกจากราขการ.${type}`); }) .catch((e) => { messageError($q, e); }) .finally(() => { hideLoader(); }); }; 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); }; const popUp = (action: "pass" | "passNot") => { reasonReign.value = ""; dateBreak.value = null; actionPass.value = action === "pass"; openModal(); // if (action === "pass") { // $q.dialog({ // title: "ยืนยันการอนุมัติการลาออก", // message: "ต้องการยืนยันอนุมัติการลาออกนี้ใช่หรือไม่?", // cancel: { // flat: true, // color: "negative", // }, // persistent: true, // }).onOk(async () => { // confirmpopUp(); // }); // } else if (action === "passNot") { // $q.dialog({ // title: "ยืนยันการยับยั้งการลาออก", // message: "ต้องการยืนยันการยับยั้งการลาออกนี้ใช่หรือไม่?", // cancel: { // flat: true, // color: "negative", // }, // persistent: true, // }).onOk(async () => { // rejectpopUp(); // }); // } }; const conditionPopup = () => { if (myFormConfirm.value !== null) { myFormConfirm.value.validate().then(async (check) => { if (check) { if (actionPass.value) { await confirmpopUp(); } else { await rejectpopUp(); } } }); } }; const confirmpopUp = async () => { const body = { reason: reasonReign.value, }; await http .put(config.API.resignConfirm(id.value), body) .then(() => { console.log("ยืนยัน"); success($q, "การอนุมัติสำเร็จ"); closeModal(); }) .catch((e) => { console.log(e); messageError($q, e); }) .finally(() => { fetchData(id.value); }); }; const rejectpopUp = async () => { const body = { reason: reasonReign.value, }; await http .put(config.API.resignReject(id.value), body) .then(() => { success($q, "การยับยั้งสำเร็จ"); closeModal(); }) .catch((e) => { messageError($q, e); }) .finally(() => { fetchData(id.value); }); }; const redirectToRegistry = (id: string) => { router.push(`/registry/${id}`); }; const conditionSave = () => { if (myForm.value !== null) { myForm.value.validate().then((success) => { if (success) { dialogMessage( $q, "ต้องการแก้ไขข้อมูลหรือไม่?", "แก้ไขข้อมูลรายละเอียดการลาออก", "mdi-help-circle-outline", "ตกลง", "public", async () => await saveData(), undefined ); } }); } }; 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()); salary; showLoader(); await http .put(config.API.resingByid(id.value), formData) .then((res: any) => { // const data = res.data.result; // console.log(data); success($q, "แก้ไขข้อมูลเพื่อลงบัญชีแนบท้ายสำเร็จ"); edit.value = false; }) .catch((e) => { messageError($q, e); }) .finally(async () => { await fetchData(id.value); hideLoader(); }); }; // const clickClose = () => { // userNote.value = ""; // modalPass.value = false; // modalPassNot.value = false; // }; // const savePass = () => { // $q.dialog({ // title: "ยืนยันการขอลาออก", // message: "ต้องการยืนยันการขอลาออกข้อมูลนี้ใช่หรือไม่ ?", // cancel: { // flat: true, // const: "negative", // }, // persistent: true, // }) // .onOk(() => { // modalPass.value = false; // console.log("----MSG---- :", userNote.value); // console.log("passSave (close)"); // userNote.value = ""; // }) // .onCancel(() => {}) // .onDismiss(() => {}); // }; // const savePassNot = () => { // $q.dialog({ // title: "ยืนยันการขอลาออก", // message: "ต้องการยืนยันการขอลาออกข้อมูลนี้ใช่หรือไม่ ?", // cancel: { // flat: true, // const: "negative", // }, // persistent: true, // }) // .onOk(() => { // modalPass.value = false; // console.log("----MSG---- :", userNote.value); // console.log("passSaveNot (close)"); // userNote.value = ""; // }) // .onCancel(() => {}) // .onDismiss(() => {}); // }; const getClass = (val: boolean) => { return { "full-width inputgreen cursor-pointer": val, "full-width cursor-pointer": !val, }; };