166 lines
4.2 KiB
Vue
166 lines
4.2 KiB
Vue
<script setup lang="ts">
|
|
import { ref, defineAsyncComponent, onMounted } from "vue";
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
import { useQuasar } from "quasar";
|
|
import { useRoute, useRouter } from "vue-router";
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
import { useProbationDataStore } from "@/modules/05_placement/storeProbation";
|
|
|
|
const Header = defineAsyncComponent(
|
|
() =>
|
|
import(
|
|
"@/modules/05_placement/components/probation/FormEvaluation/Header.vue"
|
|
)
|
|
);
|
|
const FormEvaluate = defineAsyncComponent(
|
|
() =>
|
|
import(
|
|
"@/modules/05_placement/components/probation/FormEvaluation/FormEvaluate.vue"
|
|
)
|
|
);
|
|
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
const checkRoutePermisson = ref<boolean>(route.name == "probationFormDetail");
|
|
const mixin = useCounterMixin();
|
|
const $q = useQuasar();
|
|
const { showLoader, hideLoader, messageError } = mixin;
|
|
const probationStore = useProbationDataStore();
|
|
const { fecthdataAssign } = probationStore;
|
|
const assignId = ref<string>(route.params.form.toString());
|
|
const personalId = ref<string>(route.params.personalId.toString());
|
|
const tab = ref<string>("save1");
|
|
const tabs = ref<any>([]);
|
|
const dataArrayNumber = ref<number>(1);
|
|
const evaluate = ref<any>([]);
|
|
|
|
/**
|
|
* เปลี่ยน tab
|
|
* @param tabVal type
|
|
*/
|
|
function changeTab(tabVal: string) {
|
|
tab.value = tabVal;
|
|
dataArrayNumber.value = Number(tabVal.charAt(4));
|
|
}
|
|
|
|
/**
|
|
* get data
|
|
* @param id person id
|
|
*/
|
|
async function fecthAssign(id: string) {
|
|
showLoader();
|
|
await http
|
|
.get(config.API.createformCommader(id))
|
|
.then(async (res: any) => {
|
|
await fecthdataAssign(res.data.data);
|
|
evaluate.value = probationStore.evaluate;
|
|
tabs.value = evaluate.value;
|
|
// fullname.value = res.data.data.person ? res.data.data.person.name : "";
|
|
dataArrayNumber.value = 1;
|
|
})
|
|
.catch((e: any) => {
|
|
messageError($q, e);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/** เปลี่ยน type file */
|
|
function 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);
|
|
}
|
|
|
|
/**
|
|
* download file
|
|
* @param type type
|
|
*/
|
|
async function FileDownload(type: string) {
|
|
let numTab = evaluate.value.find((e: any) => e.no === dataArrayNumber.value);
|
|
showLoader();
|
|
await http
|
|
.get(config.API.reportEvaluate(type, numTab.id), {
|
|
responseType: "blob",
|
|
})
|
|
.then(async (res) => {
|
|
downloadFile(
|
|
res,
|
|
`แบบประเมินผล(ผู้บังคับบัญชา)_${probationStore.person.name}_ครั้งที่${numTab.no}.${type}`
|
|
);
|
|
})
|
|
.catch(async (e) => {
|
|
messageError($q, JSON.parse(await e.response.data.text()));
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/** เปลี่ยนหน้า เพิ่ม */
|
|
function addData() {
|
|
router.push(
|
|
`/probation/detail/addevalua/${personalId.value}/${assignId.value}`
|
|
);
|
|
}
|
|
|
|
onMounted(() => {
|
|
fecthAssign(assignId.value);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<Header
|
|
v-if="tabs.length > 0"
|
|
:change-tab="changeTab"
|
|
:loop="tabs.length"
|
|
:add-data="addData"
|
|
:FileDownload="FileDownload"
|
|
/>
|
|
|
|
<q-tab-panels
|
|
v-model="tab"
|
|
animated
|
|
swipeable
|
|
vertical
|
|
transition-prev="jump-up"
|
|
transition-next="jump-up"
|
|
v-if="tabs.length > 0"
|
|
class="mt"
|
|
>
|
|
<q-tab-panel
|
|
v-for="item in probationStore.evaluate"
|
|
:name="`save${item.no}`"
|
|
:key="item.no"
|
|
>
|
|
<FormEvaluate
|
|
:tab="tab"
|
|
:data="probationStore.evaluate.find((x: any) => x.no === dataArrayNumber)"
|
|
action="edit"
|
|
/>
|
|
</q-tab-panel>
|
|
</q-tab-panels>
|
|
|
|
<div v-else class="q-gutter-md">
|
|
<div class="flex justify-center items-center q-my-md q-gutter-md">
|
|
<q-btn
|
|
v-if="!checkRoutePermisson"
|
|
outline
|
|
color="primary"
|
|
label="สร้างแบบประเมิน"
|
|
@click="addData"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<style lang="scss" scoped>
|
|
.mt {
|
|
margin-top: 25px;
|
|
}
|
|
</style>
|