hrms-user/src/modules/08_KPI/components/Tab/Dialog/DialogCommentProblem.vue
2024-05-13 18:00:40 +07:00

511 lines
18 KiB
Vue

<script setup lang="ts">
import { ref, watch, onMounted, reactive } from "vue";
import DialogHeader from "@/components/DialogHeader.vue";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";
import type {
FormComment,
FormCommentByRole,
} from "@/modules/08_KPI/interface/request/index";
import { useRoute } from "vue-router";
import { useQuasar } from "quasar";
const $q = useQuasar();
const route = useRoute();
const id = ref<string>(route.params.id as string);
const mixin = useCounterMixin();
const {
dialogConfirm,
showLoader,
hideLoader,
messageError,
dialogMessageNotify,
success,
} = mixin;
const modal = defineModel<boolean>("modal", { required: true });
const type = defineModel<string>("type", { required: true });
const idList = defineModel<string>("idList", { required: true });
const modalAdd = ref<boolean>(false);
const splitterModel = ref<number>(40);
const listTarget = ref<any>([]);
const listCheck = ref<string>("");
const reasonEvaluator = ref<string>(""); //ผู้ประเมิน
const reasonCommander = ref<string>(""); //ผู้บังคับบัญชาเหนือขึ้นไป
const reasonCommanderHigh = ref<string>(""); //ผู้บังคับบัญชาเหนือขึ้นไปอีกขั้นหนึ่ง
const reasonEvaluatorRef = ref<any>();
const reasonCommanderRef = ref<any>();
const reasonCommanderHighRef = ref<any>();
const sendType = ref<string>("");
const formDataAdd = reactive<FormComment>({
topic: "",
reason: "",
});
const formDataView = reactive<FormCommentByRole>({
id: "",
topic: "",
reason: "",
reasonEvaluator: "",
reasonCommander: "",
reasonCommanderHigh: "",
});
let count = ref<number>(0);
function clickList(index: string, data: any) {
listCheck.value = index as string;
formDataView.id = data.id;
formDataView.topic = data.topic;
formDataView.reason = data.reason;
formDataView.reasonEvaluator = data.reasonEvaluator;
formDataView.reasonCommander = data.reasonCommander;
formDataView.reasonCommanderHigh = data.reasonCommanderHigh;
reasonEvaluator.value = data.reasonEvaluator ?? "";
reasonCommander.value = data.reasonCommander ?? "";
reasonCommanderHigh.value = data.reasonCommanderHigh ?? "";
if (count.value >= 1) {
reasonEvaluatorRef.value.reset();
reasonCommanderRef.value.reset();
reasonCommanderHighRef.value.reset();
}
count.value++;
showLoader();
setTimeout(() => {
hideLoader();
}, 100);
}
function onSubmitAdd() {
dialogConfirm($q, () => {
showLoader();
http
.put(
config.API.kpiCommentP("problem", type.value+sendType.value, "user", idList.value),
{
reason: formDataAdd.reason,
topic: formDataAdd.topic,
}
)
.then((res) => {
console.log(res.data);
success($q, "บันทึกข้อมูลสำเร็จ");
getList();
closeAdd();
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
function onSubmit() {}
function close() {
count.value = 0;
modal.value = false;
reasonEvaluator.value = "";
reasonCommander.value = "";
reasonCommanderHigh.value = "";
listTarget.value = [];
listCheck.value = "";
}
function closeAdd() {
modalAdd.value = false;
formDataAdd.topic = "";
formDataAdd.reason = "";
}
function getList() {
showLoader();
http
.get(config.API.kpiCommentP("problem", type.value, "user", idList.value))
.then((res) => {
const data = res.data.result;
listTarget.value = data;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function onSubmitComment(role: string) {
dialogConfirm($q, () => {
const body = {
reason:
role == "evaluator"
? reasonEvaluator.value
: role == "commander"
? reasonCommander.value
: role == "commanderhigh"
? reasonCommanderHigh.value
: null,
};
showLoader();
http
.put(
config.API.kpiCommentP("problem", type.value, role, formDataView.id),
body
)
.then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ");
getList();
setTimeout(() => {
if (listCheck.value) {
const idCheck = listCheck.value;
const data = listTarget.value.find(
(item: any) => item.id == idCheck
);
clickList(idCheck, data);
}
}, 200);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
});
}
watch(
() => modal.value,
() => {
if (modal.value == true) {
getList();
}
}
);
</script>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 70vw">
{{ type }}
<q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader tittle="รายงานปัญหา" :close="close" />
<q-separator />
<q-card-section class="q-pa-none">
<q-splitter
v-model="splitterModel"
disable
separator-class="bg-gray"
separator-style="width: 1px"
>
<template v-slot:before>
<div class="q-pa-sm">
<q-btn
icon="add"
color="teal"
flat
round
@click="
() => {
modalAdd = true;
}
"
>
<q-tooltip>เพมหวขอรายงานปญหา</q-tooltip>
</q-btn>
<q-card bordered flat class="no-shadow bg-white col-12">
<div class="row q-px-md q-py-sm items-center bg-grey-1">
<div class="col-12">
<span>วขอปญหา</span>
</div>
</div>
<q-separator />
<q-card-section class="q-pa-none">
<div v-if="listTarget.length > 0">
<q-list separator dense>
<q-item
v-for="(item, index) in listTarget"
:key="item.id"
clickable
v-ripple
:active="listCheck === item.id"
active-class="my-menu-link"
@click="clickList(item.id, item)"
>
<q-item-section class="q-pa-none">
<div class="row items-center">
<div class="col-12">
<span>{{ item.topic }}</span>
</div>
</div>
</q-item-section>
</q-item>
</q-list>
</div>
<div v-else class="q-pa-md">
<span>ไมพบขอม</span>
</div>
</q-card-section>
</q-card>
</div>
</template>
<template v-slot:after>
<div
v-if="!listCheck"
class="row col-12 items-center"
style="height: 30vh"
>
<q-banner class="q-pa-lg col-12 text-center">
<q-icon
name="mdi-hand-pointing-left"
size="lg"
color="primary"
/>
<p class="text-grey-9 q-pt-sm">
กรณาเลอกหวขอรายงานปญหา
</p>
</q-banner>
</div>
<div v-else>
<div class="row q-pa-md q-col-gutter-sm">
<div class="row col-12 text-weight-medium">
<div class="col-4 text-grey-6">วขอรายงานปญหา</div>
<div class="col-8">{{ formDataView.topic }}</div>
</div>
<div class="row col-12 text-weight-medium">
<div class="col-4 text-grey-6">รายละเอยดรายงานปญหา</div>
<div class="col-8">{{ formDataView.reason }}</div>
</div>
<div class="col-12">
<q-separator />
</div>
<!-- ความคดเหนของผประเม -->
<q-form
ref="reasonEvaluatorRef"
greedy
@submit.prevent
@validation-success="onSubmitComment('evaluator')"
class="full-width"
>
<div class="row col-12 q-col-gutter-sm">
<div class="col-12">
<span class="text-weight-medium text-grey-6"
>ความคดเหนของผประเม</span
>
</div>
<div class="col-12">
<q-input
outlined
dense
:readonly="formDataView.reasonEvaluator !== null"
label="ความคิดเห็นของผู้ประเมิน"
v-model="reasonEvaluator"
type="textarea"
class="inputgreen"
lazy-rules
hide-bottom-space
:rules="[(val:string) => !!val || `${'กรุณากรอกความคิดเห็นของผู้ประเมิน'}`,]"
></q-input>
</div>
<div
v-if="formDataView.reasonEvaluator == null"
class="col-12"
align="right"
>
<q-btn
label="บันทึกและส่งให้ผู้บังคับ"
color="secondary"
type="submit"
><q-tooltip
>นทกและสงใหงค</q-tooltip
></q-btn
>
</div>
</div>
</q-form>
<!-- ความคดเหนของผงคบบญชาเหนอขนไป -->
<q-form
class="full-width"
ref="reasonCommanderRef"
greedy
@submit.prevent
@validation-success="onSubmitComment('commander')"
>
<div class="row col-12 q-col-gutter-sm">
<div class="col-12">
<span class="text-weight-medium text-grey-6"
>ความคดเหนของผงคบบญชาเหนอขนไป
(ามงคบบญชาเหนอขนไป)</span
>
</div>
<div class="col-12">
<q-input
outlined
dense
label="ความคิดเห็นของผู้บังคับบัญชาเหนือขึ้นไป"
v-model="reasonCommander"
type="textarea"
class="inputgreen"
lazy-rules
:readonly="formDataView.reasonCommander !== null"
hide-bottom-space
:rules="[(val:string) => !!val || `${'กรุณากรอกความคิดเห็นของผู้บังคับบัญชาเหนือขึ้นไป'}`,]"
></q-input>
</div>
<div
v-if="formDataView.reasonCommander == null"
class="col-12"
align="right"
>
<q-btn label="บันทึก" color="secondary" type="submit"
><q-tooltip>นท</q-tooltip></q-btn
>
</div>
</div>
</q-form>
<q-form
class="full-width"
ref="reasonCommanderHighRef"
greedy
@submit.prevent
@validation-success="onSubmitComment('commanderhigh')"
>
<div class="row col-12 q-col-gutter-sm">
<div class="col-12">
<span class="text-weight-medium text-grey-6"
>ความคดเหนของผงคบบญชาเหนอขนไปอกขนหน
(ามงคบบญชาเหนอขนไปอกขนหน)</span
>
</div>
<div class="col-12">
<q-input
outlined
dense
label="ความคิดเห็นของผู้บังคับบัญชาเหนือขึ้นไปอีกขั้นหนึ่ง"
v-model="reasonCommanderHigh"
type="textarea"
class="inputgreen"
lazy-rules
:readonly="formDataView.reasonCommanderHigh !== null"
hide-bottom-space
:rules="[(val:string) => !!val || `${'กรุณากรอกความคิดเห็นของผู้บังคับบัญชาเหนือขึ้นไปอีกขั้นหนึ่ง'}`,]"
></q-input>
</div>
<div
v-if="formDataView.reasonCommanderHigh == null"
class="col-12"
align="right"
>
<q-btn label="บันทึก" color="secondary" type="submit"
><q-tooltip>นท</q-tooltip></q-btn
>
</div>
</div>
</q-form>
</div>
</div>
</template>
</q-splitter>
</q-card-section>
</q-form>
</q-card>
</q-dialog>
<q-dialog v-model="modalAdd" persistent>
<q-card style="min-width: 30vw">
<q-form greedy @submit.prevent @validation-success="onSubmitAdd">
<DialogHeader tittle="เพิ่มหัวข้อรายงานปัญหา" :close="closeAdd" />
<q-separator />
<q-card-section>
<div class="row q-col-gutter-sm">
<div class="col-12">
<q-input
v-model="formDataAdd.topic"
outlined
class="inputgreen"
label="หัวข้อรายงานปัญหา"
dense
lazy-rules
hide-bottom-space
:rules="[(val:string) => !!val || `${'กรุณากรอกหัวข้อรายงานปัญหา'}`,]"
/>
</div>
<div class="col-12">
<q-input
v-model="formDataAdd.reason"
outlined
class="inputgreen"
label="รายละเอียดปัญหา"
dense
lazy-rules
hide-bottom-space
:rules="[(val:string) => !!val || `${'กรุณากรอกรายละเอียดปัญหา'}`,]"
type="textarea"
/>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right" class="bg-white text-teal">
<q-btn
label="บันทึกแบบร่าง"
color="info"
type="submit"
@click="
() => {
sendType = '';
}
"
><q-tooltip>นทกแบบราง</q-tooltip></q-btn
>
<q-btn
label="ส่งไปยังผู้ประเมิน"
color="secondary"
type="submit"
@click="
() => {
sendType = 'send';
}
"
><q-tooltip>งไปยงผประเม</q-tooltip></q-btn
>
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>
<style scoped>
.border-right {
border-right: 1px solid #000;
}
.my-menu-link {
background: #ebf9f7 !important;
color: #1bb19ab8 !important;
}
</style>