UI ทะเบียนประวัติ Part 1
This commit is contained in:
parent
cb49d7e0ab
commit
d448de5784
12 changed files with 1111 additions and 27 deletions
|
|
@ -1,6 +1,7 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, ref, reactive } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import axios from "axios";
|
||||
|
||||
import { checkPermission } from "@/utils/permissions";
|
||||
import { useRoute } from "vue-router";
|
||||
|
|
@ -36,6 +37,8 @@ const {
|
|||
onSearchDataTable,
|
||||
} = mixin;
|
||||
|
||||
const fileUpload = ref<File>();
|
||||
const uploadUrl = ref<string>("");
|
||||
/** props*/
|
||||
const isLeave = defineModel<boolean>("isLeave", {
|
||||
required: true,
|
||||
|
|
@ -74,6 +77,7 @@ const OpsFilter = ref<InsigniaOps>({
|
|||
});
|
||||
|
||||
const insigniaOptions = ref<any[]>([]);
|
||||
const insigniaOptionsMain = ref<any[]>([]);
|
||||
//ต้วลือกรายการครื่องราช
|
||||
const Ops = ref<InsigniaOps>({
|
||||
insigniaOptions: [],
|
||||
|
|
@ -516,7 +520,12 @@ async function addEditData(editStatus: boolean = false) {
|
|||
!editStatus && empType.value === "" ? profileId.value : undefined,
|
||||
};
|
||||
try {
|
||||
await http[method](url, reqBody);
|
||||
await http[method](url, reqBody).then(async (res) => {
|
||||
if (fileUpload.value && res.data.result) {
|
||||
await uploadProfile(res.data.result);
|
||||
}
|
||||
});
|
||||
|
||||
await fetchData();
|
||||
await success($q, "บันทึกข้อมูลสำเร็จ");
|
||||
modal.value = false;
|
||||
|
|
@ -527,6 +536,80 @@ async function addEditData(editStatus: boolean = false) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันส้ราง Path อัปโหลดไฟล์
|
||||
* @param id
|
||||
*/
|
||||
async function uploadProfile(id: string) {
|
||||
await http
|
||||
.post(
|
||||
config.API.subFile("ทะเบียนประวัติ", "เครื่องราชฯ", profileId.value, id),
|
||||
{
|
||||
replace: true,
|
||||
fileList: [
|
||||
{
|
||||
fileName: "เอกสารหลักฐาน",
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
.then(async (res) => {
|
||||
uploadUrl.value = res.data["เอกสารหลักฐาน"].uploadUrl;
|
||||
await uploadFileURL(uploadUrl.value, fileUpload.value);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันอัปโหลดำไฟล์
|
||||
* @param uploadUrl Path อัปโหลดไฟล์
|
||||
* @param file ไฟล์เอกสาร
|
||||
*/
|
||||
async function uploadFileURL(uploadUrl: string, file: any) {
|
||||
await axios
|
||||
.put(uploadUrl, file, {
|
||||
headers: {
|
||||
"Content-Type": file.type,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
fileUpload.value = undefined;
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชันโหลไฟลเอกสารหลักฐาน
|
||||
* @param id รายการที่ต้องการโหลด
|
||||
*/
|
||||
async function onDownloadFile(id: string) {
|
||||
showLoader();
|
||||
await http
|
||||
.get(
|
||||
config.API.subFileByFileName(
|
||||
"ทะเบียนประวัติ",
|
||||
"เครื่องราชฯ",
|
||||
profileId.value,
|
||||
id,
|
||||
"เอกสารหลักฐาน"
|
||||
)
|
||||
)
|
||||
.then(async (res) => {
|
||||
const data = res.data.downloadUrl;
|
||||
window.open(data, "_blank");
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
/** เปิด form ข้อมูลเครื่องราชอิสริยาภรณ์*/
|
||||
function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) {
|
||||
modal.value = true;
|
||||
|
|
@ -534,7 +617,7 @@ function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) {
|
|||
|
||||
if (editStatus && row) {
|
||||
id.value = row.id;
|
||||
insigniaType.value = row.insignia.insigniaType.name;
|
||||
insigniaType.value = row.insignia.insigniaType.id;
|
||||
insigniaForm.year = row.year;
|
||||
insigniaForm.no = row.no;
|
||||
insigniaForm.volume = row.volume;
|
||||
|
|
@ -548,6 +631,14 @@ function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) {
|
|||
insigniaForm.refCommandDate = row.refCommandDate;
|
||||
insigniaForm.refCommandNo = row.refCommandNo;
|
||||
insigniaForm.note = row.note;
|
||||
|
||||
const insigniaTypeFilter = insigniaOptionsMain.value.filter(
|
||||
(r: any) => r.typeId === insigniaType.value
|
||||
);
|
||||
if (insigniaTypeFilter.length > 0) {
|
||||
OpsFilter.value.insigniaOptions = insigniaTypeFilter;
|
||||
insigniaOptions.value = OpsFilter.value.insigniaOptions;
|
||||
}
|
||||
} else {
|
||||
clearData();
|
||||
}
|
||||
|
|
@ -610,12 +701,15 @@ function filterSelector(val: string, update: Function, refData: string) {
|
|||
}
|
||||
|
||||
/** ค้นหาลำดับชั้น*/
|
||||
function insigniaTypeSelection() {
|
||||
const insigniaTypeFilter = Ops.value.insigniaOptions.filter(
|
||||
(r: DataOptionInsignia) => r.id === insigniaForm.insigniaId
|
||||
function insigniaTypeSelection(check: boolean) {
|
||||
if (check) {
|
||||
insigniaForm.insigniaId = "";
|
||||
}
|
||||
const insigniaTypeFilter = insigniaOptionsMain.value.filter(
|
||||
(r: any) => r.typeId === insigniaType.value
|
||||
);
|
||||
if (insigniaTypeFilter.length > 0) {
|
||||
insigniaType.value = insigniaTypeFilter[0].typeName;
|
||||
OpsFilter.value.insigniaOptions = insigniaTypeFilter;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -635,6 +729,7 @@ function clearData() {
|
|||
insigniaForm.refCommandNo = "";
|
||||
insigniaForm.refCommandDate = null;
|
||||
insigniaForm.note = "";
|
||||
fileUpload.value = undefined;
|
||||
}
|
||||
|
||||
function serchDataTable() {
|
||||
|
|
@ -658,7 +753,8 @@ onMounted(async () => {
|
|||
await fetchData();
|
||||
store.insigniaOption.length === 0 ? await fetchInsignia() : "";
|
||||
Ops.value.insigniaOptions = store.insigniaOption;
|
||||
OpsFilter.value.insigniaOptions = store.insigniaOption;
|
||||
|
||||
insigniaOptionsMain.value = store.insigniaOption;
|
||||
insigniaOptions.value = store.insigniaOption;
|
||||
});
|
||||
</script>
|
||||
|
|
@ -755,6 +851,7 @@ onMounted(async () => {
|
|||
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
||||
<span class="text-weight-medium">{{ col.label }}</span>
|
||||
</q-th>
|
||||
<q-th auto-width></q-th>
|
||||
</q-tr>
|
||||
</template>
|
||||
|
||||
|
|
@ -789,6 +886,19 @@ onMounted(async () => {
|
|||
{{ col.value ? col.value : "-" }}
|
||||
</div>
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
v-if="props.row.isUpload == true"
|
||||
color="green"
|
||||
flat
|
||||
dense
|
||||
round
|
||||
icon="mdi-file-document-outline"
|
||||
@click="onDownloadFile(props.row.id)"
|
||||
>
|
||||
<q-tooltip>ดาวน์โหลด</q-tooltip>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
|
||||
|
|
@ -951,15 +1061,15 @@ onMounted(async () => {
|
|||
option-value="id"
|
||||
input-debounce="0"
|
||||
option-label="name"
|
||||
v-model="insigniaForm.insigniaId"
|
||||
v-model="insigniaType"
|
||||
class="inputgreen"
|
||||
:label="`${'ชื่อเครื่องราชฯ'}`"
|
||||
:options="insigniaOptions"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือกชื่อเครื่องราชฯ'}`]"
|
||||
:label="`${'ลำดับชั้น'}`"
|
||||
:options="store.insigniaTypeOp"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือกลำดับชั้น'}`]"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => filterSelector(inputValue, doneFn,'insigniaOptions'
|
||||
) "
|
||||
@update:modelValue="insigniaTypeSelection"
|
||||
@update:modelValue="insigniaTypeSelection(true)"
|
||||
>
|
||||
<template v-slot:no-option>
|
||||
<q-item>
|
||||
|
|
@ -971,16 +1081,39 @@ onMounted(async () => {
|
|||
</q-select>
|
||||
</div>
|
||||
<div class="col-xs-6 col-sm-6 col-md-6">
|
||||
<q-input
|
||||
<q-select
|
||||
dense
|
||||
readonly
|
||||
outlined
|
||||
:readonly="insigniaType == ''"
|
||||
use-input
|
||||
hide-selected
|
||||
fill-input
|
||||
emit-value
|
||||
lazy-rules
|
||||
map-options
|
||||
hide-bottom-space
|
||||
v-model="insigniaType"
|
||||
:label="`${'ลำดับชั้น'}`"
|
||||
/>
|
||||
option-value="id"
|
||||
input-debounce="0"
|
||||
option-label="name"
|
||||
v-model="insigniaForm.insigniaId"
|
||||
class="inputgreen"
|
||||
:label="`${'ชื่อเครื่องราชฯ'}`"
|
||||
:options="insigniaOptions"
|
||||
:rules="[(val:string) => !!val || `${'กรุณาเลือกชื่อเครื่องราชฯ'}`]"
|
||||
@filter="(inputValue:string,
|
||||
doneFn:Function) => filterSelector(inputValue, doneFn,'insigniaOptions'
|
||||
) "
|
||||
>
|
||||
<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-6 col-sm-6 col-md-6">
|
||||
<q-input
|
||||
dense
|
||||
|
|
@ -1152,6 +1285,83 @@ onMounted(async () => {
|
|||
label="หมายเหตุ"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-12">
|
||||
<div class="row">
|
||||
<q-uploader
|
||||
color="gray"
|
||||
type="file"
|
||||
flat
|
||||
ref="uploader"
|
||||
class="full-width"
|
||||
text-color="white"
|
||||
:max-size="10000000"
|
||||
accept=".pdf"
|
||||
bordered
|
||||
label="[ไฟล์ pdf ขนาดไม่เกิน 10MB]"
|
||||
@added="(v:any) => (fileUpload = v[0])"
|
||||
>
|
||||
<template v-slot:header="scope">
|
||||
<div class="row no-wrap items-center q-pa-sm q-gutter-xs">
|
||||
<q-btn
|
||||
v-if="scope.queuedFiles.length > 0"
|
||||
icon="clear_all"
|
||||
@click="scope.removeQueuedFiles"
|
||||
round
|
||||
dense
|
||||
flat
|
||||
>
|
||||
<q-tooltip>ลบทั้งหมด</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="scope.uploadedFiles.length > 0"
|
||||
icon="done_all"
|
||||
@click="scope.removeUploadedFiles"
|
||||
round
|
||||
dense
|
||||
flat
|
||||
>
|
||||
<q-tooltip>ลบไฟล์ที่อัปโหลด</q-tooltip>
|
||||
</q-btn>
|
||||
<q-spinner
|
||||
v-if="scope.isUploading"
|
||||
class="q-uploader__spinner"
|
||||
/>
|
||||
<div class="col">
|
||||
<div class="q-uploader__title">
|
||||
{{ "[ไฟล์ .pdf ขนาดไม่เกิน 10MB]" }}
|
||||
</div>
|
||||
<div class="q-uploader__subtitle">
|
||||
{{ scope.uploadSizeLabel }} /
|
||||
{{ scope.uploadProgressLabel }}
|
||||
</div>
|
||||
</div>
|
||||
<q-btn
|
||||
v-if="scope.canAddFiles"
|
||||
type="a"
|
||||
icon="add_box"
|
||||
@click="scope.pickFiles"
|
||||
round
|
||||
dense
|
||||
flat
|
||||
>
|
||||
<q-uploader-add-trigger />
|
||||
<q-tooltip>เลือกไฟล์</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
v-if="scope.isUploading"
|
||||
icon="clear"
|
||||
@click="scope.abort"
|
||||
round
|
||||
dense
|
||||
flat
|
||||
>
|
||||
<q-tooltip>ยกเลิกการอัปโหลด</q-tooltip>
|
||||
</q-btn>
|
||||
</div>
|
||||
</template>
|
||||
</q-uploader>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
<q-separator />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue