hrms-mgt/src/modules/11_discipline/components/4_Result/Form.vue

654 lines
22 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import http from "@/plugins/http";
import config from "@/app.config";
import { useQuasar } from "quasar";
2023-11-24 16:52:10 +07:00
import { useRouter, useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { useDisciplineResultStore } from "@/modules/11_discipline/store/ResultStore";
import { useDisciplineMainStore } from "@/modules/11_discipline/store/main";
2023-12-27 15:50:41 +07:00
import DialogHistory from "@/modules/11_discipline/components/4_Result/DialogHistory.vue";
import PopupPersonal from "@/components/Dialogs/PopupPersonalNew.vue";
2023-11-24 16:52:10 +07:00
import type {
FormData,
FormRef,
DataOption,
DataOptionRes,
2023-12-15 17:29:47 +07:00
FileArray,
2023-11-24 16:52:10 +07:00
} from "@/modules/11_discipline/interface/request/result";
const modalPersonal = ref<boolean>(false);
const personId = ref<string>("");
const countNum = ref<number>(1);
const mainStore = useDisciplineMainStore();
const modalPerson = ref<boolean>(false);
const isReadonly = ref<boolean>(false); // อ่านได้อย่างเดียว
const dataStore = useDisciplineResultStore();
2023-11-24 16:52:10 +07:00
const mixin = useCounterMixin();
2023-12-25 16:31:24 +07:00
const {
hideLoader,
dialogConfirm,
success,
messageError,
showLoader,
dialogRemove,
2024-08-15 11:43:34 +07:00
downloadRenameFileByLink,
2023-12-25 16:31:24 +07:00
} = mixin;
2023-11-24 16:52:10 +07:00
const router = useRouter();
const route = useRoute();
const checkRoutePermisson = ref<boolean>(
route.name == "disciplineResultDetail"
);
2023-11-24 16:52:10 +07:00
const $q = useQuasar();
const id = ref<string>(route.params.id as string);
const isSave = ref<boolean>(false); // มีการแก้ไขรอบันทึก
const respondentType = ref<string>("");
2024-05-28 17:01:29 +07:00
const organization = ref<DataOption>();
const organizationId = ref<string>("");
2024-05-28 17:01:29 +07:00
const organizationName = ref<string>("");
const consideredAgency = ref<string>("");
2023-12-25 16:31:24 +07:00
const organizationOption = ref<DataOption[]>([]);
2023-11-24 16:52:10 +07:00
/** ตัวแปร ref สำหรับแสดง validate */
const detailRef = ref<Object | null>(null);
2023-12-27 15:50:41 +07:00
const modalHistory = ref<boolean>(false);
const personalId = ref<string>("");
2023-11-24 16:52:10 +07:00
/** รับ props มาจากหน้าหลัก */
const props = defineProps({
data: {
type: Object,
default: null,
},
onSubmit: {
type: Function,
default: () => "",
},
fetchData: {
type: Function,
default: () => "",
},
2023-11-24 16:52:10 +07:00
});
/** ข้อมูล v-model ของฟอร์ม */
const formData = reactive<FormData>({
resultDescription: "",
2023-12-15 17:29:47 +07:00
disciplineType: "",
titleType: "",
oc: "",
file: null,
2023-12-20 17:04:32 +07:00
disciplineDisciplinary_DocResults: [],
2023-12-15 17:29:47 +07:00
year: new Date().getFullYear(),
2023-11-24 16:52:10 +07:00
});
/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */
const objectdisciplinary: FormRef = {
resultDescription: detailRef,
2023-11-24 16:52:10 +07:00
};
/** function เรียกรายชื่อหน่วยงาน*/
2024-05-28 17:01:29 +07:00
/** ดึงข้อมูล active */
async function getActive() {
showLoader();
await http
2024-05-28 17:01:29 +07:00
.get(config.API.activeOrganization)
.then((res) => {
2024-05-28 17:01:29 +07:00
getOc(res.data.result.activeId);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function getOc(activeId: string) {
showLoader();
await http
2024-08-20 10:39:17 +07:00
.get(config.API.orgByIdSystem(activeId, route.meta.Key as string))
2024-05-28 17:01:29 +07:00
.then(async (res) => {
organizationOption.value = await res.data.result.map((item: any) => ({
id: item.orgTreeId,
name: item.orgName,
}));
})
.catch((err) => {
messageError($q, err);
2024-05-28 17:01:29 +07:00
})
.finally(() => {
hideLoader();
});
}
async function selectComplainant(val: string) {
organizationId.value = "";
consideredAgency.value = "";
}
2023-11-24 16:52:10 +07:00
/**
* งกนสำหรบบนทกขอม ระบบจะแสดง dialog ใหนยนการบนท
* หากยนยนจะสงขอมลไปบนทกท api
* หากยกเลกจะกลบไปหนาฟอร
*/
function onSubmit() {
dialogConfirm($q, async () => {
await http
.put(config.API.listResultById(id.value), formData)
.then(() => {
isSave.value = false;
success($q, "บันทึกข้อมูลสำเร็จ");
props.fetchData();
})
.catch((err) => {
messageError($q, err);
})
.finally(async () => {});
});
2023-11-24 16:52:10 +07:00
}
async function fetchDatadetail() {
formData.resultDescription = props.data.resultDescription;
2023-11-24 16:52:10 +07:00
}
/**
* เชคขอมลจาก props
* เมอมอม
* เกบขอมลลง formData
*/
watch(
() => props.data,
async () => {
if (countNum.value === 1) {
2024-01-17 17:30:51 +07:00
respondentType.value = props.data.respondentType;
formData.oc = props.data.resultOc;
formData.disciplineType = props.data.resultDisciplineType;
formData.titleType = props.data.resultTitleType;
formData.disciplineDisciplinary_DocResults =
props.data.disciplineDisciplinary_DocResults;
formData.year = props.data.resultYear ?? 0;
mainStore.rowsAdd = props.data.persons;
await fetchDatadetail();
2024-05-28 17:01:29 +07:00
await getActive();
organizationId.value = props.data.organizationId;
organizationName.value = props.data.organization;
organization.value = {
id: props.data.organizationId,
name: props.data.organization,
};
2024-01-17 17:30:51 +07:00
} else if (countNum.value === 2) {
formData.disciplineDisciplinary_DocResults =
props.data.disciplineDisciplinary_DocResults;
}
}
);
2023-11-24 16:52:10 +07:00
2023-12-08 14:00:02 +07:00
function inputEdit(val: boolean) {
return {
"full-width cursor-pointer ": val,
"full-width cursor-pointer inputgreen": !val,
};
}
/** ฟังก์ชั่นเช็คการแก้ไขฟอร์มแล้วไม่ได้กดบันทึก */
function changeFormData() {
isSave.value = true;
}
2023-11-24 16:52:10 +07:00
/**
* งขอมลจำลองไปย store
*/
2023-12-15 17:29:47 +07:00
function uploadFile() {
/** uploadFile */
2023-12-20 17:04:32 +07:00
const Data = new FormData();
Data.append("file", formData.file);
showLoader();
http
.put(config.API.upLoadFileResult(id.value), Data)
.then((res) => {
props.fetchData();
countNum.value = 2;
success($q, "อัปโหลดไฟล์สำเร็จ");
2023-12-20 17:04:32 +07:00
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
formData.file = null;
});
2023-12-15 17:29:47 +07:00
}
function downloadFile(link: string) {
2023-12-21 16:33:34 +07:00
window.open(link, "_blank");
2023-12-15 17:29:47 +07:00
}
function deleteFile(id: string) {
2023-12-20 17:04:32 +07:00
dialogRemove($q, () => confirmDelete(id));
2023-12-15 17:29:47 +07:00
}
/**
* นย ลบ ไฟล
* @param id id file
*/
2023-12-20 17:04:32 +07:00
function confirmDelete(docid: string) {
showLoader();
http
.delete(config.API.deleteFileResult(id.value, docid))
.then((res) => {
success($q, `ลบไฟล์สำเร็จ`);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
props.fetchData();
});
2023-12-15 17:29:47 +07:00
}
2023-12-27 11:08:35 +07:00
2023-12-27 15:50:41 +07:00
function openDetial(id: string) {
personalId.value = id;
modalHistory.value = true;
2023-12-27 11:08:35 +07:00
}
2023-12-27 15:50:41 +07:00
function closeDetail() {
modalHistory.value = false;
2024-01-05 11:05:49 +07:00
personalId.value = "";
2023-12-27 11:08:35 +07:00
}
function onclickViewinfo(id: string) {
modalPersonal.value = true;
personId.value = id;
}
function updatemodalPersonal(modal: boolean) {
modalPersonal.value = modal;
}
2023-11-24 16:52:10 +07:00
</script>
<template>
<div class="row col-12 bg-white">
<div v-if="isSave" class="col-12">
<q-banner
inline-actions
bordered
rounded
class="bg-red-1 text-red border-orange q-ma-md"
>
<q-icon name="mdi-information-outline" size="20px" /> แจงเตอน
งไมไดนทกขอม
</q-banner>
<q-separator />
</div>
2024-05-28 17:01:29 +07:00
<q-form
greedy
@submit.prevent
@validation-success="onSubmit"
class="col-12 row"
>
<div class="col-12 row">
<div class="col-sm-12 col-md-9 row no-wrap">
<div class="col-12 q-pa-md">
<div class="row col-12 q-col-gutter-md">
<div class="col-xs-12 col-sm-4">
<q-select
readonly
for="SelectrespondentType"
v-model="respondentType"
ref="respondentTypeRef"
dense
outlined
label="ผู้ถูกร้องเรียน"
option-value="id"
option-label="name"
emit-value
use-input
map-options
hide-bottom-space
:options="dataStore.complainantoptions"
@update:model-value="selectComplainant(respondentType)"
@filter="(inputValue: any,
doneFn: Function) => dataStore.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
2024-05-28 17:01:29 +07:00
class="col-xs-12 col-sm-4"
v-if="respondentType === 'ORGANIZATION'"
id="organizationId"
>
<q-select
2024-05-28 17:01:29 +07:00
readonly
for="inputOffice"
name="organizationId"
ref="organizationIdRef"
dense
hide-bottom-space
outlined
option-label="name"
option-value="id"
map-options
2024-05-28 17:01:29 +07:00
v-model="organization"
:options="organizationOption"
2024-05-28 17:01:29 +07:00
label="หน่วยงานที่ถูกร้องเรียน"
/>
</div>
<div class="row col-12" v-if="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"
>
กรองเรยน
2023-12-15 17:29:47 +07:00
</div>
<div class="col-12"><q-separator /></div>
<div class="col-xs-12 q-pa-sm">
<d-table
ref="table"
:columns="mainStore.columnsRespondent"
:rows="mainStore.rowsAdd"
row-key="idcard"
flat
bordered
:paging="true"
dense
class="custom-header-table"
:visible-columns="mainStore.visibleColumnsRespondent"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th auto-width></q-th>
<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">
<td>
<q-btn
dense
flat
round
color="info"
icon="mdi-eye"
@click="onclickViewinfo(props.row.personId)"
>
<q-tooltip>อมลในทะเบยนประว</q-tooltip>
</q-btn>
<q-btn
dense
flat
round
color="deep-purple"
icon="mdi-history"
@click="openDetial(props.row.personId)"
>
<q-tooltip>ประว</q-tooltip>
</q-btn>
</td>
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div
v-else-if="col.name === 'organization'"
class="table_ellipsis"
>
{{ props.row.organization }}
</div>
<div v-else-if="col.name === 'salary'">
2024-05-28 15:41:15 +07:00
{{
props.row.salary
? props.row.salary.toLocaleString()
: ""
}}
</div>
<div v-else>
{{ col.value }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
2023-12-15 17:29:47 +07:00
</div>
</q-card>
</div>
<div class="col-12">
<q-input
:readonly="checkRoutePermisson"
:class="inputEdit(isReadonly)"
type="textarea"
dense
outlined
ref="detailRef"
v-model="formData.resultDescription"
for="#detail"
label="สรุปผลการพิจารณา"
hide-bottom-space
@update:model-value="changeFormData()"
/>
</div>
<div class="col-3">
<q-input
:readonly="checkRoutePermisson"
v-model="formData.disciplineType"
dense
:class="inputEdit(isReadonly)"
outlined
label="ประเภทวินัย"
/>
</div>
<div class="col-3">
<q-input
:readonly="checkRoutePermisson"
v-model="formData.titleType"
dense
outlined
:class="inputEdit(isReadonly)"
label="ประเภทของเรื่อง"
/>
</div>
<div class="col-4">
<q-input
:readonly="checkRoutePermisson"
v-model="formData.oc"
dense
outlined
:class="inputEdit(isReadonly)"
label="หน่วยงาน/ส่วนราชการ"
/>
</div>
<div class="col-2">
<datepicker
menu-class-name="modalfix"
v-model="formData.year"
class="col-2"
:locale="'th'"
autoApply
:readonly="checkRoutePermisson"
year-picker
:enableTimePicker="false"
>
<template #year="{ year }">{{ year + 543 }}</template>
<template #year-overlay-value="{ value }">{{
parseInt(value + 543)
}}</template>
<template #trigger>
2023-12-15 17:29:47 +07:00
<q-input
dense
:class="inputEdit(isReadonly)"
:readonly="checkRoutePermisson"
2023-12-15 17:29:47 +07:00
outlined
:model-value="
formData.year === 0 ? null : Number(formData.year) + 543
"
:label="`${'ปีงบประมาณ'}`"
>
<template v-slot:prepend>
<q-icon
name="event"
class="cursor-pointer"
style="color: var(--q-primary)"
2023-12-15 17:29:47 +07:00
>
</q-icon>
</template>
<template
v-if="!checkRoutePermisson && formData.year"
v-slot:append
>
<q-icon
name="cancel"
@click.stop.prevent="formData.year = 0"
class="cursor-pointer"
/>
</template>
</q-input>
</template>
</datepicker>
2023-12-15 17:29:47 +07:00
</div>
</div>
</div>
<div class="row"><q-separator vertical /></div>
</div>
2023-12-15 17:29:47 +07:00
<!-- พโหลดไฟล -->
<div class="col-sm-12 col-md-3 q-pa-md">
<q-card bordered class="row col-12" style="border: 1px solid #d6dee1">
<div class="col-12 text-weight-medium bg-grey-1 q-py-sm q-px-md">
ปโหลดไฟลเอกสารหลกฐาน
</div>
<div class="col-12"><q-separator /></div>
2024-08-19 13:25:17 +07:00
<div class="row col-12 q-col-gutter-y-sm q-pa-sm">
<div class="col-12 row" v-if="!checkRoutePermisson">
<q-file
for="inputFiles"
class="col-12"
outlined
dense
v-model="formData.file"
@added="uploadFile"
label="ไฟล์เอกสารหลักฐาน"
hide-bottom-space
accept=".pdf,.xlsx,.docx,.png,.jpg"
clearable
>
<template v-slot:prepend>
<q-icon name="attach_file" color="primary" />
</template>
<template v-slot:after>
<q-btn
v-if="formData.file"
size="14px"
flat
round
dense
color="add"
icon="mdi-upload"
@click="uploadFile"
><q-tooltip>ปโหลดไฟล</q-tooltip></q-btn
>
</template>
</q-file>
</div>
2024-08-15 11:43:34 +07:00
<div
v-if="formData.disciplineDisciplinary_DocResults.length > 0"
class="col-xs-12 row"
>
<q-list class="full-width" bordered separator>
<q-item
v-for="data in formData.disciplineDisciplinary_DocResults"
:key="data.id"
clickable
v-ripple
>
2024-08-15 11:43:34 +07:00
<q-item-section>{{ data.fileName }}</q-item-section>
<q-space />
<q-btn
size="12px"
flat
round
dense
color="blue"
icon="mdi-download"
@click="
downloadRenameFileByLink(data.pathName, data.fileName)
"
><q-tooltip>ดาวนโหลดไฟล</q-tooltip></q-btn
>
<q-btn
v-if="!checkRoutePermisson"
size="12px"
flat
round
dense
color="red"
class="q-ml-sm"
icon="mdi-delete-outline"
@click="deleteFile(data.id)"
><q-tooltip>ลบไฟล</q-tooltip></q-btn
>
</q-item>
</q-list>
</div>
<div class="col-12" v-else>
<q-card class="q-pa-md" bordered> ไมรายการเอกสาร </q-card>
</div>
</div>
</q-card>
</div>
<div class="col-12" v-if="!checkRoutePermisson"><q-separator /></div>
<div class="row col-12 q-pa-sm" v-if="!checkRoutePermisson">
<q-space />
<q-btn
for="ButtonOnSubmit"
id="formSubmit"
color="secondary"
label="บันทึก"
type="submit"
><q-tooltip>บทกขอม</q-tooltip></q-btn
>
</div>
</div>
2024-05-28 17:01:29 +07:00
</q-form>
</div>
<PopupPersonal
:modal="modalPersonal"
:id="personId"
@update:modal="updatemodalPersonal"
/>
2023-12-27 15:50:41 +07:00
<DialogHistory
:modal="modalHistory"
:close="closeDetail"
:person-id="personalId"
2023-12-27 11:08:35 +07:00
/>
2023-11-24 16:52:10 +07:00
</template>