hrms-mgt/src/modules/06_retirement/components/resignEMP/ResignReject.vue
2024-11-15 15:54:51 +07:00

840 lines
28 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, computed } from "vue";
import axios from "axios";
import { useRouter, useRoute } from "vue-router";
import { useQuasar, QForm } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import genReport from "@/plugins/genreport";
import { useCounterMixin } from "@/stores/mixin";
import DialogHeader from "@/components/DialogHeader.vue";
import type {
TypeFile,
rowFile,
FileList,
} from "@/modules/06_retirement/interface/response/Main";
import type { QTableProps } from "quasar";
import type { DataProfile } from "@/modules/05_placement/interface/index/Main";
import PopupPersonal from "@/components/Dialogs/PopupPersonal.vue";
import CardProfile from "@/components/CardProfile.vue";
import WorkFlow from "@/components/Workflow/Main.vue";
/** Use */
const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const checkRoutePermisson = ref<boolean>(route.name == "resignDetailRejectEMP");
const mixin = useCounterMixin();
const {
messageError,
date2Thai,
showLoader,
hideLoader,
success,
dialogConfirm,
dialogRemove,
} = mixin;
/** ตัวแปร */
const roleUser = ref<string>("");
const dataProfile = ref<DataProfile>();
const id = ref<string>(route.params.id.toString());
const myForm = ref<QForm | null>(null);
const edit = ref<boolean>(false);
const dataDetail = ref<any>({
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: "",
statusMain: "",
});
const workflowRef = ref<any>(null);
const organizationPositionOld = ref<string>("");
const positionTypeOld = ref<string>("");
const positionLevelOld = ref<string>("");
const posNo = ref<string>("");
const salary = ref<number>(0);
const date = ref<Date | null>(null);
const dateLeave = ref<Date | null>(null);
const reason = ref<string>("");
const location = ref<string>("");
const status = ref<string>("");
const remarkHorizontal = ref<string>("");
const modal = ref<boolean>(false);
const actionPass = ref<boolean>(false);
const reasonReign = ref<string>("");
const dateBreak = ref<Date | null>(null);
const isCheckData = computed(() => {
if (
organizationPositionOld.value !== "" &&
positionTypeOld.value !== "" &&
positionLevelOld.value !== "" &&
posNo.value !== "" &&
date.value !== null &&
dataDetail.value.commanderReject !== null &&
dataDetail.value.oligarchReject !== null
) {
return true;
} else return false;
});
/**เปิด-ปิด modal */
function closeModal() {
modal.value = false;
}
function openModal() {
modal.value = true;
}
const isNoDebt = ref<boolean>(false);
const isNoBurden = ref<boolean>(false);
const isDiscipline = ref<boolean>(false);
function 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;
}
/** นำข้อมูลมาจาก API*/
async function fetchData(id: string) {
showLoader();
await http
.get(config.API.listResignEMP() + `/cancel/${id}`)
.then(async (res) => {
const data = await res.data.result;
dataProfile.value = data as DataProfile;
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 ?? "";
remarkHorizontal.value = data.remarkHorizontal ?? "-";
isNoDebt.value = data.isNoDebt;
isNoBurden.value = data.isNoBurden;
isDiscipline.value = data.isDiscipline;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/**Pop up */
function popUp(action: "pass" | "passNot", type: string) {
reasonReign.value = "";
dateBreak.value = null;
actionPass.value = action === "pass";
roleUser.value = type;
openModal();
}
//เงื่อนไขpop up
function onSubmit() {
dialogConfirm($q, async () => {
showLoader();
const body = {
reason: reasonReign.value,
reject: !actionPass.value,
};
await http
.put(
config.API.resignRejectEMP(`${roleUser.value}-cancel`, id.value),
body
)
.then(async () => {
await fetchData(id.value);
closeModal();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
/**
* กดยกเลิก
*/
async function clickCancel() {
await fetchData(id.value);
edit.value = false;
myForm.value?.resetValidation();
}
/** Function บันทึก ,แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย*/
function 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.listResignEMP() + `/update-cancel/${id.value}`, formData)
.then(async () => {
await fetchData(id.value);
success($q, "บันทึกข้อมูลสำเร็จ");
edit.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
/**
* Function เพิ่ม Class เวลา Edit
* @param val เมื่อเป็นEdit จะเปลี่ยน Class
*/
function getClass(val: boolean) {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
}
/** แปลง StatusOrder */
function statusOrder(val: boolean) {
switch (val) {
case true:
return "ยับยั้ง";
case false:
return "อนุญาต";
}
}
const isDirector = ref<boolean>(false);
const isStaff = ref<boolean>(false);
function fetchCheckIsofficer() {
http
.get(config.API.workflowKeycloakSystem("RETIREMENT_CANCEL_EMP"))
.then((res) => {
isStaff.value = res.data.result.isStaff;
isDirector.value = res.data.result.isDirector;
})
.catch((err) => {
messageError($q, err);
});
}
/** Hook */
onMounted(async () => {
await Promise.all([fetchData(id.value), fetchCheckIsofficer()]);
});
</script>
<template>
<div class="q-gutter-sm q-pa-sm">
<div class="toptitle text-dark col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.push('/retirement/resign-employee')"
/>
รายละเอยดการยกเลกลาออกของ{{
dataDetail.firstName + " " + dataDetail.lastName
}}
</div>
<CardProfile :type="'employee'" :data="dataProfile as DataProfile" />
<!-- อมลการลาออก -->
<q-card bordered class="row col-12 text-dark q-mt-sm">
<div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
<div class="q-pl-sm text-weight-bold text-dark">อมลการลาออก</div>
<!-- <q-space />
<div
class="q-gutter-x-sm"
v-if="
(roleUser === 'officer' && dataDetail.officerReject === null) ||
(roleUser === 'commander' &&
dataDetail.commanderReject === null &&
dataDetail.officerReject !== null) ||
(roleUser === 'oligarch' &&
dataDetail.oligarchReject === null &&
dataDetail.commanderReject !== null &&
dataDetail.officerReject !== null)
"
>
<q-btn
outline
color="primary"
dense
icon-right="check"
class="q-px-sm"
label="อนุญาต"
@click="popUp('pass')"
/>
<q-btn
outline
color="red"
dense
icon-right="close"
class="q-px-sm"
label="ยับยั้ง"
@click="popUp('passNot')"
/>
</div> -->
</div>
<div class="col-12"><q-separator /></div>
<div class="row col-12 q-pa-md">
<div class="col-12 row bg-white q-col-gutter-md">
<div class="col-xs-6 col-sm-3 row items-start">
<div class="col-12">
<div class="col-12 text-top">สถานที่ยื่นขอลาออกจากราชการ</div>
<div class="col-12 text-detail">{{ dataDetail.location }}</div>
</div>
</div>
<div class="col-xs-6 col-sm-3 row items-start">
<div class="col-12">
<div class="col-12 text-top">วันที่ยื่นขอลาออกจากราชการ</div>
<div class="col-12 text-detail">
{{ date2Thai(dataDetail.sendDate) }}
</div>
</div>
</div>
<div class="col-xs-6 col-sm-3 row items-start">
<div class="col-12">
<div class="col-12 text-top">เหตุผลที่ลาออกจากราชการ</div>
<div class="col-12 text-detail">{{ dataDetail.reason }}</div>
</div>
</div>
<div class="col-xs-6 col-sm-3 row items-start">
<div class="col-12">
<div class="col-12 text-top">วันที่ขอลาออกจากราชการ</div>
<div
:class="
diffDate()
? 'col-12 text-detail text-red text-bold'
: 'col-12 text-detail'
"
>
{{ date2Thai(dataDetail.activeDate) }}
</div>
<div
:class="
diffDate()
? 'col-12 text-detail text-red text-bold'
: 'col-12 text-detail'
"
>
{{ diffDate() ? "(ยื่นขอลาออกน้อยกว่า 30 วัน)" : "" }}
</div>
</div>
</div>
</div>
</div>
</q-card>
<!-- ผลการพิจารณาของผู้บังคับบัญชา -->
<q-card bordered class="row col-12 text-dark q-mt-sm">
<div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
<div class="q-pl-sm text-weight-bold text-dark">
ผลการพิจารณาของผู้บังคับบัญชา
</div>
<q-space />
<div
class="q-gutter-x-sm"
v-if="
isDirector &&
dataDetail.commanderReject === null &&
dataDetail.statusMain === 'WAITTING'
"
>
<q-btn
outline
color="primary"
dense
icon-right="check"
class="q-px-sm"
label="อนุญาต"
@click="popUp('pass', 'commander')"
/>
<q-btn
outline
color="red"
dense
icon-right="close"
class="q-px-sm"
label="ยับยั้ง"
@click="popUp('passNot', 'commander')"
/>
</div>
</div>
<div class="col-12"><q-separator /></div>
<div class="row col-12 q-pa-md">
<div class="col-12 row bg-white q-col-gutter-md">
<div class="col-xs-6 row items-start">
<div class="col-12 text-top">สถานะ</div>
<div class="col-12 text-detail">
{{
dataDetail.commanderReject !== null
? statusOrder(dataDetail.commanderReject)
: "-"
}}
</div>
</div>
<!-- <div class="col-xs-6 row items-start">
<div class="col-12 text-top">วันสุดท้ายที่ยับยั้ง</div>
<div class="col-12 text-detail">
{{
dataDetail.commanderRejectDate !== null
? date2Thai(dataDetail.commanderRejectDate)
: "-"
}}
</div>
</div> -->
<div class="col-xs-12 row items-start">
<div class="col-12 text-top">ความคิดเห็นและเหตุผล</div>
<div class="col-12 text-detail">
{{
dataDetail.commanderReject
? dataDetail.commanderApproveReason
: dataDetail.commanderApproveReason
}}
</div>
</div>
</div>
</div>
</q-card>
<!-- ผลการพิจารณาของผู้มีอำนาจ -->
<q-card bordered class="row col-12 text-dark q-mt-sm">
<div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
<div class="q-pl-sm text-weight-bold text-dark">
ผลการพิจารณาของผู้มีอำนาจ
</div>
<q-space />
<div
class="q-gutter-x-sm"
v-if="
isDirector &&
dataDetail.oligarchReject === null &&
dataDetail.statusMain === 'WAITTING'
"
>
<q-btn
outline
color="primary"
dense
icon-right="check"
class="q-px-sm"
label="อนุญาต"
@click="popUp('pass', 'oligarch')"
/>
<q-btn
outline
color="red"
dense
icon-right="close"
class="q-px-sm"
label="ยับยั้ง"
@click="popUp('passNot', 'oligarch')"
/>
</div>
</div>
<div class="col-12"><q-separator /></div>
<div class="row col-12 q-pa-md">
<div class="col-12 row bg-white q-col-gutter-md">
<div class="col-xs-6 row items-start">
<div class="col-12 text-top">สถานะ</div>
<div class="col-12 text-detail">
{{
dataDetail.oligarchReject !== null
? statusOrder(dataDetail.oligarchReject)
: "-"
}}
</div>
</div>
<!-- <div class="col-xs-6 row items-start">
<div class="col-12 text-top">วันสุดท้ายที่ยับยั้ง</div>
<div class="col-12 text-detail">
{{
dataDetail.oligarchRejectDate !== null
? date2Thai(dataDetail.oligarchRejectDate)
: "-"
}}
</div>
</div> -->
<div class="col-xs-12 row items-start">
<div class="col-12 text-top">ความคิดเห็นและเหตุผล</div>
<div class="col-12 text-detail">
{{
dataDetail.oligarchReject
? dataDetail.oligarchApproveReason
: dataDetail.oligarchApproveReason
}}
</div>
</div>
</div>
</div>
</q-card>
<!-- แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย -->
<q-card bordered class="row col-12 text-dark q-mt-sm">
<q-form
ref="myForm"
greedy
@submit.prevent
@validation-success="onSubmitAttached"
class="full-width"
>
<div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
<div class="q-pl-sm text-weight-bold text-dark">
แก้ไขข้อมูลเพื่อลงบัญชีแนบท้าย
</div>
<q-space />
<!-- && workflowRef?.permission.isUpdate -->
<div
v-if="
!checkRoutePermisson &&
isStaff &&
dataDetail.statusMain === 'WAITTING'
"
>
<div class="q-gutter-sm" v-if="!edit">
<q-btn
outline
color="primary"
dense
icon-right="mdi-file-edit-outline"
class="q-px-sm"
label="แก้ไข"
style="width: 80px"
@click="edit = !edit"
v-if="!(status == 'REPORT' || status == 'DONE')"
/>
</div>
<div class="q-gutter-sm" v-else>
<q-btn
outline
color="public"
dense
class="q-px-sm"
label="บันทึก"
style="width: 80px"
type="submit"
/>
<q-btn
outline
color="red"
dense
class="q-px-sm"
label="ยกเลิก"
style="width: 80px"
@click="clickCancel"
/>
</div>
</div>
</div>
<div class="col-12"><q-separator /></div>
<div class="row col-12 q-pa-md">
<div class="col-12 row bg-white q-col-gutter-md">
<div class="col-xs-12 row items-center">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="organizationPositionOld"
:rules="[(val:string) => !!val || `${'กรุณากรอกตำแหน่ง/สังกัดเดิม'}`]"
hide-bottom-space
:label="`${'ตำแหน่ง/สังกัดเดิม'}`"
type="textarea"
/>
</div>
</div>
<div class="col-xs-6 col-sm-4 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="positionTypeOld"
:rules="[(val:string) => !!val || `${'กรุณากรอกกลุ่มงาน'}`]"
hide-bottom-space
:label="`${'กลุ่มงาน'}`"
/>
</div>
</div>
<div class="col-xs-6 col-sm-4 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="positionLevelOld"
:rules="[(val:string) => !!val || `${'กรุณากรอกระดับตำแหน่ง'}`]"
hide-bottom-space
:label="`${'ระดับตำแหน่ง'}`"
/>
</div>
</div>
<div class="col-xs-6 col-sm-4 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="posNo"
:rules="[(val:string) => !!val || `${'กรุณากรอกเลขที่'}`]"
hide-bottom-space
:label="`${'เลขที่'}`"
/>
</div>
</div>
<!-- <div class="col-xs-6 col-sm-3 row">
<div class="col-12">
<q-input
v-model="salary"
:outlined="edit"
dense
:readonly="!edit"
:borderless="!edit"
hide-bottom-space
:label="`${'เงินเดือน'}`"
:rules="[(val:number) => !!val || `${'กรุณากรอกเงินเดือน'}`]"
lazy-rules
:class="getClass(edit)"
mask="###,###,###,###"
reverse-fill-mask
/>
</div>
</div> -->
<div class="col-12"><q-separator /></div>
<div class="col-xs-4 row">
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="location"
:rules="[
(val:string) => !!val || `${'กรุณากรอกสถานที่ยื่นขอลาออกจากราชการ'}`,
]"
hide-bottom-space
:label="`${'สถานที่ยื่นขอลาออกจากราชการ'}`"
/>
</div>
</div>
<div class="col-xs-4 row">
<div class="col-12">
<datepicker
menu-class-name="modalfix"
:readonly="!edit"
v-model="date"
:locale="'th'"
autoApply
:enableTimePicker="false"
week-start="0"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
<q-input
:readonly="!edit"
:class="getClass(edit)"
:outlined="edit"
dense
:borderless="!edit"
:model-value="date !== null ? date2Thai(date) : null"
:rules="[
(val:string) =>
!!val || `${'กรุณาเลือก วันที่ยื่นขอลาออกจากราชการ'}`,
]"
hide-bottom-space
:label="`${' วันที่ยื่นขอลาออกจากราชการ'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
:style="
edit
? 'color: var(--q-primary)'
: 'color: var(--q-grey)'
"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
</div>
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="reason"
:rules="[
(val:string) => !!val || `${'กรุณากรอกเหตุผลที่ลาออกจากราชการ'}`,
]"
hide-bottom-space
:label="`${'เหตุผลที่ลาออกจากราชการ (หมายเหตุแนวตั้ง)'}`"
type="textarea"
/>
</div>
<div class="col-12">
<q-input
:class="getClass(edit)"
:outlined="edit"
dense
lazy-rules
:readonly="!edit"
:borderless="!edit"
v-model="remarkHorizontal"
:rules="[(val:string) => !!val || `${'กรุณากรอกหมายเหตุแนวนอน '}`]"
hide-bottom-space
:label="`${'หมายเหตุแนวนอน '}`"
type="textarea"
/>
</div>
</div>
</div>
</q-form>
</q-card>
<!-- <WorkFlow
ref="workflowRef"
v-model:is-check-data="isCheckData"
:id="id"
sys-name="RETIREMENT_CANCEL"
/> -->
</div>
<q-dialog v-model="modal" persistent>
<q-card style="width: 800px">
<q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader
:tittle="`${
actionPass ? 'อนุญาตยกเลิกการลาออก' : 'ยับยั้งยกเลิกการลาออก'
}`"
:close="closeModal"
/>
<q-separator />
<q-card-section class="q-p-sm q-gutter-md">
<div class="col-xs-12 col-sm-12 col-md-12">
<q-input
hide-bottom-space
dense
outlined
lazy-rules
:rules="[(val:string) => !!val || 'กรุณากรอกความคิดเห็น/เหตุผล']"
v-model="reasonReign"
:label="`${'กรอกความคิดเห็น/เหตุผล'}`"
type="textarea"
class="inputgreen"
/>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn label="บันทึก" color="secondary" type="submit"
><q-tooltip>นทกขอม</q-tooltip></q-btn
>
</q-card-actions>
<!-- <DialogFooter :editvisible="true" :save="conditionPopup" /> -->
</q-form>
</q-card>
</q-dialog>
</template>
<style lang="scss" scope>
.q-img {
border-radius: 5px;
height: 70px;
}
.text-top {
color: gray;
font-weight: 400;
padding-bottom: 3px;
}
.text-detail {
font-weight: 500;
}
</style>