2024-03-13 16:51:43 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, onMounted } from "vue";
|
2024-09-18 17:24:21 +07:00
|
|
|
import { useQuasar } from "quasar";
|
|
|
|
|
import axios from "axios";
|
2024-08-01 18:03:39 +07:00
|
|
|
|
2024-09-18 17:24:21 +07:00
|
|
|
import { checkPermission } from "@/utils/permissions";
|
2024-03-20 15:59:59 +07:00
|
|
|
import { useRoute } from "vue-router";
|
2024-03-13 16:51:43 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2024-09-18 17:24:21 +07:00
|
|
|
|
2024-08-01 12:12:28 +07:00
|
|
|
import type { ArrayFileList } from "@/modules/04_registryPerson/interface/index/document";
|
2024-09-18 17:24:21 +07:00
|
|
|
|
2024-03-20 15:59:59 +07:00
|
|
|
const $q = useQuasar();
|
|
|
|
|
const route = useRoute();
|
2024-03-13 16:51:43 +07:00
|
|
|
const mixin = useCounterMixin();
|
|
|
|
|
const {
|
|
|
|
|
success,
|
|
|
|
|
messageError,
|
2024-03-20 15:59:59 +07:00
|
|
|
showLoader,
|
|
|
|
|
hideLoader,
|
|
|
|
|
dialogConfirm,
|
2024-03-13 16:51:43 +07:00
|
|
|
dialogRemove,
|
|
|
|
|
} = mixin;
|
|
|
|
|
|
2024-10-21 17:56:47 +07:00
|
|
|
/**
|
|
|
|
|
* props
|
|
|
|
|
*/
|
2024-11-04 15:21:23 +07:00
|
|
|
const isLeave = defineModel<boolean>("isLeave", {
|
|
|
|
|
required: true,
|
2024-10-21 17:56:47 +07:00
|
|
|
});
|
|
|
|
|
|
2024-03-20 15:59:59 +07:00
|
|
|
const profileId = ref<string>(
|
|
|
|
|
route.params.id ? route.params.id.toString() : ""
|
|
|
|
|
);
|
2024-09-18 17:24:21 +07:00
|
|
|
const documentFile = ref<any>(null);
|
|
|
|
|
const fileList = ref<ArrayFileList[]>([]); //รายการเอกสารหลักฐาน
|
2024-03-20 15:59:59 +07:00
|
|
|
|
2024-09-18 17:24:21 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชันดึงข้อมูลรายการเอกสารหลักฐาน
|
|
|
|
|
*/
|
2024-03-20 15:59:59 +07:00
|
|
|
async function getData() {
|
2024-08-01 12:12:28 +07:00
|
|
|
showLoader();
|
2024-03-20 15:59:59 +07:00
|
|
|
await http
|
|
|
|
|
.get(
|
|
|
|
|
config.API.file("ระบบทะเบียนประวัติ", "เอกสารหลักฐาน", profileId.value)
|
|
|
|
|
)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
fileList.value = res.data;
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
messageError($q, e);
|
|
|
|
|
})
|
2024-03-20 17:29:50 +07:00
|
|
|
.finally(() => {
|
2024-08-01 12:12:28 +07:00
|
|
|
hideLoader();
|
2024-03-20 17:29:50 +07:00
|
|
|
});
|
2024-03-13 16:51:43 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-09-18 17:24:21 +07:00
|
|
|
* ฟังก์ชั่นสร้าง Path สำหรับอัพโหลดไฟล์เอกสารหลักฐาน
|
2024-03-13 16:51:43 +07:00
|
|
|
*/
|
2024-08-16 17:58:33 +07:00
|
|
|
function clickUpload(file: any) {
|
2024-03-20 15:59:59 +07:00
|
|
|
const fileName = { fileName: file.name };
|
|
|
|
|
dialogConfirm(
|
|
|
|
|
$q,
|
|
|
|
|
async () => {
|
2024-08-16 17:58:33 +07:00
|
|
|
showLoader();
|
2024-03-20 15:59:59 +07:00
|
|
|
const selectedFile = file;
|
|
|
|
|
const formdata = new FormData();
|
|
|
|
|
formdata.append("file", selectedFile);
|
|
|
|
|
await http
|
|
|
|
|
.post(
|
|
|
|
|
config.API.file(
|
|
|
|
|
"ระบบทะเบียนประวัติ",
|
|
|
|
|
"เอกสารหลักฐาน",
|
|
|
|
|
profileId.value
|
|
|
|
|
),
|
|
|
|
|
{
|
|
|
|
|
replace: false,
|
|
|
|
|
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 &&
|
|
|
|
|
uploadFileDoc(res.data[foundKey]?.uploadUrl, documentFile.value);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
"ยืนยันการอัปโหลดไฟล์",
|
|
|
|
|
"ต้องการยืนยันการอัปโหลดไฟล์นี้หรือไม่ ?"
|
|
|
|
|
);
|
2024-03-13 16:51:43 +07:00
|
|
|
}
|
|
|
|
|
|
2024-09-18 17:24:21 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชั่นสำหรับอัพโหลดไฟล์เอกสารหลักฐาน
|
|
|
|
|
*/
|
|
|
|
|
async function uploadFileDoc(uploadUrl: string, file: any) {
|
|
|
|
|
const Data = new FormData();
|
|
|
|
|
Data.append("file", documentFile.value);
|
|
|
|
|
showLoader();
|
|
|
|
|
await axios
|
|
|
|
|
.put(uploadUrl, file, {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": file.type,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(async () => {
|
|
|
|
|
await getData();
|
|
|
|
|
success($q, "อัปโหลดไฟล์สำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
messageError($q, e);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
documentFile.value = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-13 16:51:43 +07:00
|
|
|
/**
|
2024-09-06 13:47:50 +07:00
|
|
|
* ดาวน์โหลดลิงก์ไฟล์
|
2024-03-20 15:59:59 +07:00
|
|
|
* @param fileName file name
|
2024-03-13 16:51:43 +07:00
|
|
|
*/
|
2024-03-20 15:59:59 +07:00
|
|
|
function downloadFile(fileName: string) {
|
2024-03-13 16:51:43 +07:00
|
|
|
showLoader();
|
|
|
|
|
http
|
2024-03-20 15:59:59 +07:00
|
|
|
.get(
|
|
|
|
|
config.API.fileByFile(
|
|
|
|
|
"ระบบทะเบียนประวัติ",
|
|
|
|
|
"เอกสารหลักฐาน",
|
|
|
|
|
profileId.value,
|
|
|
|
|
fileName
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-03-13 16:51:43 +07:00
|
|
|
.then((res) => {
|
2024-03-20 15:59:59 +07:00
|
|
|
const data = res.data.downloadUrl;
|
|
|
|
|
window.open(data, "_blank");
|
2024-03-13 16:51:43 +07:00
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
messageError($q, e);
|
|
|
|
|
})
|
2024-03-20 15:59:59 +07:00
|
|
|
.finally(async () => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
2024-03-13 16:51:43 +07:00
|
|
|
}
|
2024-03-20 15:59:59 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ลบไฟล์
|
|
|
|
|
* @param fileName file name
|
|
|
|
|
*/
|
|
|
|
|
function deleteFile(fileName: string) {
|
|
|
|
|
dialogRemove($q, async () => {
|
|
|
|
|
showLoader();
|
|
|
|
|
http
|
|
|
|
|
.delete(
|
|
|
|
|
config.API.fileByFile(
|
|
|
|
|
"ระบบทะเบียนประวัติ",
|
|
|
|
|
"เอกสารหลักฐาน",
|
|
|
|
|
profileId.value,
|
|
|
|
|
fileName
|
|
|
|
|
)
|
|
|
|
|
)
|
2024-08-16 17:58:33 +07:00
|
|
|
.then(async () => {
|
|
|
|
|
await setTimeout(async () => {
|
|
|
|
|
await getData();
|
|
|
|
|
await success($q, `ลบไฟล์สำเร็จ`);
|
|
|
|
|
}, 1500);
|
2024-03-20 15:59:59 +07:00
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
messageError($q, e);
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
getData();
|
|
|
|
|
});
|
2024-03-13 16:51:43 +07:00
|
|
|
</script>
|
2024-03-08 16:46:36 +07:00
|
|
|
<template>
|
2024-04-24 17:26:12 +07:00
|
|
|
<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>
|
|
|
|
|
<div class="row col-12 q-col-gutter-y-sm q-pa-sm">
|
|
|
|
|
<div class="col-12 row">
|
|
|
|
|
<q-file
|
2024-11-04 15:21:23 +07:00
|
|
|
v-if="isLeave == false && checkPermission($route)?.attrIsUpdate"
|
2024-04-24 17:26:12 +07:00
|
|
|
for="inputFiles"
|
|
|
|
|
class="col-12"
|
|
|
|
|
outlined
|
|
|
|
|
dense
|
|
|
|
|
v-model="documentFile"
|
|
|
|
|
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
|
|
|
|
|
size="14px"
|
|
|
|
|
v-if="documentFile"
|
|
|
|
|
flat
|
|
|
|
|
round
|
|
|
|
|
dense
|
2024-12-04 16:13:12 +07:00
|
|
|
color="primary"
|
2024-04-24 17:26:12 +07:00
|
|
|
icon="mdi-upload"
|
|
|
|
|
@click="clickUpload(documentFile)"
|
|
|
|
|
><q-tooltip>อัปโหลดไฟล์</q-tooltip></q-btn
|
|
|
|
|
>
|
|
|
|
|
</template>
|
|
|
|
|
</q-file>
|
2024-03-13 16:51:43 +07:00
|
|
|
|
2024-04-24 17:26:12 +07:00
|
|
|
<!-- <div class="col-1 self-center" v-if="formData.documentFile"></div> -->
|
|
|
|
|
</div>
|
2024-03-13 16:51:43 +07:00
|
|
|
|
2024-04-24 17:26:12 +07:00
|
|
|
<div v-if="fileList.length > 0" class="col-xs-12 row">
|
|
|
|
|
<q-list class="full-width rounded-borders" bordered separator>
|
|
|
|
|
<q-item
|
|
|
|
|
clickable
|
|
|
|
|
v-ripple
|
|
|
|
|
v-for="data in fileList"
|
|
|
|
|
:key="data.id"
|
|
|
|
|
class="items-center"
|
|
|
|
|
>
|
|
|
|
|
<q-item-section>{{ data.fileName }}</q-item-section>
|
|
|
|
|
<q-space />
|
|
|
|
|
<div>
|
|
|
|
|
<q-btn
|
|
|
|
|
size="12px"
|
|
|
|
|
flat
|
|
|
|
|
round
|
|
|
|
|
dense
|
|
|
|
|
color="blue"
|
|
|
|
|
icon="mdi-download"
|
|
|
|
|
@click="downloadFile(data.fileName)"
|
|
|
|
|
><q-tooltip>ดาวน์โหลดไฟล์</q-tooltip></q-btn
|
|
|
|
|
>
|
|
|
|
|
<q-btn
|
2024-11-04 15:21:23 +07:00
|
|
|
v-if="isLeave == false"
|
2024-04-24 17:26:12 +07:00
|
|
|
size="12px"
|
|
|
|
|
flat
|
|
|
|
|
round
|
|
|
|
|
dense
|
|
|
|
|
color="red"
|
|
|
|
|
class="q-ml-sm"
|
|
|
|
|
icon="mdi-delete-outline"
|
|
|
|
|
@click="deleteFile(data.fileName)"
|
|
|
|
|
><q-tooltip>ลบไฟล์</q-tooltip></q-btn
|
|
|
|
|
>
|
2024-03-13 16:51:43 +07:00
|
|
|
</div>
|
2024-04-24 17:26:12 +07:00
|
|
|
</q-item>
|
|
|
|
|
</q-list>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="col-12" v-else>
|
|
|
|
|
<q-card class="q-pa-md" bordered> ไม่มีรายการเอกสาร </q-card>
|
2024-03-13 16:51:43 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-24 17:26:12 +07:00
|
|
|
</q-card>
|
2024-03-08 16:46:36 +07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|