ออกคำสั่ง => API

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-25 13:57:10 +07:00
parent af491b19f9
commit 9c3e759176
3 changed files with 206 additions and 83 deletions

View file

@ -57,11 +57,11 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
{ {
name: "commandExcecuteDate", name: "commandAffectDate",
align: "left", align: "left",
label: "วันที่ลงนาม", label: "วันที่ลงนาม",
sortable: false, sortable: false,
field: "commandExcecuteDate", field: "commandAffectDate",
format(val) { format(val) {
return val ? date2Thai(val) : "-"; return val ? date2Thai(val) : "-";
}, },
@ -69,11 +69,11 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
{ {
name: "commandAffectDate", name: "commandExcecuteDate",
align: "left", align: "left",
label: "วันที่คำสั่งมีผล", label: "วันที่คำสั่งมีผล",
sortable: false, sortable: false,
field: "commandAffectDate", field: "commandExcecuteDate",
format(val) { format(val) {
return val ? date2Thai(val) : "-"; return val ? date2Thai(val) : "-";
}, },

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from "vue"; import { onBeforeMount, ref } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
@ -79,7 +79,7 @@ function onConfirmSignature() {
); );
} }
onMounted(async () => { onBeforeMount(async () => {
await fetchData(); await fetchData();
}); });
</script> </script>

View file

@ -1,12 +1,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { onBeforeMount, onMounted, ref } from "vue"; import { onBeforeMount, onMounted, ref } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import axios from "axios";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useCommandDetail } from "@/modules/18_command/store/DetailStore"; import { useCommandDetail } from "@/modules/18_command/store/DetailStore";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
import { log } from "console";
const $q = useQuasar(); const $q = useQuasar();
const route = useRoute(); const route = useRoute();
@ -86,6 +88,111 @@ async function updateCheckboxAuthority(val: boolean) {
}); });
} }
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();
});
}
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();
});
}
/**
* ดาวนโหลดลงกไฟล
* @param fileName file name
*/
function downloadFile(file: any, group: string) {
let type = group === "order" ? "คำสั่ง" : "แนบท้าย";
showLoader();
http
.get(
config.API.fileByFile(
"ระบบออกคำสั่ง",
type,
commandId.value,
file.fileName
)
)
.then((res) => {
const data = res.data.downloadUrl;
window.open(data, "_blank");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
}
/** /**
* งกนยนยนการสงออกคำส * งกนยนยนการสงออกคำส
*/ */
@ -125,9 +232,20 @@ function onConfirmOrder() {
} }
} }
onMounted(() => { onMounted(async () => {
isCheckDraft.value = isDraft.value; isCheckDraft.value = isDraft.value;
isCheckAuthority.value = isAuthority.value; isCheckAuthority.value = isAuthority.value;
if (step.value > 1) {
showLoader();
let promises = [fetchDoc("order")];
if (isAttachment.value) {
promises.push(fetchDoc("tailer"));
}
await Promise.all(promises).finally(() => {
hideLoader();
});
}
}); });
</script> </script>
@ -176,108 +294,113 @@ onMounted(() => {
/> />
</div> </div>
<div <div class="col-6" style="padding-left: 50px" v-if="isAuthority">
:class="isAttachment ? 'col-12' : 'col-6'"
style="padding-left: 50px"
v-if="isAuthority"
>
<fieldset class="border q-px-lg q-py-sm"> <fieldset class="border q-px-lg q-py-sm">
<legend class="text-header q-px-sm"> <legend class="text-header q-px-sm">
ปโหลดเอกสารสแกนกลบเขาสระบบ ปโหลดเอกสารสแกนกลบเขาสระบบ
</legend> </legend>
<div class="row q-col-gutter-md q-mb-md"> <div class="row q-col-gutter-md q-mb-md">
<!-- คำส --> <!-- คำส -->
<div :class="isAttachment ? 'col-6' : 'col-12'"> <div class="col-12">
<label class="text-file">คำส</label> <label class="text-file">คำส</label>
<div class="text-right" v-if="fileOrder"> <div v-if="fileOrder">
<q-btn flat dense color="primary" icon="mdi-eye" rounded>
<q-tooltip>ไฟลคำส</q-tooltip>
</q-btn>
<!-- :href="OrderPDFUpload" -->
<q-btn <q-btn
rounded
type="a"
flat flat
dense dense
color="red" color="primary"
icon="mdi-download" icon="mdi-eye"
target="_blank" rounded
@click.prevent="downloadFile(fileOrder, 'order')"
> >
<q-tooltip>ไฟลคำส</q-tooltip>
</q-btn>
<q-btn rounded flat dense color="red" icon="mdi-download">
<q-tooltip>ดาวนโหลดไฟลคำส</q-tooltip> <q-tooltip>ดาวนโหลดไฟลคำส</q-tooltip>
</q-btn> </q-btn>
</div> </div>
<q-file
v-if="step === 2" <div class="row q-col-gutter-sm">
outlined <div class="col-11">
dense <q-file
v-model="fileUploadOrder" v-if="step === 2 && !store.readonly"
label="เลือกไฟล์คำสั่ง" outlined
hide-bottom-space dense
:rules="[(val:string) => val || 'กรุณาเลือกไฟล์ไฟล์คำสั่ง']" v-model="fileUploadOrder"
accept=".pdf" label="เลือกไฟล์คำสั่ง"
:readonly="store.readonly" hide-bottom-space
> accept=".pdf"
<template v-slot:prepend> :readonly="store.readonly"
<q-icon name="attach_file" /> >
</template> <template v-slot:prepend>
</q-file> <q-icon name="attach_file" />
</template>
</q-file>
</div>
<div class="col-1" v-if="!store.readonly && step === 2">
<q-btn
@click.prevent="onUploadFile('order')"
flat
round
icon="mdi-upload"
:color="fileUploadOrder == null ? 'grey-5' : 'blue-5'"
:disable="fileUploadOrder == null"
/>
<q-tooltip>ปโหลดไฟลคำส</q-tooltip>
</div>
</div>
</div> </div>
<!-- เอกสารแนบทาย --> <!-- เอกสารแนบทาย -->
<div v-if="isAttachment" class="col-6"> <div v-if="isAttachment" class="col-12">
<label class="text-file">เอกสารแนบทาย</label> <label class="text-file">เอกสารแนบทาย</label>
<div class="text-right" v-if="fileTailer"> <div v-if="fileTailer">
<q-btn flat dense color="primary" icon="mdi-eye" rounded>
<q-tooltip>เอกสารแนบทาย</q-tooltip>
</q-btn>
<!-- :href="TailerPDFUpload" -->
<q-btn <q-btn
type="a"
rounded
flat flat
dense dense
color="red" color="primary"
icon="mdi-download" icon="mdi-eye"
target="_blank" rounded
@click.prevent="downloadFile(fileTailer, 'tailer')"
> >
<q-tooltip>เอกสารแนบทาย</q-tooltip>
</q-btn>
<q-btn rounded flat dense color="red" icon="mdi-download">
<q-tooltip>ดาวนโหลดเอกสารแนบทาย</q-tooltip> <q-tooltip>ดาวนโหลดเอกสารแนบทาย</q-tooltip>
</q-btn> </q-btn>
</div> </div>
<q-file <div class="row q-col-gutter-sm">
v-if="step === 2" <div class="col-11">
outlined <q-file
dense v-if="step === 2 && !store.readonly"
v-model="fileUploadTailer" outlined
label="เลือกไฟล์เอกสารแนบท้าย" dense
hide-bottom-space v-model="fileUploadTailer"
:rules="[(val:string) => val || 'กรุณาเลือกไฟล์เอกสารแนบท้าย']" label="เลือกไฟล์เอกสารแนบท้าย"
accept=".pdf" hide-bottom-space
:readonly="store.readonly" accept=".pdf"
> :readonly="store.readonly"
<template v-slot:prepend> >
<q-icon name="attach_file" /> <template v-slot:prepend>
</template> <q-icon name="attach_file" />
</q-file> </template>
</div> </q-file>
</div>
<div class="row col-12" v-if="!store.readonly"> <div class="col-1" v-if="!store.readonly && step === 2">
<q-space /> <q-btn
<q-btn @click.prevent="onUploadFile('tailer')"
icon="mdi-upload" flat
label="อัปโหลดเอกสารส" round
:color=" icon="mdi-upload"
fileUploadOrder == null || :color="fileUploadTailer == null ? 'grey-5' : 'blue-5'"
(isAttachment && fileUploadTailer === null) :disable="fileUploadTailer == null"
? 'grey-5' />
: 'blue-5' <q-tooltip>ปโหลดไฟลเอกสารแนบทาย</q-tooltip>
" </div>
:disable=" </div>
fileUploadOrder == null ||
(isAttachment && fileUploadTailer === null)
"
>
</q-btn>
</div> </div>
</div> </div>
</fieldset> </fieldset>
@ -289,7 +412,7 @@ onMounted(() => {
step === 2 && step === 2 &&
isAuthority && isAuthority &&
fileOrder && fileOrder &&
(isAttachment || fileTailer) (!isAttachment || fileTailer)
" "
> >
<q-btn <q-btn