แก้ แสดง error
This commit is contained in:
parent
f732b87763
commit
95ebd013e4
1 changed files with 77 additions and 79 deletions
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue