hrms-mgt/src/modules/11_discipline/components/1_Complaint/AddComplaintPage.vue

619 lines
22 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
// import Type
import type { DataOption } from "@/modules/11_discipline/interface/index/Main";
import type {
FormData,
MyObjectComplaintsRef,
} from "@/modules/11_discipline/interface/request/complaint";
// importStroe
import { useCounterMixin } from "@/stores/mixin";
import { useComplainstDataStore } from "@/modules/11_discipline/store/ComplaintsStore";
const $q = useQuasar();
const router = useRouter();
const mixin = useCounterMixin();
const { date2Thai, dialogConfirm } = mixin; //function จาก stores หลัก
const complainstStore = useComplainstDataStore();
const { selectComplainantTpye, filterSelector, fetchOptioin } = complainstStore; // function จาก store complainstStore
// options ทั้งหมด
const complainantoptions = ref<DataOption[]>([
{ id: "0", name: "บุคคล" },
{ id: "1", name: "หน่ายงาน" },
{ id: "2", name: "กรุงเทพหมานคร" },
]);
const agencytoptions = ref<DataOption[]>([
{ id: "0", name: "หน่ายงานเอ" },
{ id: "1", name: "หน่ายงานบี" },
{ id: "2", name: "หน่ายงานชี" },
]);
const offenseDescriptiontoptions = ref<DataOption[]>([
{ id: "0", name: "ยังไม่ระบุ" },
{ id: "1", name: "ไม่ร้ายแรง" },
{ id: "2", name: "ร้ายแรง" },
]);
const considerationLeveltoptions = ref<DataOption[]>([
{ id: "0", name: "ปกติ" },
{ id: "1", name: "ด่วน" },
{ id: "2", name: "ด่วนมาก" },
]);
const receivecomplaintstoptions = ref<DataOption[]>([
{ id: "0", name: "สตง" },
{ id: "1", name: "ปปช" },
{ id: "2", name: "ปปท" },
{ id: "3", name: "จดหมาย" },
{ id: "4", name: "อีเมล" },
{ id: "5", name: "โทรศัพท์" },
{ id: "6", name: "บอกกล่าว" },
]);
// ข้อมูล form
const formData = reactive<FormData>({
complainantType: "",
complainant: "",
office: "",
agency: "",
topicComplaint: "",
detail: "",
datereceive: null,
dateconsideration: null,
offenseDescription: "",
considerationLevel: "",
datewarn: null,
receivecomplaints: "",
petitioner: "",
files: null,
});
const fileDocDataUpload = ref<File[]>([]);
onMounted(() => {
fetchOptioin(complainantoptions.value, agencytoptions.value);
});
// เลือกผู้ร้องเรียน
async function selectComplainant(val: string) {
formData.complainant = "";
formData.office = "";
formData.agency = "";
if (val === "0") {
await fetchListname(); // ถ้าเลือกบุกคลจะเรียก function fetchListname เรียกรายชื่อจากทะเบียน
} else if (val === "1") {
await fetchOffice(); // ถ้าเลือกหน่วยงานจะเรียก function fetchOffice เรียกโครงสร้างสำนักงาน
}
}
// เรียกรายชื่อ
async function fetchListname() {
const listName = [
{
id: "1",
name: "นายเอ",
},
{
id: "2",
name: "นายบี",
},
{
id: "3",
name: "นายชี",
},
];
selectComplainantTpye(listName);
}
// เรียกโครงสร้างสำนักงาน
async function fetchOffice() {
// const listOffice = [
// {
// id: "1",
// name: "สำนักเอ",
// },
// {
// id: "2",
// name: "สำนักเอ",
// },
// {
// id: "3",
// name: "สำนักเอ",
// },
// ];
}
// อัพโหลดไฟล์
const fileUploadDoc = async (files: any) => {
files.forEach((file: any) => {
fileDocDataUpload.value.push(file);
});
};
// เลือกระดับการพิจารณา
function selectLevel(val: string) {
let dayNum = 0;
if (val == "3") {
dayNum = 15; // ด่วนมาก
} else if (val == "1") {
dayNum = 30; // ด่วน
} else {
dayNum = 45; // ปกติ
}
// วันแจ้งเตือนล่วงหน้า
if (formData.dateconsideration) {
const currentDate = new Date(formData.dateconsideration);
const newDate = new Date(
currentDate.getTime() + dayNum * 24 * 60 * 60 * 1000
);
formData.datewarn = newDate;
}
}
// validateForm
const complainantTypeRef = ref<Object | null>(null);
const complainantRef = ref<Object | null>(null);
const officeRef = ref<Object | null>(null);
const agencyRef = ref<Object | null>(null);
const topicComplaintRef = ref<Object | null>(null);
const detailRef = ref<Object | null>(null);
const datereceiveRef = ref<Object | null>();
const dateconsiderationRef = ref<Object | null>(null);
const offenseDescriptionRef = ref<Object | null>(null);
const considerationLevelRef = ref<Object | null>(null);
const datewarnRef = ref<Object | null>(null);
const receivecomplaintsRef = ref<Object | null>(null);
const petitionerRef = ref<Object | null>(null);
const filesRef = ref<Object | null>(null);
const objectComplaintsRef: MyObjectComplaintsRef = {
complainantType: complainantTypeRef,
complainant: complainantRef,
office: officeRef,
agency: agencyRef,
topicComplaint: topicComplaintRef,
detail: detailRef,
datereceive: datereceiveRef,
dateconsideration: dateconsiderationRef,
offenseDescription: offenseDescriptionRef,
considerationLevel: considerationLevelRef,
datewarn: datewarnRef,
receivecomplaints: receivecomplaintsRef,
petitioner: petitionerRef,
files: filesRef,
};
function validateForm() {
const hasError = [];
for (const key in objectComplaintsRef) {
if (Object.prototype.hasOwnProperty.call(objectComplaintsRef, key)) {
const property = objectComplaintsRef[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("ไม่ผ่าน ");
}
}
// บันทึกข้อมูล
function onSubmit() {
dialogConfirm(
$q,
async () => {
console.log(formData);
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
<q-btn
for="backMainPageButton"
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.push(`/discipline/complaints`)"
/>
เพมเรองรองเรยน
</div>
<div class="col-12 q-mt-sm">
<q-card flat bordered>
<form @submit.prevent="validateForm">
<div class="col-12 row q-pa-md">
<div
class="col-xs-12 col-sm-12 row q-col-gutter-x-md q-col-gutter-y-xs"
>
<div class="col-xs-12 col-sm-3" id="complainantType">
<q-select
for="SelectcomplainantType"
ref="complainantTypeRef"
dense
outlined
v-model="formData.complainantType"
:options="complainstStore.complainantoptions"
label="ผู้ถูกร้องเรียน"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกผู้ร้องเรียน'}`]"
lazy-rules
@update:model-value="
selectComplainant(formData.complainantType)
"
use-input
@filter="(inputValue: any,
doneFn: Function) => filterSelector(inputValue, doneFn, 'filtercomplainantType'
)"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div
class="col-xs-12 col-sm-3"
id="complainant"
v-if="formData.complainantType === '0'"
>
<q-select
for="selectComplainant"
ref="complainantRef"
dense
outlined
v-model="formData.complainant"
:options="complainstStore.optionListName"
label="รายชื่อจากทะเบียรประวัติ"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกรายชื่อ'}`]"
lazy-rules
use-input
@filter="(inputValue: any,
doneFn: Function) => filterSelector(inputValue, doneFn, 'filtercomplainantOP'
)"
><template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div
class="col-xs-12 col-sm-3"
v-if="formData.complainantType === '1'"
id="office"
>
<q-input
for="inputOffice"
name="office"
ref="officeRef"
dense
outlined
v-model="formData.office"
label="เลือกสำนักงาน"
:rules="[(val) => !!val || `${'กรุณาเลือกสำนักงาน'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-3" id="agency">
<q-select
ref="agencyRef"
for="selectAgency"
dense
outlined
v-model="formData.agency"
:options="complainstStore.agencytoptions"
label="หน่วยงานที่พิจารณา"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกหน่วยงาน'}`]"
lazy-rules
use-input
@filter="(inputValue: any,
doneFn: Function) => filterSelector(inputValue, doneFn, 'filteragencytoptions'
)"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไมอม
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div class="col-xs-12 col-sm-12" id="topicComplaint">
<q-input
for="inputTopicComplaint"
ref="topicComplaintRef"
dense
outlined
v-model="formData.topicComplaint"
:rules="[(val) => !!val || 'กรุณาการข้อมูล']"
lazy-rules
label="เรื่องร้องเรียน"
type="textarea"
rows="5"
/>
</div>
<div class="col-xs-12 col-sm-12" id="detail">
<q-input
for="inputDetail"
ref="detailRef"
dense
outlined
v-model="formData.detail"
:rules="[(val) => !!val || 'กรุณาการข้อมูล']"
lazy-rules
label="รายละเอียดที่เกี่นวข้องกับเรื่องที่ต้องการจะข้อเรียน"
type="textarea"
rows="5"
/>
</div>
<div class="col-xs-12 col-sm-3" id="datereceive">
<datepicker
menu-class-name="modalfix"
v-model="formData.datereceive"
:locale="'th'"
autoApply
borderless
:enableTimePicker="false"
week-start="0"
>
<template #year="{ year }">
{{ year + 543 }}
</template>
<template #year-overlay-value="{ value }">
{{ parseInt(value + 543) }}
</template>
<template #trigger>
<q-input
for="inputDatereceive"
ref="datereceiveRef"
outlined
dense
class="full-width datepicker"
:model-value="
formData.datereceive != null
? date2Thai(formData.datereceive)
: null
"
label="วันที่รับเรื่อง"
:rules="[
(val) => !!val || `${'กรุณาเลือกวันที่รับเรื่อง'}`,
]"
lazy-rules
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<div class="col-xs-12 col-sm-3" id="considerationLevel">
<q-select
for="selectConsiderationLevel"
ref="considerationLevelRef"
dense
outlined
v-model="formData.considerationLevel"
:options="considerationLeveltoptions"
label="ระดับการพิจารณา"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกระดับการพิจารณา'}`]"
lazy-rules
@update:model-value="selectLevel(formData.considerationLevel)"
/>
</div>
<div class="col-xs-12 col-sm-3" id="dateconsideration">
<datepicker
menu-class-name="modalfix"
v-model="formData.dateconsideration"
@update:model-value="selectLevel(formData.considerationLevel)"
:locale="'th'"
autoApply
borderless
:enableTimePicker="false"
week-start="0"
>
<template #year="{ year }">
{{ year + 543 }}
</template>
<template #year-overlay-value="{ value }">
{{ parseInt(value + 543) }}
</template>
<template #trigger>
<q-input
for="inputDateconsideration"
ref="dateconsiderationRef"
outlined
dense
class="full-width datepicker"
:model-value="
formData.dateconsideration != null
? date2Thai(formData.dateconsideration)
: null
"
label="วันที่กำหนดวันพิจารณา"
:rules="[
(val) => !!val || `${'กรุณาเลือกวันที่กำหนดวันพิจารณา'}`,
]"
lazy-rules
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<div class="col-xs-12 col-sm-3" id="offenseDescription">
<q-select
for="selectOffenseDescription"
ref="offenseDescriptionRef"
dense
outlined
v-model="formData.offenseDescription"
:options="offenseDescriptiontoptions"
label="ลักษณะความผิด"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกลักษณะความผิด'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-3" id="datewarn">
<datepicker
menu-class-name="modalfix"
v-model="formData.datewarn"
:locale="'th'"
autoApply
borderless
:enableTimePicker="false"
week-start="0"
>
<template #year="{ year }">
{{ year + 543 }}
</template>
<template #year-overlay-value="{ value }">
{{ parseInt(value + 543) }}
</template>
<template #trigger>
<q-input
for="inputDatewarn"
ref="datewarnRef"
outlined
dense
class="full-width datepicker"
:model-value="
formData.datewarn != null
? date2Thai(formData.datewarn)
: null
"
label="วันที่แจ้งเตือนล่วงหน้า"
:rules="[
(val) =>
!!val || `${'กรุณาเลือกวันที่แจ้งเตือนล่วงหน้า'}`,
]"
lazy-rules
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
>
</q-icon>
</template>
</q-input>
</template>
</datepicker>
</div>
<div class="col-xs-12 col-sm-3" id="receivecomplaints">
<q-select
for="selectReceivecomplaints"
ref="receivecomplaintsRef"
dense
outlined
v-model="formData.receivecomplaints"
:options="receivecomplaintstoptions"
label="รับเรื่องร้องเรียน"
option-value="id"
option-label="name"
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกรับเรื่องร้องเรียน'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-12"></div>
<div class="col-xs-12 col-sm-12" id="petitioner">
<q-input
for="inputPetitioner"
ref="petitionerRef"
dense
outlined
v-model="formData.petitioner"
label="ผู้ร้องเรียน"
:rules="[(val) => !!val || `${'กรุณากรอกข้อมูล'}`]"
lazy-rules
type="textarea"
rows="5"
/>
</div>
<div class="col-xs-12 col-sm-6"></div>
<div class="col-xs-12 col-sm-6" id="files">
<q-file
for="inputFiles"
ref="filesRef"
outlined
dense
v-model="formData.files"
@added="fileUploadDoc"
label="ไฟล์เอกสารหลักฐาน"
hide-bottom-space
lazy-rules
accept=".pdf,.xlsx,.doc"
clearable
:rules="[(val) => !!val || `${'กรุณาเพิ่มไฟล์เอกสารหลักฐาน'}`]"
>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
</q-file>
</div>
</div>
</div>
<q-separator />
<div class="row col-12 q-pa-sm">
<q-space />
<q-btn
for="ButtonOnSubmit"
id="onSubmit"
color="secondary"
label="บันทึก"
type="submit"
><q-tooltip>บทกขอม</q-tooltip></q-btn
>
</div>
</form>
</q-card>
</div>
</template>
<style scoped></style>