2023-11-24 16:52:10 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, onMounted, reactive, watch } from "vue";
|
2023-11-29 13:48:07 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
2023-11-24 16:52:10 +07:00
|
|
|
import { useQuasar, QForm } from "quasar";
|
|
|
|
|
import { useRouter, useRoute } from "vue-router";
|
2023-11-29 13:48:07 +07:00
|
|
|
|
2023-11-24 16:52:10 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
|
import { useInvestigateDisStore } from "@/modules/11_discipline/store/InvestigateDisStore";
|
|
|
|
|
|
|
|
|
|
import type {
|
|
|
|
|
FormData,
|
|
|
|
|
FormRef,
|
|
|
|
|
} from "@/modules/11_discipline/interface/request/result";
|
|
|
|
|
|
|
|
|
|
const investigateDis = useInvestigateDisStore();
|
|
|
|
|
const { fecthDirector } = investigateDis;
|
|
|
|
|
|
|
|
|
|
const mixin = useCounterMixin();
|
2023-11-29 13:48:07 +07:00
|
|
|
const { date2Thai, hideLoader, dialogConfirm, success, messageError } = mixin;
|
2023-11-24 16:52:10 +07:00
|
|
|
const router = useRouter();
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
|
|
|
|
const $q = useQuasar();
|
|
|
|
|
const id = ref<string>(route.params.id as string);
|
|
|
|
|
|
|
|
|
|
/** ตัวแปร ref สำหรับแสดง validate */
|
|
|
|
|
const detailRef = ref<Object | null>(null);
|
|
|
|
|
|
|
|
|
|
/** รับ props มาจากหน้าหลัก */
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
data: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: null,
|
|
|
|
|
},
|
|
|
|
|
onSubmit: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => "",
|
|
|
|
|
},
|
2023-11-29 13:48:07 +07:00
|
|
|
fetchData: {
|
|
|
|
|
type: Function,
|
|
|
|
|
default: () => "",
|
|
|
|
|
},
|
2023-11-24 16:52:10 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** ข้อมูล v-model ของฟอร์ม */
|
|
|
|
|
const formData = reactive<FormData>({
|
2023-11-29 13:48:07 +07:00
|
|
|
resultDescription: "",
|
2023-11-24 16:52:10 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */
|
|
|
|
|
const objectdisciplinary: FormRef = {
|
2023-11-29 13:48:07 +07:00
|
|
|
resultDescription: detailRef,
|
2023-11-24 16:52:10 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** ฟังชั่นตรวจสอบความถูกต้องก่อน บันทึก */
|
|
|
|
|
function validateForm() {
|
|
|
|
|
const hasError = [];
|
|
|
|
|
for (const key in objectdisciplinary) {
|
|
|
|
|
if (Object.prototype.hasOwnProperty.call(objectdisciplinary, key)) {
|
|
|
|
|
const property = objectdisciplinary[key];
|
|
|
|
|
if (property.value && typeof property.value.validate === "function") {
|
|
|
|
|
const isValid = property.value.validate();
|
|
|
|
|
hasError.push(isValid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasError.every((result) => result === true)) {
|
|
|
|
|
onSubmit();
|
|
|
|
|
} else {
|
|
|
|
|
console.log(hasError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ฟังก์ชั่นสำหรับบันทึกข้อมูล ระบบจะแสดง dialog ให้ยืนยันการบันทึก
|
|
|
|
|
* หากยืนยันจะส่งข้อมูลไปบันทึกที่ api
|
|
|
|
|
* หากยกเลิกจะกลับไปหน้าฟอร์ม
|
|
|
|
|
*/
|
|
|
|
|
function onSubmit() {
|
|
|
|
|
dialogConfirm(
|
|
|
|
|
$q,
|
|
|
|
|
async () => {
|
2023-11-29 13:48:07 +07:00
|
|
|
await http
|
|
|
|
|
.put(config.API.listResultById(id.value), formData)
|
|
|
|
|
.then(() => {
|
|
|
|
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(async () => {
|
|
|
|
|
await props.fetchData();
|
|
|
|
|
});
|
2023-11-24 16:52:10 +07:00
|
|
|
},
|
|
|
|
|
"ยืนยันการบันทึกข้อมูล",
|
|
|
|
|
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fetchDatadetail() {
|
2023-11-29 13:48:07 +07:00
|
|
|
formData.resultDescription = props.data.resultDescription;
|
2023-11-24 16:52:10 +07:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* เช็คข้อมูลจาก props
|
|
|
|
|
* เมื่อมีข้อมูล
|
|
|
|
|
* เก็บข้อมูลลง formData
|
|
|
|
|
*/
|
2023-11-29 13:48:07 +07:00
|
|
|
watch(
|
|
|
|
|
() => props.data,
|
|
|
|
|
async () => {
|
|
|
|
|
await fetchDatadetail();
|
|
|
|
|
}
|
|
|
|
|
);
|
2023-11-24 16:52:10 +07:00
|
|
|
|
|
|
|
|
/**เมื่อเริ่มโหลดหน้า
|
|
|
|
|
* ส่งข้อมูลจำลองไปยัง store
|
|
|
|
|
*/
|
2023-11-29 13:48:07 +07:00
|
|
|
onMounted(async () => {});
|
2023-11-24 16:52:10 +07:00
|
|
|
</script>
|
|
|
|
|
<template>
|
|
|
|
|
<div class="col-xs-12 col-sm-12 col-md-11">
|
|
|
|
|
<form @submit.prevent="validateForm">
|
|
|
|
|
<div class="col-12">
|
|
|
|
|
<q-card>
|
|
|
|
|
<div class="col-12 row q-pa-md">
|
|
|
|
|
<div class="col-12 row q-col-gutter-md">
|
|
|
|
|
<q-input
|
|
|
|
|
type="textarea"
|
|
|
|
|
class="col-12"
|
|
|
|
|
dense
|
|
|
|
|
outlined
|
|
|
|
|
ref="detailRef"
|
2023-11-29 13:48:07 +07:00
|
|
|
v-model="formData.resultDescription"
|
2023-11-24 16:52:10 +07:00
|
|
|
for="#detail"
|
|
|
|
|
label="สรุปผลการพิจารณา"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
:rules="[(val) => !!val || `${'กรุณากรอกกรณีมีความผิด'}`]"
|
|
|
|
|
lazy-rules
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<q-separator />
|
|
|
|
|
<div class="row col-12 q-pa-sm">
|
|
|
|
|
<q-space />
|
|
|
|
|
<q-btn
|
|
|
|
|
for="ButtonOnSubmit"
|
|
|
|
|
id="formSubmit"
|
|
|
|
|
color="secondary"
|
|
|
|
|
label="บันทึก"
|
|
|
|
|
type="submit"
|
|
|
|
|
><q-tooltip>บับทึกข้อมูล</q-tooltip></q-btn
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
</q-card>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|