fix: ตัวแปร ค้นหาขั้นสูง เก็บใน store

This commit is contained in:
setthawutttty 2025-07-18 10:04:14 +07:00
parent 3a7cfad344
commit 9dcb54a384
8 changed files with 330 additions and 384 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, reactive } from "vue";
import { ref, reactive, watchEffect } from "vue";
import { useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
@ -26,36 +26,6 @@ const modal = ref<boolean>(false);
/** เปิด popup ค้นหาขั้นสูง */
function onSearch() {
modal.value = true;
formComplaint.dateReceived = null;
formComplaint.respondentType = "";
formComplaint.offenseDetails = "";
formComplaint.levelConsideration = "";
formComplaint.dateConsideration = null;
formInvestigateFacts.respondentType = "";
formInvestigateFacts.offenseDetails = "";
formInvestigateFacts.investigationDetail = "";
formInvestigateFacts.investigationDate = null;
formInvestigateFacts.dateReceived = null;
formInvestigateFacts.investigationStatusResult = "";
formInvestigateDisciplinary.respondentType = "";
formInvestigateDisciplinary.offenseDetails = "";
formInvestigateDisciplinary.disciplinaryFaultLevel = "";
formInvestigateDisciplinary.disciplinaryCaseFault = "";
formInvestigateDisciplinary.disciplinaryDate = null;
formInvestigateDisciplinary.dateReceived = null;
formResult.respondentType = "";
formResult.offenseDetails = "";
formResult.disciplinaryFaultLevel = "";
formResult.disciplinaryCaseFault = "";
formResult.disciplinaryDate = null;
formResult.resultDisciplineType = "";
formResult.resultTitleType = "";
formResult.resultOc = "";
formResult.resultYear = null;
}
/** ปิด popup ค้นหาขั้นสูง */
@ -63,179 +33,46 @@ function onClose() {
modal.value = false;
}
/** ตัวแปร ค้นหาขั้นสูง เรื่องร้องเรียน*/
const formComplaint = reactive<{
dateReceived: [Date, Date] | null;
respondentType: string;
offenseDetails: string;
levelConsideration: string;
dateConsideration: [Date, Date] | null;
}>({
dateReceived: null, // [0] - [1]
respondentType: "", //
offenseDetails: "", //
levelConsideration: "", //
dateConsideration: null, // [0] - [1]
});
const formInvestigateFacts = reactive<{
respondentType: string;
offenseDetails: string;
investigationDetail: string;
investigationDate: [Date, Date] | null;
dateReceived: [Date, Date] | null;
investigationStatusResult: string;
}>({
respondentType: "", //
offenseDetails: "", //
investigationDetail: "", //
investigationDate: null, // [0] - [1]
dateReceived: null, // [0] - [1]
investigationStatusResult: "", //
});
const formInvestigateDisciplinary = reactive<{
respondentType: string;
offenseDetails: string;
disciplinaryFaultLevel: string;
disciplinaryCaseFault: string;
disciplinaryDate: [Date, Date] | null;
dateReceived: [Date, Date] | null;
}>({
respondentType: "", //
offenseDetails: "", //
disciplinaryFaultLevel: "", //
disciplinaryCaseFault: "", //
disciplinaryDate: null, // [0]-[1]
dateReceived: null, // [0]-[1]
});
const formResult = reactive<{
respondentType: string;
offenseDetails: string;
disciplinaryFaultLevel: string;
disciplinaryCaseFault: string;
disciplinaryDate: [Date, Date] | null;
resultDisciplineType: string;
resultTitleType: string;
resultOc: string;
resultYear: number | null;
}>({
respondentType: "", //
offenseDetails: "", //
disciplinaryFaultLevel: "", //
disciplinaryCaseFault: "", //
disciplinaryDate: null, // [0]-[1]
resultDisciplineType: "", // input
resultTitleType: "", //
resultOc: "", // /
resultYear: null, //
});
/** fn ค้นหาขั้นสูง */
function complaintBody() {
return {
dateReceivedStart: formComplaint.dateReceived?.[0]
? convertDateToAPI(formComplaint.dateReceived[0])
: null,
dateReceivedEnd: formComplaint.dateReceived?.[1]
? convertDateToAPI(formComplaint.dateReceived[1])
: null,
respondentType: formComplaint.respondentType,
offenseDetails: formComplaint.offenseDetails,
levelConsideration: formComplaint.levelConsideration,
dateConsiderationStart: formComplaint.dateConsideration?.[0]
? convertDateToAPI(formComplaint.dateConsideration[0])
: null,
dateConsiderationEnd: formComplaint.dateConsideration?.[1]
? convertDateToAPI(formComplaint.dateConsideration[1])
: null,
};
}
function investigateFactsBody() {
return {
respondentType: formInvestigateFacts.respondentType,
offenseDetails: formInvestigateFacts.offenseDetails,
investigationDetail: formInvestigateFacts.investigationDetail,
investigationDateStart: formInvestigateFacts.investigationDate?.[0]
? convertDateToAPI(formInvestigateFacts.investigationDate[0])
: null,
investigationDateEnd: formInvestigateFacts.investigationDate?.[1]
? convertDateToAPI(formInvestigateFacts.investigationDate[1])
: null,
dateReceivedStart: formInvestigateFacts.dateReceived?.[0]
? convertDateToAPI(formInvestigateFacts.dateReceived[0])
: null,
dateReceivedEnd: formInvestigateFacts.dateReceived?.[1]
? convertDateToAPI(formInvestigateFacts.dateReceived[1])
: null,
investigationStatusResult: formInvestigateFacts.investigationStatusResult,
};
}
function disciplinaryBody() {
return {
respondentType: formInvestigateDisciplinary.respondentType,
offenseDetails: formInvestigateDisciplinary.offenseDetails,
disciplinaryFaultLevel: formInvestigateDisciplinary.disciplinaryFaultLevel,
disciplinaryCaseFault:
formInvestigateDisciplinary.disciplinaryCaseFault.trim(),
disciplinaryDateStart: formInvestigateDisciplinary.disciplinaryDate?.[0]
? convertDateToAPI(formInvestigateDisciplinary.disciplinaryDate[0])
: null,
disciplinaryDateEnd: formInvestigateDisciplinary.disciplinaryDate?.[1]
? convertDateToAPI(formInvestigateDisciplinary.disciplinaryDate[1])
: null,
dateReceivedStart: formInvestigateDisciplinary.dateReceived?.[0]
? convertDateToAPI(formInvestigateDisciplinary.dateReceived[0])
: null,
dateReceivedEnd: formInvestigateDisciplinary.dateReceived?.[1]
? convertDateToAPI(formInvestigateDisciplinary.dateReceived[1])
: null,
};
}
function resultBody() {
return {
respondentType: formResult.respondentType,
offenseDetails: formResult.offenseDetails,
disciplinaryFaultLevel: formResult.disciplinaryFaultLevel,
disciplinaryCaseFault: formResult.disciplinaryCaseFault.trim(),
disciplinaryDateStart: formResult.disciplinaryDate?.[0]
? convertDateToAPI(formResult.disciplinaryDate[0])
: null,
disciplinaryDateEnd: formResult.disciplinaryDate?.[1]
? convertDateToAPI(formResult.disciplinaryDate[1])
: null,
resultDisciplineType: formResult.resultDisciplineType.trim(),
resultTitleType: formResult.resultTitleType.trim(),
resultOc: formResult.resultOc.trim(),
resultYear: formResult.resultYear,
};
}
function fnSearch() {
let body: any;
switch (route.name) {
case "disciplineComplaints":
body = complaintBody();
break;
case "disciplineInvestigatefacts":
body = investigateFactsBody();
break;
case "disciplineDisciplinary":
body = disciplinaryBody();
break;
case "disciplineResult":
body = resultBody();
break;
}
props.getData?.(body);
props.getData?.(1);
onClose();
}
function resetForms() {
store.formComplaint.dateReceived = null;
store.formComplaint.respondentType = "";
store.formComplaint.offenseDetails = "";
store.formComplaint.levelConsideration = "";
store.formComplaint.dateConsideration = null;
store.formInvestigateFacts.respondentType = "";
store.formInvestigateFacts.offenseDetails = "";
store.formInvestigateFacts.investigationDetail = "";
store.formInvestigateFacts.investigationDate = null;
store.formInvestigateFacts.dateReceived = null;
store.formInvestigateFacts.investigationStatusResult = "";
store.formInvestigateDisciplinary.respondentType = "";
store.formInvestigateDisciplinary.offenseDetails = "";
store.formInvestigateDisciplinary.disciplinaryFaultLevel = "";
store.formInvestigateDisciplinary.disciplinaryCaseFault = "";
store.formInvestigateDisciplinary.disciplinaryDate = null;
store.formInvestigateDisciplinary.dateReceived = null;
store.formResult.respondentType = "";
store.formResult.offenseDetails = "";
store.formResult.disciplinaryFaultLevel = "";
store.formResult.disciplinaryCaseFault = "";
store.formResult.disciplinaryDate = null;
store.formResult.resultDisciplineType = "";
store.formResult.resultTitleType = "";
store.formResult.resultOc = "";
store.formResult.resultYear = null;
}
watchEffect(() => {
resetForms();
});
</script>
<template>
<div>
@ -262,7 +99,7 @@ function fnSearch() {
>
<div class="col-12">
<datepicker
v-model="formComplaint.dateReceived"
v-model="store.formComplaint.dateReceived"
:locale="'th'"
autoApply
borderless
@ -284,8 +121,8 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formComplaint.dateReceived != null
? dateThaiRange(formComplaint.dateReceived)
store.formComplaint.dateReceived != null
? dateThaiRange(store.formComplaint.dateReceived)
: null
"
:label="`${'วันที่รับเรื่องเริ่มต้น-สิ้นสุด'}`"
@ -300,10 +137,12 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formComplaint.dateReceived !== null"
v-if="store.formComplaint.dateReceived !== null"
name="clear"
class="cursor-pointer"
@click.prevent.stop="formComplaint.dateReceived = null"
@click.prevent.stop="
store.formComplaint.dateReceived = null
"
>
</q-icon>
</template>
@ -313,7 +152,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formComplaint.respondentType"
v-model="store.formComplaint.respondentType"
:options="store.complainantoptionsMain"
option-label="name"
option-value="id"
@ -328,7 +167,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formComplaint.offenseDetails"
v-model="store.formComplaint.offenseDetails"
:options="store.offenseDetailstOptions"
option-label="name"
option-value="id"
@ -343,7 +182,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formComplaint.levelConsideration"
v-model="store.formComplaint.levelConsideration"
:options="complainstStore.levelConsiderationtOptions"
option-label="name"
option-value="id"
@ -358,7 +197,7 @@ function fnSearch() {
</div>
<div class="col-12">
<datepicker
v-model="formComplaint.dateConsideration"
v-model="store.formComplaint.dateConsideration"
:locale="'th'"
autoApply
borderless
@ -379,8 +218,8 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formComplaint.dateConsideration != null
? dateThaiRange(formComplaint.dateConsideration)
store.formComplaint.dateConsideration != null
? dateThaiRange(store.formComplaint.dateConsideration)
: null
"
:label="`${'วันที่เริ่มต้น-สิ้นสุดการพิจารณา'}`"
@ -395,11 +234,11 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formComplaint.dateConsideration !== null"
v-if="store.formComplaint.dateConsideration !== null"
name="clear"
class="cursor-pointer"
@click.prevent.stop="
formComplaint.dateConsideration = null
store.formComplaint.dateConsideration = null
"
>
</q-icon>
@ -416,7 +255,7 @@ function fnSearch() {
>
<div class="col-12">
<q-select
v-model="formInvestigateFacts.respondentType"
v-model="store.formInvestigateFacts.respondentType"
:options="store.complainantoptionsMain"
option-label="name"
option-value="id"
@ -431,7 +270,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formInvestigateFacts.offenseDetails"
v-model="store.formInvestigateFacts.offenseDetails"
:options="store.offenseDetailstOptions"
option-label="name"
option-value="id"
@ -446,7 +285,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formInvestigateFacts.investigationDetail"
v-model="store.formInvestigateFacts.investigationDetail"
:options="investigateStore.investigationDetailOp"
option-label="name"
option-value="id"
@ -462,7 +301,7 @@ function fnSearch() {
<div class="col-12">
<datepicker
v-model="formInvestigateFacts.investigationDate"
v-model="store.formInvestigateFacts.investigationDate"
:locale="'th'"
autoApply
borderless
@ -483,8 +322,10 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formInvestigateFacts.investigationDate != null
? dateThaiRange(formInvestigateFacts.investigationDate)
store.formInvestigateFacts.investigationDate != null
? dateThaiRange(
store.formInvestigateFacts.investigationDate
)
: null
"
:label="`${'วันที่สืบสวนเริ่มต้น-สิ้นสุด'}`"
@ -499,11 +340,13 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formInvestigateFacts.investigationDate !== null"
v-if="
store.formInvestigateFacts.investigationDate !== null
"
name="clear"
class="cursor-pointer"
@click.prevent.stop="
formInvestigateFacts.investigationDate = null
store.formInvestigateFacts.investigationDate = null
"
>
</q-icon>
@ -514,7 +357,7 @@ function fnSearch() {
</div>
<div class="col-12">
<datepicker
v-model="formInvestigateFacts.dateReceived"
v-model="store.formInvestigateFacts.dateReceived"
:locale="'th'"
autoApply
borderless
@ -535,8 +378,8 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formInvestigateFacts.dateReceived != null
? dateThaiRange(formInvestigateFacts.dateReceived)
store.formInvestigateFacts.dateReceived != null
? dateThaiRange(store.formInvestigateFacts.dateReceived)
: null
"
:label="`${'วันที่รับเรื่องเริ่มต้น-สิ้นสุด'}`"
@ -551,11 +394,11 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formInvestigateFacts.dateReceived !== null"
v-if="store.formInvestigateFacts.dateReceived !== null"
name="clear"
class="cursor-pointer"
@click.prevent.stop="
formInvestigateFacts.dateReceived = null
store.formInvestigateFacts.dateReceived = null
"
>
</q-icon>
@ -566,7 +409,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formInvestigateFacts.investigationStatusResult"
v-model="store.formInvestigateFacts.investigationStatusResult"
:options="store.statusResultOptions"
option-label="name"
option-value="id"
@ -587,7 +430,7 @@ function fnSearch() {
>
<div class="col-12">
<q-select
v-model="formInvestigateDisciplinary.respondentType"
v-model="store.formInvestigateDisciplinary.respondentType"
:options="store.complainantoptionsMain"
option-label="name"
option-value="id"
@ -602,7 +445,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formInvestigateDisciplinary.offenseDetails"
v-model="store.formInvestigateDisciplinary.offenseDetails"
:options="store.offenseDetailstOptions"
option-label="name"
option-value="id"
@ -617,7 +460,9 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formInvestigateDisciplinary.disciplinaryFaultLevel"
v-model="
store.formInvestigateDisciplinary.disciplinaryFaultLevel
"
:options="InvestigateDisStore.optionsfaultLevel"
option-label="name"
option-value="id"
@ -632,7 +477,9 @@ function fnSearch() {
</div>
<div class="col-12">
<q-input
v-model="formInvestigateDisciplinary.disciplinaryCaseFault"
v-model="
store.formInvestigateDisciplinary.disciplinaryCaseFault
"
dense
outlined
label="กรณีความผิด"
@ -640,7 +487,7 @@ function fnSearch() {
</div>
<div class="col-12">
<datepicker
v-model="formInvestigateDisciplinary.disciplinaryDate"
v-model="store.formInvestigateDisciplinary.disciplinaryDate"
:locale="'th'"
autoApply
borderless
@ -661,9 +508,9 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formInvestigateDisciplinary.disciplinaryDate != null
store.formInvestigateDisciplinary.disciplinaryDate != null
? dateThaiRange(
formInvestigateDisciplinary.disciplinaryDate
store.formInvestigateDisciplinary.disciplinaryDate
)
: null
"
@ -680,12 +527,14 @@ function fnSearch() {
<template v-slot:append>
<q-icon
v-if="
formInvestigateDisciplinary.disciplinaryDate !== null
store.formInvestigateDisciplinary.disciplinaryDate !==
null
"
name="clear"
class="cursor-pointer"
@click.prevent.stop="
formInvestigateDisciplinary.disciplinaryDate = null
store.formInvestigateDisciplinary.disciplinaryDate =
null
"
>
</q-icon>
@ -696,7 +545,7 @@ function fnSearch() {
</div>
<div class="col-12">
<datepicker
v-model="formInvestigateDisciplinary.dateReceived"
v-model="store.formInvestigateDisciplinary.dateReceived"
:locale="'th'"
autoApply
borderless
@ -717,9 +566,9 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formInvestigateDisciplinary.dateReceived != null
store.formInvestigateDisciplinary.dateReceived != null
? dateThaiRange(
formInvestigateDisciplinary.dateReceived
store.formInvestigateDisciplinary.dateReceived
)
: null
"
@ -735,11 +584,14 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formInvestigateDisciplinary.dateReceived !== null"
v-if="
store.formInvestigateDisciplinary.dateReceived !==
null
"
name="clear"
class="cursor-pointer"
@click.prevent.stop="
formInvestigateDisciplinary.dateReceived = null
store.formInvestigateDisciplinary.dateReceived = null
"
>
</q-icon>
@ -755,7 +607,7 @@ function fnSearch() {
>
<div class="col-12">
<q-select
v-model="formResult.respondentType"
v-model="store.formResult.respondentType"
:options="store.complainantoptionsMain"
option-label="name"
option-value="id"
@ -770,7 +622,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formResult.offenseDetails"
v-model="store.formResult.offenseDetails"
:options="store.offenseDetailstOptions"
option-label="name"
option-value="id"
@ -785,7 +637,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-select
v-model="formResult.disciplinaryFaultLevel"
v-model="store.formResult.disciplinaryFaultLevel"
:options="InvestigateDisStore.optionsfaultLevel"
option-label="name"
option-value="id"
@ -800,7 +652,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-input
v-model="formResult.disciplinaryCaseFault"
v-model="store.formResult.disciplinaryCaseFault"
dense
outlined
label="กรณีความผิด"
@ -808,7 +660,7 @@ function fnSearch() {
</div>
<div class="col-12">
<datepicker
v-model="formResult.disciplinaryDate"
v-model="store.formResult.disciplinaryDate"
:locale="'th'"
autoApply
borderless
@ -829,8 +681,8 @@ function fnSearch() {
dense
class="full-width datepicker"
:model-value="
formResult.disciplinaryDate != null
? dateThaiRange(formResult.disciplinaryDate)
store.formResult.disciplinaryDate != null
? dateThaiRange(store.formResult.disciplinaryDate)
: null
"
:label="`${'วันที่สอบสวนเริ่มต้น-สิ้นสุด'}`"
@ -845,10 +697,12 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formResult.disciplinaryDate !== null"
v-if="store.formResult.disciplinaryDate !== null"
name="clear"
class="cursor-pointer"
@click.prevent.stop="formResult.disciplinaryDate = null"
@click.prevent.stop="
store.formResult.disciplinaryDate = null
"
>
</q-icon>
</template>
@ -858,7 +712,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-input
v-model="formResult.resultDisciplineType"
v-model="store.formResult.resultDisciplineType"
dense
outlined
label="ประเภทวินัย"
@ -866,7 +720,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-input
v-model="formResult.resultTitleType"
v-model="store.formResult.resultTitleType"
dense
outlined
label="ประเภทของเรื่อง"
@ -874,7 +728,7 @@ function fnSearch() {
</div>
<div class="col-12">
<q-input
v-model="formResult.resultOc"
v-model="store.formResult.resultOc"
dense
outlined
label="หน่วยงาน/ส่วนราชการ"
@ -882,7 +736,7 @@ function fnSearch() {
</div>
<div class="col-12">
<datepicker
v-model="formResult.resultYear"
v-model="store.formResult.resultYear"
class="col-2"
:locale="'th'"
autoApply
@ -898,9 +752,9 @@ function fnSearch() {
dense
outlined
:model-value="
formResult.resultYear === null
store.formResult.resultYear === null
? null
: Number(formResult.resultYear) + 543
: Number(store.formResult.resultYear) + 543
"
:label="`${'ปีงบประมาณ'}`"
>
@ -914,10 +768,10 @@ function fnSearch() {
</template>
<template v-slot:append>
<q-icon
v-if="formResult.resultYear !== null"
v-if="store.formResult.resultYear !== null"
name="clear"
class="cursor-pointer"
@click.prevent.stop="formResult.resultYear = null"
@click.prevent.stop="store.formResult.resultYear = null"
>
</q-icon>
</template>