แก้ แสดง error

This commit is contained in:
setthawutttty 2025-07-29 11:12:06 +07:00
parent f732b87763
commit 95ebd013e4

View file

@ -17,12 +17,9 @@ const { dialogConfirm, success, showLoader, hideLoader, messageError } = mixin;
const commandId = defineModel<string>("commandId", { required: true }); // id const commandId = defineModel<string>("commandId", { required: true }); // id
const type = defineModel<string>("type", { required: true }); // tab const type = defineModel<string>("type", { required: true }); // tab
// //
const dataTemplateDetail = defineModel<DataTemplateDetail>( const dataTemplate = defineModel<DataTemplateDetail>("dataTemplateDetail", {
"dataTemplateDetail", required: true,
{ });
required: true,
}
);
const documentFile = ref<File | null>(null); // file const documentFile = ref<File | null>(null); // file
const isLoadPDF = ref<boolean>(false); // Loading display pdf const isLoadPDF = ref<boolean>(false); // Loading display pdf
@ -57,69 +54,71 @@ const { fetchDataTemplate } = defineProps({
* @param dataTemple รายละเอยดคำส * @param dataTemple รายละเอยดคำส
*/ */
async function fetchDocumentTemplate(dataTemple: DataTemplateDetail) { async function fetchDocumentTemplate(dataTemple: DataTemplateDetail) {
showLoader(); if (dataTemple) {
isLoadPDF.value = false; showLoader();
pdfSrc.value = undefined; isLoadPDF.value = false;
page.value = 1; pdfSrc.value = undefined;
const reportName = await `${dataTemplateDetail.value.code}_${type.value}`; page.value = 1;
const body = { const reportName = `${dataTemple.code}_${type.value}`;
template: reportName, const body = {
reportName: `${typeFile.value}-report`, template: reportName,
data: { reportName: `${typeFile.value}-report`,
issue: "............", // data: {
title: "......", // issue: "............", //
commandNo: "......", title: "......", //
commandYear: "......", commandNo: "......",
commandTitle: dataTemple.name, commandYear: "......",
detailHeader: dataTemple.detailHeader, commandTitle: dataTemple.name,
detailBody: dataTemple.detailBody, detailHeader: dataTemple.detailHeader,
detailFooter: dataTemple.detailFooter, detailBody: dataTemple.detailBody,
commandDate: "..................", detailFooter: dataTemple.detailFooter,
commandAffectDate: "..................", commandDate: "..................",
commandExcecuteDate: "..................", commandAffectDate: "..................",
name: "....................................", commandExcecuteDate: "..................",
name1: dataTemple.name1, name: "....................................",
name2: dataTemple.name2, name1: dataTemple.name1,
name3: dataTemple.name3, name2: dataTemple.name2,
name4: dataTemple.name4, name3: dataTemple.name3,
position: "ผู้อำนวยการสำนัก/เขต", name4: dataTemple.name4,
authorizedUserFullName: "............", position: "ผู้อำนวยการสำนัก/เขต",
authorizedPosition: "...................", authorizedUserFullName: "............",
...(dataTemple.persons ? { persons: dataTemple.persons } : {}), authorizedPosition: "...................",
}, ...(dataTemple.persons ? { persons: dataTemple.persons } : {}),
}; },
};
await axios await axios
.post( .post(
config.API.reportTemplate + `/${typeFile.value}?folder=command`, config.API.reportTemplate + `/${typeFile.value}?folder=command`,
body, body,
{ {
headers: { headers: {
accept: "application/pdf", accept: "application/pdf",
"content-Type": "application/json", "content-Type": "application/json",
}, },
responseType: "blob", responseType: "blob",
} }
) )
.then(async (res) => { .then(async (res) => {
const blob = new Blob([res.data]); const blob = new Blob([res.data]);
const objectUrl = URL.createObjectURL(blob); const objectUrl = URL.createObjectURL(blob);
const pdfData = await usePDF(`${objectUrl}`); const pdfData = await usePDF(`${objectUrl}`);
// PDF // PDF
setTimeout(() => { setTimeout(() => {
pdfSrc.value = pdfData.pdf.value; pdfSrc.value = pdfData.pdf.value;
numOfPages.value = pdfData.pages.value; numOfPages.value = pdfData.pages.value;
isLoadPDF.value = true; isLoadPDF.value = true;
hideLoader();
}, 1500);
})
.catch((e) => {
// Template
messageError($q, "", "ไม่พบข้อมูล Template");
isLoadPDF.value = false;
hideLoader(); hideLoader();
}, 1500); });
}) }
.catch((e) => {
// Template
messageError($q, "", "ไม่พบข้อมูล Template");
isLoadPDF.value = false;
hideLoader();
});
} }
/** /**
@ -130,7 +129,7 @@ async function uploadTemplate() {
$q, $q,
async () => { async () => {
showLoader(); showLoader();
const reportName = await `${dataTemplateDetail.value.code}_${type.value}`; const reportName = await `${dataTemplate.value.code}_${type.value}`;
await axios await axios
.post( .post(
config.API.reportTemplate + config.API.reportTemplate +
@ -150,7 +149,7 @@ async function uploadTemplate() {
hideLoader(); hideLoader();
// Template UI // Template UI
fetchDocumentTemplate(dataTemplateDetail.value); fetchDocumentTemplate(dataTemplate.value);
fetchDataTemplate(commandId.value); fetchDataTemplate(commandId.value);
}) })
.catch(async (e) => { .catch(async (e) => {
@ -170,8 +169,8 @@ async function uploadTemplate() {
*/ */
async function downloadTemplate() { async function downloadTemplate() {
const check = await (type.value == "cover" const check = await (type.value == "cover"
? dataTemplateDetail.value.fileCover ? dataTemplate.value.fileCover
: dataTemplateDetail.value.fileAttachment); : dataTemplate.value.fileAttachment);
await axios await axios
.post( .post(
config.API.reportTemplate + `/${typeFile.value}/download?folder=command`, config.API.reportTemplate + `/${typeFile.value}/download?folder=command`,
@ -189,7 +188,7 @@ async function downloadTemplate() {
.then(async (res) => { .then(async (res) => {
var a = document.createElement("a"); var a = document.createElement("a");
a.href = URL.createObjectURL(res.data); a.href = URL.createObjectURL(res.data);
a.download = `${dataTemplateDetail.value.code}_${type.value}.${typeFile.value}`; a.download = `${dataTemplate.value.code}_${type.value}.${typeFile.value}`;
a.click(); a.click();
hideLoader(); hideLoader();
}) })
@ -217,17 +216,16 @@ async function updateReportName(name: string) {
} }
// working on click command list // working on click command list
watch(dataTemplateDetail, () => { watch(
fetchDocumentTemplate(dataTemplateDetail.value); () => dataTemplate.value,
}); async (newValue, oldValue) => {
await fetchDocumentTemplate(newValue);
}
);
// working on change tab // working on change tab
onMounted(() => { onMounted(() => {
fetchDocumentTemplate(dataTemplateDetail.value); fetchDocumentTemplate(dataTemplate.value);
});
defineExpose({
fetchDocumentTemplate,
}); });
</script> </script>