hrms-mgt/src/modules/18_command/components/Step/View0_Digital.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 307bfc67c0 ออกคำสั่ง PreViewPDF
2024-09-26 12:10:15 +07:00

749 lines
24 KiB
Vue

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import axios from "axios";
import { useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";
import { useCommandDetail } from "@/modules/18_command/store/DetailStore";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
import type { DataOption } from "@/modules/18_command/interface/index/Main";
import type { DataFileDownload } from "@/modules/18_command/interface/response/Main";
import DialogHeader from "@/components/DialogHeader.vue";
import PerviewPDF from "@/modules/18_command/components/Step/PerviewPDF.vue";
const $q = useQuasar();
const route = useRoute();
const store = useCommandDetail();
const {
showLoader,
hideLoader,
messageError,
dialogConfirm,
dialogMessageNotify,
} = useCounterMixin();
const commandId = ref<string>(route.params.id.toString()); //ID คำสั่ง
const { fetchData } = defineProps({
fetchData: { type: Function, require: true },
});
const step = defineModel<number>("step", { required: true }); //ขั้นตอนการลงนาม
//แบบร่าง
const isCheckDraft = defineModel<boolean>("isDraft", { required: true });
// แบบร่าง
const isAttachment = defineModel<boolean>("isAttachment", { required: true }); //เช็คบัญชีแนบท้าย
const fileUploadOrder = ref<any>(null); //ไฟล์คำสั่ง
const fileUploadTailer = ref<any>(null); //ไฟล์เอกสารแนบท้าย
const fileOrder = ref<any>(null); //ไฟล์คำสั่ง
const fileTailer = ref<any>(null); //ไฟล์เอกสารแนบท้าย
const modalSelect = ref<boolean>(false); //popup เลือกผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง
const typeFilter = ref<string>("firstname");
const search = ref<string>("");
const typeFilterOp = ref<DataOption[]>([
{ id: "citizenId", name: "เลขประจำตัวประชาชน" },
{ id: "firstname", name: "ชื่อ" },
{ id: "lastname", name: "นามสกุล" },
]);
const rows = ref<any[]>([
{
citizenId: "6796519798790",
firstName: "ว่าที่ร้อยตรีวรรนิมมามานา วงศ์วโรทัย",
},
]); //รายชื่อผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง
const selected = ref<any[]>([]); //เลือกผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง
const columns = ref<QTableProps["columns"]>([
{
name: "citizenId",
align: "left",
label: "เลขประจำตัวประชาชน",
sortable: true,
field: "citizenId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "fullName",
align: "left",
label: "ชื่อ-นามสกุล",
sortable: true,
field: "fullName",
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",
},
]);
//รอผู้มีอำนาจลงนามอนุมัติ
const rowsAuthority = ref<any[]>([
{
fullName: "ว่าที่ร้อยตรีวรรนิมมามานา วงศ์วโรทัย",
comment: "ความคิดเห็น",
position: "หัวหน้าสำนัก",
},
{
fullName: "นายศรัณย์ ศิลาดี",
comment: "",
position: "ผู้อำนวนการ",
},
]); //รายชื่อผู้อำนาจลงนามอนุมัติ
const modalComment = ref<boolean>(false); //popup แสดงความเห็น
const reason = ref<string>("");
//รอออกคำสั่ง
const isCheckOrder = ref<boolean>(true); //เช็ครอออกคำสั่ง
const isLoad = ref<boolean>(false); //แสดงโหลด
const isPersonSign = ref<boolean>(false); //ผู้มีอำนาจลงนาม
const modalPerView = ref<boolean>(false);
/**
* ฟังก์ชันยืนยันการส่งให้ผู้มีอำนาจลงนามอนุมัติ
*/
function onConfirmDraft() {
if (
store?.dataCommand?.commandNo !== "" &&
store?.dataCommand?.commandExcecuteDate !== null
) {
modalSelect.value = true;
} else {
dialogMessageNotify(
$q,
"ไม่สามารถดำเนินการต่อได้ กรุณากรอกเลขที่คำสั่ง และวันที่คำสั่งมีผลให้ครบ"
);
}
}
function onSearchData() {}
function onConfirmSendToCommander() {
dialogConfirm(
$q,
async () => {
showLoader();
await http
.put(config.API.command + `/draft/${commandId.value}`, {
sign: true,
})
.then(async () => {
await fetchData?.();
isCheckDraft.value = true;
onCloseDialog();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
},
"ยืนยันการส่งไปยังผู้บังคับบัญชา/ผู้มีอำนาจ",
"คุณต้องการส่งไปยังผู้บังคับบัญชา/ผู้มีอำนาจใช่หรือไม่?"
);
}
function updateSelect() {
search.value = "";
}
function onComment() {
modalComment.value = true;
}
function onSubmitComment() {
dialogConfirm($q, () => {
rowsAuthority.value[1].comment = reason.value;
onCloseDialog();
});
}
function onCloseDialog() {
modalSelect.value = false;
modalComment.value = false;
isPersonSign.value = false;
}
async function fetchDoc(group: string) {
showLoader();
let type = group === "order" ? "คำสั่ง" : "แนบท้าย";
await http
.get(config.API.file("ระบบออกคำสั่ง", type, commandId.value))
.then((res) => {
const data = res.data[0];
if (group === "order") {
fileOrder.value = data;
} else {
fileTailer.value = data;
}
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function onUploadFile(group: string) {
showLoader();
let type = group === "order" ? "คำสั่ง" : "แนบท้าย";
let file = group === "order" ? fileUploadOrder.value : fileUploadTailer.value;
const fileName = { fileName: type };
http
.post(config.API.file("ระบบออกคำสั่ง", type, commandId.value), {
replace: true,
fileList: fileName,
})
.then(async (res) => {
const foundKey: string | undefined = Object.keys(res.data).find(
(key) =>
res.data[key]?.fileName !== undefined &&
res.data[key]?.fileName !== ""
);
foundKey &&
(await uploadFileDoc(res.data[foundKey]?.uploadUrl, file, group));
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* ฟังก์ชั่นสำหรับอัพโหลดไฟล์เอกสารหลักฐาน
*/
async function uploadFileDoc(uploadUrl: string, file: any, group: string) {
const formData = new FormData();
formData.append("file", file);
showLoader();
await axios
.put(uploadUrl, file, {
headers: {
"Content-Type": file.type,
},
})
.then(async () => {
await fetchDoc(group);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
if (group === "order") {
fileUploadOrder.value = null;
} else {
fileUploadTailer.value = null;
}
hideLoader();
});
}
const dataFile = ref<DataFileDownload>();
/**
* ดาวน์โหลดลิงก์ไฟล์
* @param fileName file name
*/
function downloadFile(file: any, group: string, isView: boolean = false) {
let type = group === "order" ? "คำสั่ง" : "แนบท้าย";
showLoader();
http
.get(
config.API.fileByFile(
"ระบบออกคำสั่ง",
type,
commandId.value,
file.fileName
)
)
.then((res) => {
const data = res.data;
dataFile.value = data;
if (isView) {
modalPerView.value = true;
} else {
window.open(data.downloadUrl, "_blank");
}
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
}
onMounted(async () => {
isLoad.value = false;
let promises = [fetchDoc("order")];
if (isAttachment.value) {
promises.push(fetchDoc("tailer"));
}
await Promise.all(promises).finally(() => {
isLoad.value = true;
});
});
</script>
<template>
<div class="q-px-lg q-py-md" v-if="isLoad">
<q-timeline :color="store.status === 'CANCEL' ? 'grey-4' : 'blue-5'">
<!-- แบบร่าง -->
<q-timeline-entry
title="แบบร่าง"
:icon="step === 1 ? 'mdi-pencil' : step > 1 ? 'done' : 'mdi-numeric-1'"
>
<div class="row q-col-gutter-sm">
<div class="row col-12 q-col-gutter-sm">
<div class="col-12 text-header">
อัปโหลดเอกสารสแกนกลับเข้าสู่ระบบ
</div>
<div class="col-6">
<q-card
bordered
class="row col-12"
style="border: 1px solid #d6dee1"
>
<div
class="row items-center col-12 text-weight-medium bg-grey-1 q-py-sm q-px-md"
>
คำสั่ง
<q-space />
<q-btn
v-if="fileOrder"
rounded
flat
dense
color="primary"
icon="mdi-eye"
@click.prevent="downloadFile(fileOrder, 'order', true)"
>
<q-tooltip>ดูไฟล์คำสั่ง</q-tooltip>
</q-btn>
<q-btn
v-if="fileOrder"
rounded
flat
dense
color="red"
icon="mdi-download"
@click.prevent="downloadFile(fileOrder, 'order')"
>
<q-tooltip>ดาวน์โหลดไฟล์คำสั่ง</q-tooltip>
</q-btn>
</div>
<div class="col-12"><q-separator /></div>
<div class="col-12 q-pa-md" v-if="step === 1">
<q-file
outlined
dense
v-model="fileUploadOrder"
label="เลือกไฟล์คำสั่ง"
hide-bottom-space
accept=".pdf"
:readonly="store.readonly"
>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
<template v-slot:after>
<q-btn
@click.prevent="onUploadFile('order')"
flat
round
icon="mdi-upload"
:color="fileUploadOrder == null ? 'grey-5' : 'blue-5'"
:disable="fileUploadOrder == null"
/>
</template>
</q-file>
</div>
</q-card>
</div>
<div class="col-6" v-if="isAttachment">
<q-card
bordered
class="row col-12"
style="border: 1px solid #d6dee1"
>
<div
class="row items-center col-12 text-weight-medium bg-grey-1 q-py-sm q-px-md"
>
เอกสารแนบท้าย
<q-space />
<q-btn
v-if="fileTailer"
rounded
flat
dense
color="primary"
icon="mdi-eye"
@click.prevent="downloadFile(fileTailer, 'tailer', true)"
>
<q-tooltip>ดูไฟล์เอกสารแนบท้าย</q-tooltip>
</q-btn>
<q-btn
v-if="fileTailer"
rounded
flat
dense
color="red"
icon="mdi-download"
@click.prevent="downloadFile(fileTailer, 'tailer')"
>
<q-tooltip>ดาวน์โหลดไฟล์แนบท้าย</q-tooltip>
</q-btn>
</div>
<div class="col-12"><q-separator /></div>
<div class="col-12 q-pa-md" v-if="step === 1">
<q-file
outlined
dense
v-model="fileUploadTailer"
label="เลือกไฟล์เอกสารแนบท้าย"
hide-bottom-space
accept=".pdf"
:readonly="store.readonly"
>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
<template v-slot:after>
<q-btn
@click.prevent="onUploadFile('tailer')"
flat
round
icon="mdi-upload"
:color="fileUploadTailer == null ? 'grey-5' : 'blue-5'"
:disable="fileUploadTailer == null"
/>
<q-tooltip>อัปโหลดไฟล์เอกสารแนบท้าย</q-tooltip>
</template>
</q-file>
</div>
</q-card>
</div>
</div>
<div
class="col-12"
v-if="!isCheckDraft && fileOrder && (!isAttachment || fileTailer)"
>
<q-btn
v-if="!store.readonly"
@click.prevent="onConfirmDraft"
label="เลือกผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง"
:color="
fileOrder === null || (isAttachment && fileTailer === null)
? 'grey-5'
: 'public'
"
:disable="
fileOrder === null || (isAttachment && fileTailer === null)
"
/>
</div>
</div>
</q-timeline-entry>
<!-- รอผู้มีอำนาจลงนามอนุมัติ -->
<q-timeline-entry
title="รอผู้มีอำนาจลงนามอนุมัติ"
:icon="step === 2 ? 'mdi-pencil' : step > 2 ? 'done' : 'mdi-numeric-2'"
:color="step < 2 ? 'grey-4' : ''"
>
<div class="row q-col-gutter-sm" v-if="isCheckDraft">
<div class="">
<q-list bordered separator>
<q-item v-for="(item, index) in rowsAuthority" :key="index">
<q-item-section>
<q-item-label
>{{ item.fullName }}
{{ `(${item.position})` }}</q-item-label
>
<q-item-label caption lines="2">{{
item.comment
}}</q-item-label>
</q-item-section>
<q-item-section
side
top
v-if="
index === rowsAuthority.length - 1 && item.comment === ''
"
>
<q-item-label caption v-if="!store.readonly">
<q-btn
flat
dense
color="info"
icon="info"
round
@click.prevent="onComment"
>
<q-tooltip>แสดงความเห็น </q-tooltip>
</q-btn>
</q-item-label>
</q-item-section>
</q-item>
</q-list>
</div>
<div
class="col-12"
v-if="rowsAuthority[rowsAuthority.length - 1].comment !== ''"
>
<q-btn
@click.prevent="onConfirmDraft"
label="เลือกผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง"
color="public"
/>
</div>
</div>
</q-timeline-entry>
<!-- รอออกคำสั่ง -->
<q-timeline-entry
title="รอออกคำสั่ง"
:icon="step === 3 ? 'mdi-pencil' : step > 3 ? 'done' : 'mdi-numeric-3'"
:color="step < 3 ? 'grey-4' : ''"
>
<!-- <div class="row q-col-gutter-sm" v-if="isCheckAuthority">
<div class="col-12">รอออกคำสั่ง</div>
</div> -->
</q-timeline-entry>
<!-- รอออกคำสั่ง -->
<q-timeline-entry
title="ออกคำสั่งเสร็จสิ้น"
:icon="step === 4 ? 'mdi-pencil' : step > 4 ? 'done' : 'mdi-numeric-4'"
:color="step < 4 ? 'grey-4' : ''"
>
<div class="row q-col-gutter-sm" v-if="step === 4">
<div class="q-pa-md q-gutter-sm">
<q-btn
color="blue-5"
icon-right="mdi-download"
label="ดาวน์โหลดคำสั่งที่เซ็นต์แล้ว"
/>
<q-btn
color="blue-5"
icon-right="mdi-download"
label="ดาวน์โหลดบัญชีแนบท้ายที่เซ็นต์แล้ว"
/>
</div>
</div>
</q-timeline-entry>
</q-timeline>
</div>
<div class="full-width row flex-center text-accent q-gutter-sm" v-else>
<span
><div
style="
height: 50vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
"
class="text-grey-5"
>
<q-spinner color="primary" size="3em" :thickness="10" />
</div>
</span>
</div>
<!-- เลือกผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง -->
<q-dialog v-model="modalSelect" persistent>
<q-card style="min-width: 70%">
<DialogHeader
:tittle="'เลือกผู้บังคับบัญชา/ผู้มีอำนาจออกคำสั่ง'"
:close="onCloseDialog"
/>
<q-separator />
<q-card-section>
<div class="col-12 q-col-gutter-sm">
<div class="col-12 row q-col-gutter-md items-start">
<div class="col-12 col-sm-6 col-md-3">
<q-select
label="ค้นหาจาก"
v-model="typeFilter"
:options="typeFilterOp"
emit-value
dense
@update:model-value="updateSelect"
map-options
outlined
option-label="name"
option-value="id"
/>
</div>
<div class="col-12 col-sm-6 col-md-6">
<q-input
v-model="search"
outlined
clearable
hide-bottom-space
dense
label="คำค้น"
@clear="search = ''"
/>
</div>
<div class="col-12 col-sm-6 col-md-3">
<q-btn
color="primary"
icon="search"
label="ค้นหา"
class="full-width q-pa-sm"
@click.prevent="onSearchData"
>
</q-btn>
</div>
</div>
<div class="col-12">
<d-table
flat
:columns="columns"
:rows="rows"
row-key="id"
dense
selection="single"
v-model:selected="selected"
>
<template v-slot:header-selection="scope">
<q-checkbox
keep-color
color="primary"
dense
v-model="scope.checkBox"
/>
</template>
<template v-slot:header="props">
<q-tr :props="props">
<q-th class="text-center"> </q-th>
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td class="text-center">
<q-checkbox
keep-color
color="primary"
dense
v-model="props.selected"
/>
</q-td>
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div>
{{ col.value ?? "-" }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
<div class="col-12">
<q-checkbox v-model="isPersonSign" label="ผู้มีอำนาจลงนาม" />
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn
:disable="selected.length === 0"
@click.prevent="onConfirmSendToCommander"
label="ส่งไปยังผู้บังคับบัญชา/ผู้มีอำนาจ"
color="public"
/>
</q-card-actions>
</q-card>
</q-dialog>
<!-- แสดงความเห -->
<q-dialog v-model="modalComment" persistent>
<q-card style="min-width: 40%">
<q-form greedy @submit.prevent @validation-success="onSubmitComment">
<DialogHeader :tittle="'แสดงความเห็น'" :close="onCloseDialog" />
<q-separator />
<q-card-section>
<div class="row col-12 q-col-gutter-sm">
<div class="col-12">
<q-input
dense
outlined
v-model="reason"
label="ความเห็น"
type="textarea"
:rules="[(val: string) => val !== null && val !== '' || `${'กรุณากรอกความเห็น'}`]"
hide-bottom-space
lazy-rules
/>
</div>
</div>
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn color="secondary" label="บันทึกความเห็น" type="onSubmit" />
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
<PerviewPDF
v-model:modal="modalPerView"
v-model:data-file="dataFile as DataFileDownload"
/>
</template>
<style lang="scss" scoped>
.text-header {
color: #34373c;
font-size: 1rem;
font-weight: 300;
}
</style>