hrms-mgt/src/modules/05_placement/components/probation/FormEvaluation/Template1.vue
setthawutttty 3469871886 no message
2023-08-29 14:56:06 +07:00

147 lines
4 KiB
Vue

<script setup lang="ts">
import { ref, defineAsyncComponent, watch, onMounted, onUpdated } from "vue";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router";
const Header = defineAsyncComponent(
() =>
import(
"@/modules/05_placement/components/probation/FormEvaluation/Header.vue"
)
);
const FormSaveResult = defineAsyncComponent(
() =>
import(
"@/modules/05_placement/components/probation/FormEvaluation/FormSaveResult.vue"
)
);
import http from "@/plugins/http";
import config from "@/app.config";
const router = useRouter();
const route = useRoute();
const $q = useQuasar();
const mixin = useCounterMixin();
const { showLoader, hideLoader, messageError, success } = mixin;
const assignId = ref<string>(route.params.form.toString());
const personalId = ref<string>(route.params.personalId.toString());
const fullname = ref<string>("");
const evaluate = ref<any>([]);
const tabs = ref<any>([]);
const tab = ref<string>("save1");
const dataArrayNumber = ref<number>();
const dataRole = ref<string>("mentor");
onMounted(async () => {
await fecthAssign(assignId.value);
});
const fecthAssign = async (id: string) => {
showLoader();
await http
.get(config.API.formevaluate(id))
.then(async (res: any) => {
evaluate.value = res.data.data.evaluate;
tabs.value = evaluate.value;
fullname.value = res.data.data.person.name;
dataArrayNumber.value = 1;
})
.catch((e: any) => {
// console.log(e);
messageError($q, e);
})
.finally(() => {
hideLoader();
});
};
const changeTab = (tabVal: string) => {
tab.value = tabVal;
dataArrayNumber.value = Number(tabVal.charAt(4));
};
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 FileDownload = async (type: string) => {
let numTab = evaluate.value.find((e: any) => e.no === dataArrayNumber.value);
//ผู้ดูเเล
if (dataRole.value == "mentor") {
showLoader();
await http
.get(config.API.reportEvaluateRecord1(type, numTab.id), {
responseType: "blob",
})
.then(async (res) => {
downloadFile(
res,
`แบบบันทึกผล(ผู้ดูเเล)_${fullname.value}_ครั้งที่${numTab.no}.${type}`
);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
} else {
//ผุ้บังคับ
showLoader();
await http
.get(config.API.reportEvaluateRecord2(type, numTab.id), {
responseType: "blob",
})
.then(async (res) => {
downloadFile(
res,
`แบบบันทึกผล(ผู้บังคับบัญชา)_${fullname.value}_ครั้งที่${numTab.no}.${type}`
);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
};
const addData = () => {
router.push(
`/probation/detail/addresult/${personalId.value}/${assignId.value}`
);
};
</script>
<template>
<Header
v-if="tabs.length > 0"
:change-tab="changeTab"
:add-data="addData"
:loop="tabs.length"
:FileDownload="FileDownload"
/>
<q-page-container v-if="tabs.length > 0">
<FormSaveResult
:tab="tab"
:data="evaluate.find((x: any) => x.no === dataArrayNumber)"
action="edit"
/>
</q-page-container>
<div class="q-gutter-md" v-else-if="tabs.length == 0">
<div class="flex justify-center items-center q-my-md q-gutter-md">
<q-btn
outline
color="primary"
label="สร้างแบบบันทึกผล"
@click="addData"
/>
</div>
</div>
</template>