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

918 lines
31 KiB
Vue

<script setup lang="ts">
import { ref, onMounted, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import type { QTableProps } from "quasar";
/** import Type */
import type { DataOption } from "@/modules/11_discipline/interface/index/Main";
import type {
FormData,
MyObjectComplaintsRef,
DataAddRequest,
ArrayPerson,
} from "@/modules/11_discipline/interface/request/complaint";
/** importStroe*/
import { useCounterMixin } from "@/stores/mixin";
import { useComplainstDataStore } from "@/modules/11_discipline/store/ComplaintsStore";
import DialogAddPersonal from "@/components/Dialogs/AddPersonal.vue";
const $q = useQuasar();
const router = useRouter();
const fileDocDataUpload = ref<File[]>([]);
/** เรียกใช้ store */
const mixin = useCounterMixin();
const complainstStore = useComplainstDataStore();
const { date2Thai, dialogConfirm } = mixin;
const { selectComplainantTpye, filterSelector } = complainstStore; // function จาก store complainstStore
/** validateForm */
const respondentTypeRef = ref<Object | null>(null);
const complainantRef = ref<Object | null>(null);
const officeRef = ref<Object | null>(null);
const consideredAgencyRef = ref<Object | null>(null);
const titleRef = ref<Object | null>(null);
const descriptionRef = ref<Object | null>(null);
const dateReceivedRef = ref<Object | null>();
const dateConsiderationRef = ref<Object | null>(null);
const offenseDetailsRef = ref<Object | null>(null);
const levelConsiderationRef = ref<Object | null>(null);
const dateNotificationRef = ref<Object | null>(null);
const complaintFromRef = ref<Object | null>(null);
const appellantRef = ref<Object | null>(null);
const documentFileRef = ref<Object | null>(null);
/** รับ props มาจากหน้าหลัก */
const props = defineProps({
data: {
type: Object,
default: null,
},
onSubmit: {
type: Function,
default: () => "",
},
});
/** ข้อมูล form*/
const personOj = reactive<ArrayPerson>({
idcard: "",
name: "",
position: "",
positionLevel: "",
salary: "",
organization: "",
});
const formData = reactive<FormData>({
respondentType: "",
office: "",
consideredAgency: "",
title: "",
description: "",
dateReceived: null,
dateConsideration: null,
offenseDetails: "",
levelConsideration: "",
dateNotification: null,
complaintFrom: "",
appellant: "",
documentFile: null,
complaintStatus: "",
persons: [personOj],
personId: [],
organizationId: null,
respondentId: [],
});
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */
const objectComplaintsRef: MyObjectComplaintsRef = {
respondentType: respondentTypeRef,
office: officeRef,
consideredAgency: consideredAgencyRef,
title: titleRef,
description: descriptionRef,
dateReceived: dateReceivedRef,
dateConsideration: dateConsiderationRef,
offenseDetails: offenseDetailsRef,
levelConsideration: levelConsiderationRef,
dateNotification: dateNotificationRef,
complaintFrom: complaintFromRef,
appellant: appellantRef,
documentFile: documentFileRef,
};
/** options ทั้งหมด*/
const offenseDetailstoptions = ref<DataOption[]>([
{ id: "NOT_SPECIFIED", name: "ยังไม่ระบุ" },
{ id: "NOT_DEADLY", name: "ไม่ร้ายแรง" },
{ id: "DEADLY", name: "ร้ายแรง" },
]);
const levelConsiderationtoptions = ref<DataOption[]>([
{ id: "NORMAL", name: "ปกติ" },
{ id: "URGENT", name: "ด่วน" },
{ id: "VERY_URGENT", name: "ด่วนมาก" },
]);
const complaintFromtoptions = ref<DataOption[]>([
{ id: "สตง", name: "สตง" },
{ id: "ปปช", name: "ปปช" },
{ id: "ปปท", name: "ปปท" },
{ id: "จดหมาย", name: "จดหมาย" },
{ id: "อีเมล", name: "อีเมล" },
{ id: "โทรศัพท์", name: "โทรศัพท์" },
{ id: "บอกกล่าว", name: "บอกกล่าว" },
]);
/** หัวตาราง */
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "idcard",
align: "left",
label: "เลขบัตรประชาชน",
sortable: true,
field: "idcard",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
align: "left",
label: "ชื่อ - นามสกุล",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "position",
align: "left",
label: "ตำแหน่ง",
sortable: true,
field: "position",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "positionLevel",
align: "left",
label: "ระดับ",
sortable: true,
field: "positionLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "salary",
align: "left",
label: "เงินเดือน",
sortable: true,
field: "salary",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "organization",
align: "left",
label: "หน่วยงาน",
sortable: true,
field: "organization",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/** หัวข้อที่เเสดงในตาราง */
const visibleColumns = ref<string[]>([
"no",
"idcard",
"name",
"position",
"positionLevel",
"salary",
"organization",
]);
/**
* รับค่าผู้ถูกร้องเรียน
* @param val บุคคล หน่วยงาน กทม
*/
async function selectComplainant(val: string) {
formData.office = "";
formData.consideredAgency = "";
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() {}
/**
* ฟังชั่นอัปโหลดไฟล์
* @param documentFile ไฟล์ที่รับมา
*/
async function fileUploadDoc(documentFile: any) {
documentFile.forEach((file: any) => {
fileDocDataUpload.value.push(file);
});
}
/**
* เลือกระดับการพิจารณา
* @param val รับตัวเลข ในรูปแบบ string
*/
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.dateNotification = newDate;
}
}
/** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */
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);
props.onSubmit();
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
/**ชั่งฟังเพิ่มข้อมูล ลง ตาราง */
const modal = ref<boolean>(false);
const toggleModal = () => (modal.value = !modal.value);
async function addPerson() {
const listData: DataAddRequest[] = [
{
id: "001",
idcard: "0000000000001",
name: "นางศิรินภา คงน้อย",
position: "ตำเเหน่ง1",
positionLevel: "level1",
salary: "10000",
organization: "สำนักงาน 1",
},
{
id: "002",
idcard: "0000000000002",
name: "นายแก้ว คำ",
position: "ตำแหน่ง2",
positionLevel: "level2",
salary: "1000",
organization: "สำนักงาน 2",
},
{
id: "003",
idcard: "0000000000003",
name: "นายภัทรานุย คงนอย",
position: "ตำแหน่ง2",
positionLevel: "level3",
salary: "100",
organization: "สำนักงาน 3",
},
];
await complainstStore.fetchComplainstAdd(listData);
toggleModal();
}
/**
* เช็คข้อมูลจาก props
* เมื่อมีข้อมูล
* เก็บข้อมูลลง formData
*/
watch(props.data, async () => {
console.log(props.data.persons);
formData.respondentType = props.data.respondentType;
formData.office = props.data.office;
formData.consideredAgency = props.data.consideredAgency;
formData.title = props.data.title;
formData.description = props.data.description;
formData.dateReceived = props.data.dateReceived;
formData.dateConsideration = props.data.dateConsideration;
formData.offenseDetails = props.data.offenseDetails;
formData.levelConsideration = props.data.levelConsideration;
formData.dateNotification = props.data.dateNotification;
formData.complaintFrom = props.data.complaintFrom;
formData.appellant = props.data.appellant;
formData.documentFile = props.data.documentFile;
formData.complaintStatus = props.data.complaintStatus;
complainstStore.fetchComplainstAdd(props.data.persons);
});
/**
* ฟังชั่น รับค่าจาก คอมโพเเนน
* @param returnData ค่าที่ได้คืนมา
*/
function handleSave(returnData: any) {
console.log("returnData:", returnData);
}
onMounted(() => {
complainstStore.columns = columns.value;
complainstStore.visibleColumns = visibleColumns.value;
});
</script>
<template>
<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-md">
<div class="col-xs-12 col-sm-3" id="respondentType">
<q-select
for="SelectrespondentType"
v-model="formData.respondentType"
ref="respondentTypeRef"
dense
outlined
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
label="ผู้ถูกร้องเรียน"
option-value="id"
option-label="name"
emit-value
use-input
map-options
hide-bottom-space
:options="complainstStore.complainantoptions"
:rules="[(val) => !!val || `${'กรุณาเลือกผู้ร้องเรียน'}`]"
lazy-rules
@update:model-value="selectComplainant(formData.respondentType)"
@filter="(inputValue: any,
doneFn: Function) => filterSelector(inputValue, doneFn, 'filterrespondentType'
)"
>
<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.respondentType === 'ORGANIZATION'"
id="office"
>
<q-select
for="inputOffice"
name="office"
ref="officeRef"
dense
hide-bottom-space
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
outlined
option-label="name"
option-value="id"
emit-value
map-options
v-model="formData.office"
:options="complainstStore.officeOp"
label="เลือกสำนักงาน"
:rules="[(val) => !!val || `${'กรุณาเลือกสำนักงาน'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-3" id="consideredAgency">
<q-select
ref="consideredAgencyRef"
for="selectAgency"
dense
outlined
v-model="formData.consideredAgency"
:options="complainstStore.consideredAgencytoptions"
label="หน่วยงานที่พิจารณา"
option-value="id"
option-label="name"
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
hide-bottom-space
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกหน่วยงาน'}`]"
lazy-rules
use-input
@filter="(inputValue: any,
doneFn: Function) => filterSelector(inputValue, doneFn, 'filterconsideredAgencytoptions'
)"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
ไม่มีข้อมูล
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div class="row col-12" v-if="formData.respondentType === 'PERSON'">
<q-card
bordered
class="row col-12"
style="border: 1px solid #d6dee1"
>
<div
class="col-xs-12 col-sm-12 text-weight-medium bg-grey-1 q-py-xs q-px-md"
>
ผู้ถูกร้องเรียน
<q-btn
v-if="
formData.complaintStatus === 'NEW' ||
formData.complaintStatus === ''
"
size="12px"
flat
round
dense
color="add"
class="q-ml-sm"
@click="toggleModal"
icon="mdi-plus"
>
<q-tooltip>เพิ่มผู้ถูกร้องเรียน</q-tooltip>
</q-btn>
</div>
<div class="col-12"><q-separator /></div>
<div class="col-xs-12 q-pa-sm">
<d-table
ref="table"
:columns="complainstStore.columns"
:rows="complainstStore.rowsAdd"
row-key="interrogated"
flat
bordered
:paging="true"
dense
class="custom-header-table"
:visible-columns="complainstStore.visibleColumns"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
style="color: #000000; font-weight: 500"
>
<span class="text-weight-medium">{{
col.label
}}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div>
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
</q-card>
</div>
<div class="col-xs-12 col-sm-12" id="title">
<q-input
for="inputTopicComplaint"
ref="titleRef"
dense
outlined
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
hide-bottom-space
v-model="formData.title"
:rules="[(val) => !!val || 'กรุณาการข้อมูล']"
lazy-rules
label="เรื่องร้องเรียน"
type="textarea"
rows="5"
/>
</div>
<div class="col-xs-12 col-sm-12" id="description">
<q-input
for="inputDetail"
ref="descriptionRef"
dense
outlined
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
hide-bottom-space
v-model="formData.description"
:rules="[(val) => !!val || 'กรุณาการข้อมูล']"
lazy-rules
label="รายละเอียดที่เกี่นวข้องกับเรื่องที่ต้องการจะข้อเรียน"
type="textarea"
rows="5"
/>
</div>
<div class="col-xs-12 col-sm-3" id="dateReceived">
<datepicker
menu-class-name="modalfix"
v-model="formData.dateReceived"
:locale="'th'"
autoApply
borderless
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
: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="dateReceivedRef"
outlined
dense
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
hide-bottom-space
class="full-width datepicker"
:model-value="
formData.dateReceived != null
? date2Thai(formData.dateReceived)
: 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="levelConsideration">
<q-select
for="selectConsiderationLevel"
ref="levelConsiderationRef"
dense
outlined
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
v-model="formData.levelConsideration"
:options="levelConsiderationtoptions"
label="ระดับการพิจารณา"
option-value="id"
option-label="name"
emit-value
hide-bottom-space
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกระดับการพิจารณา'}`]"
lazy-rules
@update:model-value="selectLevel(formData.levelConsideration)"
/>
</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.levelConsideration)"
:locale="'th'"
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
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
"
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
label="วันที่กำหนดวันพิจารณา"
hide-bottom-space
: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="offenseDetails">
<q-select
for="selectOffenseDescription"
ref="offenseDetailsRef"
dense
outlined
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
v-model="formData.offenseDetails"
:options="offenseDetailstoptions"
label="ลักษณะความผิด"
option-value="id"
option-label="name"
emit-value
hide-bottom-space
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกลักษณะความผิด'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-3" id="dateNotification">
<datepicker
menu-class-name="modalfix"
v-model="formData.dateNotification"
:locale="'th'"
autoApply
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
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="dateNotificationRef"
outlined
dense
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
hide-bottom-space
class="full-width datepicker"
:model-value="
formData.dateNotification != null
? date2Thai(formData.dateNotification)
: 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="complaintFrom">
<q-select
for="selectReceivecomplaints"
ref="complaintFromRef"
dense
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
outlined
v-model="formData.complaintFrom"
:options="complaintFromtoptions"
label="รับเรื่องร้องเรียน"
option-value="id"
option-label="name"
hide-bottom-space
emit-value
map-options
:rules="[(val) => !!val || `${'กรุณาเลือกรับเรื่องร้องเรียน'}`]"
lazy-rules
/>
</div>
<div class="col-xs-12 col-sm-12" id="appellant">
<q-input
for="inputPetitioner"
ref="appellantRef"
dense
outlined
v-model="formData.appellant"
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
label="ผู้ร้องเรียน"
:rules="[(val) => !!val || `${'กรุณากรอกข้อมูล'}`]"
lazy-rules
hide-bottom-space
type="textarea"
rows="5"
/>
</div>
<div class="col-12" id="documentFile">
<q-file
for="inputFiles"
ref="documentFileRef"
outlined
dense
class="fit"
:readonly="
formData.complaintStatus !== 'NEW' &&
formData.complaintStatus !== ''
"
v-model="formData.documentFile"
@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"
v-if="
formData.complaintStatus === 'NEW' ||
formData.complaintStatus === ''
"
>
<q-space />
<q-btn
for="ButtonOnSubmit"
id="onSubmit"
color="secondary"
label="บันทึก"
type="submit"
><q-tooltip>บทกขอม</q-tooltip></q-btn
>
</div>
</form>
</q-card>
</div>
<DialogAddPersonal
:modal="modal"
btn-title="เพิ่มรายชื่อผู้ถูกสอบสวน"
:close="toggleModal"
:save="addPerson"
@returnData="handleSave"
/>
</template>
<style scoped></style>