hrms-mgt/src/modules/12_evaluatePersonal/components/Detail/step/step4.vue

580 lines
17 KiB
Vue

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import { useQuasar } from "quasar";
import axios from "axios";
import http from "@/plugins/http";
import config from "@/app.config";
import genReport from "@/plugins/genreport";
/** importType*/
import type { PersonInformation } from "@/modules/12_evaluatePersonal/interface/response/evalute";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
import { useEvaluateDetailStore } from "@/modules/12_evaluatePersonal/store/EvaluateDetail";
/** use*/
const route = useRoute();
const $q = useQuasar();
const mixin = useCounterMixin();
const store = useEvaluateDetailStore();
const {
date2Thai,
showLoader,
hideLoader,
messageError,
success,
dialogConfirm,
} = mixin;
const id = ref<string>(route.params.id as string);
const profile = ref<any>();
const messenger = ref<string>("");
const title = ref<string>("");
const modalEvaluation = ref<boolean>(false);
const fileEvaluationUpload = ref<any>();
const fileEvaluationUploadRef = ref<any>();
const files = [
{
id: "file1",
fileName: "แบบพิจารณาคุณสมบัติบุคคล",
pathName: "1-แบบพิจารณาคุณสมบัติบุคคล",
},
{
id: "file2",
fileName: "แบบแสดงรายละเอียดการเสนอผลงาน",
pathName: "2-แบบแสดงรายละเอียดการเสนอผลงาน",
},
{
id: "file3",
fileName:
"แบบตรวจสอบความถูกต้องครบถ้วนของข้อมูลเพื่อประกอบการคัดเลือกบุคคล (เอกสารแบบ ก)",
pathName:
"3-แบบตรวจสอบความถูกต้องครบถ้วนของข้อมูลเพื่อประกอบการคัดเลือกบุคคล (เอกสารแบบ ก)",
},
{
id: "file4",
fileName: "แบบประเมินคุณลักษณะบุคคล",
pathName: "4-แบบประเมินคุณลักษณะบุคคล",
},
{
id: "file5",
fileName: "แบบสรุปข้อมูลของผู้ขอรับการคัดเลือก (เอกสารหมายเลข 9)",
pathName: "5-แบบสรุปข้อมูลของผู้ขอรับการคัดเลือก (เอกสารหมายเลข 9)",
},
{
id: "file6",
fileName: "ผลงานที่จะส่งประเมิน (เอกสารหมายเลข 11)",
pathName: "6-ผลงานที่จะส่งประเมิน (เอกสารหมายเลข 11)",
},
];
/** function ดาวน์โหลดไฟล์ต้นแบบ*/
async function onClickDowloadFile(
tp: string,
templateName: string,
fileName: string
) {
showLoader();
const data = Object.assign(
{ fullName: profile.value == null ? "" : profile.value.fullName },
{ position: profile.value == null ? "" : profile.value.position },
{ positionLevel: profile.value == null ? "" : profile.value.positionLevel },
{ posNo: profile.value == null ? "" : profile.value.posNo },
{ oc: profile.value == null ? "" : profile.value.oc },
{
birthDate:
profile.value == null ? "" : date2Thai(profile.value.birthDate),
},
{ govAge: profile.value == null ? "" : profile.value.govAge },
{
positionLevelNew:
profile.value == null
? ""
: profile.value.type == "EXPERT"
? "ชำนาญการ"
: "ชำนาญการพิเศษ",
},
tp === "EV1_005" || tp === "EV1_007"
? { organizationName: "หน่วยงาน" }
: null,
tp === "EV1_007" ? { positionName: "ตำแหน่ง" } : null,
tp === "EV1_007" ? { positionLeaveName: "ระดับ" } : null
);
const body = {
template: tp,
reportName: templateName,
data: data,
};
await genReport(body, fileName);
}
/** function เปิด popup ติดต่อผู้ขอประเมิน */
function openPopUp() {
modalEvaluation.value = true;
}
/**
* function ดาวน์โหลดไฟล์
* @param name ชื้อไฟล์
*/
async function downloadFile(name: string) {
showLoader();
await http
.get(config.API.evaluationFilebyId("เล่ม 1", id.value, name))
.then((res) => {
const link = res.data.downloadUrl;
const type = res.data.fileType;
const fileName = res.data.fileName;
getPDF(link, type, fileName);
})
.catch((e) => {})
.finally(() => {
hideLoader();
});
}
/**
* function เรียกไฟล์ PDF
* @param url link PDF
* @param type ประเภทไฟล์
* @param fileName ชือไฟล์
*/
async function getPDF(url: string, type: string, fileName: string) {
await axios
.get(url, {
method: "GET",
responseType: "blob",
headers: {
"Content-Type": "application/json",
Accept: type, // ถ้ามีการระบุเมื่ออัปโหลด
},
})
.then(async (res) => {
const a = document.createElement("a");
a.href = window.URL.createObjectURL(res.data);
a.download = fileName;
a.click();
})
.catch((e) => {})
.finally(() => {});
}
/** function ส่งไปประกาศบนเว็บไซต์ */
function onWebSite() {
download10Url.value === ""
? (fileEvaluationUpload.value = "")
: fileEvaluationUpload.value;
fileEvaluationUploadRef.value.validate();
if (
fileEvaluationUploadRef.value.hasError === false &&
download10Url.value !== ""
) {
dialogConfirm(
$q,
() => {
showLoader();
http
.put(config.API.evaluationApproveDoc1(id.value))
.then(() => {
success($q, "ส่งไปประกาศบนเว็บไซต์สำเร็จ");
})
.catch(() => {})
.finally(() => {
getStep();
});
},
"ยืนยันการส่งไปประกาศบนเว็บไซต์",
"ยืนยันการส่งไปประกาศบนเว็บไซต์ใช่หรือไม่?"
);
}
}
/** function เช็คขั้นตอน*/
async function getStep() {
showLoader();
await http
.get(config.API.evaluateGetStep(id.value))
.then((res: any) => {
const data = res.data.result;
let step =
data.step === "CHECK_SPEC"
? 1
: data.step === "PREPARE_DOC_V1"
? 2
: data.step === "CHECK_DOC_V1"
? 3
: data.step === "WAIT_CHECK_DOC_V1"
? 4
: data.step === "ANNOUNCE_WEB"
? 5
: data.step === "PREPARE_DOC_V2"
? 6
: data.step === "WAIT_CHECK_DOC_V2"
? 7
: data.step === "CHECK_DOC_V2"
? 8
: data.step === "DONE"
? 9
: 1;
store.currentStep = step;
store.step = step;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/**
* function เรียก link อัปโหลด
* @param file ไฟล์
*/
async function upLoadFile(file: any) {
if (file) {
showLoader();
await http
.post(config.API.evaluationFileListbyId("เล่ม 1", id.value), {
fileList: {
fileName: "10-ประกาศผลการคัดเลือกบุคคล (เอกสารหมายเลข 10)",
metadata: {
tag: "value",
subject: subject.value,
author: author.value,
},
},
})
.then((res) => {
const foundKey: any = Object.keys(res.data).find(
(key) =>
res.data[key]?.fileName !== undefined &&
res.data[key]?.fileName !== ""
);
const link = res.data[foundKey]?.uploadUrl;
fileUpLoad(link);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
}
/**
* function อัปโหลดไฟล์
* @param url link อัปโหลด
*/
function fileUpLoad(url: string) {
axios
.put(url, fileEvaluationUpload.value, {
headers: { "Content-Type": fileEvaluationUpload.value?.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
checkDoc10();
success($q, "อัปโหลดไฟล์สำเร็จ");
});
}
const myForm = ref<any>();
/** fiunction ส่งข้อความ*/
async function sentMessenger() {
myForm.value.validate().then(async (result: boolean) => {
if (result) {
showLoader();
await http
.put(config.API.evaluationSentToContact(id.value), {
subject: title.value,
body: messenger.value,
})
.then(() => {
success($q, "ส่งข้อความสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
modalEvaluation.value = false;
title.value = "";
messenger.value = "";
hideLoader();
});
}
});
}
const download10Url = ref<string>("");
/** function เช็คไฟล์อัปโหลด*/
async function checkDoc10() {
showLoader();
await http
.get(
config.API.evaluationPatchData(
"เล่ม 1",
id.value,
"10-ประกาศผลการคัดเลือกบุคคล (เอกสารหมายเลข 10)"
)
)
.then((res: any) => {
download10Url.value = res.data.downloadUrl;
})
.catch(() => {
// messageError($q, e);
})
.finally(() => {
hideLoader();
});
fetchProfile();
}
/** function เรียกข้แมูลคุณสมบัติ*/
async function fetchProfile() {
showLoader();
await http
.get(config.API.evaluateGetDetail(id.value))
.then((res) => {
const data = res.data.result;
profile.value = data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
const author = ref<string>("");
const subject = ref<string>("");
/** function เรียกข้อมูลผลงาน*/
async function fetchDataSigner() {
showLoader();
await http
.get(config.API.evaluationSigner(id.value, 1))
.then((res) => {
const data = res.data.result;
author.value = data.author;
subject.value = data.subject;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
onMounted(async () => {
await checkDoc10();
await fetchDataSigner();
});
</script>
<template>
<div class="row q-col-gutter-sm q-pa-sm">
<!-- เอกสารเลมท 1 -->
<div class="col-12">
<q-card bordered style="border: 1px solid #d6dee1">
<div class="text-weight-medium bg-grey-1 q-py-sm q-px-md">
เอกสารเลมท 1
</div>
<div class="col-12"><q-separator /></div>
<q-list
v-for="file in files"
:key="file.id"
class="full-width"
bordered
>
<q-item clickable v-ripple>
<q-item-section class="text-grey-9">{{ file.fileName }}</q-item-section>
<q-item-section avatar>
<div class="row">
<div>
<q-btn
dense
flat
round
size="12px"
color="blue"
icon="mdi-download"
@click="downloadFile(file.pathName)"
>
<q-tooltip>ดาวนโหลดไฟล</q-tooltip>
</q-btn>
</div>
</div>
</q-item-section>
</q-item>
</q-list>
</q-card>
</div>
<!-- ประกาศผลการคดเลอกบคคล (เอกสารหมายเลข 10) -->
<div class="col-12">
<q-card bordered style="border: 1px solid #d6dee1">
<div class="text-weight-medium row col-12 bg-grey-1 q-py-sm q-px-md items-center">
<div>ประกาศผลการคดเลอกบคคล (เอกสารหมายเลข 10)</div>
<q-space/>
<div v-if="store.currentStep == 4" >
<q-btn
icon="download"
color="indigo"
flat
dense
round
@click="
onClickDowloadFile(
'เอกสารหมายเลข 10',
'template-4',
'ประกาศผลการคัดเลือกบุคคล (เอกสารหมายเลข 10)'
)
"
>
<q-tooltip> ดาวนโหลดตนแบบ </q-tooltip></q-btn
>
</div>
<div >
<q-btn
v-if="download10Url != ''"
:href="download10Url"
target="_blank"
class="col-12"
icon="visibility"
color="blue"
flat
dense
round
>
<q-tooltip> ไฟลเอกสาร </q-tooltip></q-btn
>
</div>
</div>
<div class="col-12" v-if="store.currentStep == 4"><q-separator /></div>
<div class="row">
<div class="col-12 q-pa-sm" v-if="store.currentStep == 4">
<q-file
ref="fileEvaluationUploadRef"
v-model="fileEvaluationUpload"
class="col-12"
outlined
dense
hide-bottom-space
lazy-rules
accept=".pdf"
:rules="
download10Url === ''
? [(val) => !!val || 'กรุณาเลือกไฟล์']
: []
"
>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
<template v-slot:after>
<q-btn
flat
round
dense
color="primary"
icon="mdi-upload "
@click="upLoadFile(fileEvaluationUpload)"
><q-tooltip>ปโหลดไฟล</q-tooltip></q-btn
>
</template>
</q-file>
</div>
</div>
</q-card>
</div>
<!-- ดตอผขอประเม -->
<div class="col-12" v-if="store.currentStep == 4">
<div class="q-mt-xs q-gutter-md" align="right">
<q-btn label="ติดต่อผู้ขอประเมิน" color="info" @click="openPopUp" />
<q-btn
unelevated
label="ส่งไปประกาศบนเว็บไซต์"
color="public"
@click="onWebSite"
/>
</div>
</div>
</div>
<!-- popup ดตอผขอประเม -->
<q-dialog v-model="modalEvaluation" persistent>
<q-card style="min-width: 60vw">
<q-toolbar>
<q-toolbar-title class="text-subtitle2 text-bold">
ดตอผขอประเม
</q-toolbar-title>
<q-btn
icon="close"
unelevated
round
dense
@click="modalEvaluation = false"
style="color: #ff8080; background-color: #ffdede"
/>
</q-toolbar>
<q-separator />
<q-card-section class="q-pa-md bg-grey-1">
<q-form ref="myForm">
<div class="row q-col-gutter-sm">
<div class="col-12">
<q-input
v-model="title"
label="หัวข้อ"
outlined
dense
bg-color="white"
:rules="[(val) => !!val || 'กรุณากรอกหัวข้อ']"
/>
</div>
<div class="col-12">
<q-input
v-model="messenger"
label="ข้อความ"
type="textarea"
outlined
dense
bg-color="white"
:rules="[(val) => !!val || 'กรุณากรอกข้อความ']"
/>
</div>
</div>
</q-form>
</q-card-section>
<q-separator />
<div class="row justify-end q-px-md q-py-sm items-center">
<q-btn
dense
color="public"
id="onSubmit"
class="q-px-md q-py-xs"
label="ส่งข้อความ"
@click="sentMessenger"
>
</q-btn>
</div>
</q-card>
</q-dialog>
</template>
<style scoped></style>