อกกคำสั่ง => report
This commit is contained in:
parent
4986a17e06
commit
6399e23d28
1 changed files with 49 additions and 117 deletions
|
|
@ -39,13 +39,11 @@ const fileTailer = ref<any>(null);
|
||||||
const OrderPDFUpload = ref<string>("");
|
const OrderPDFUpload = ref<string>("");
|
||||||
const TailerPDFUpload = ref<string>("");
|
const TailerPDFUpload = ref<string>("");
|
||||||
|
|
||||||
const orderCoverPdf = ref<any>();
|
|
||||||
const orderAttachmentPdf = ref<string>("");
|
const orderAttachmentPdf = ref<string>("");
|
||||||
|
|
||||||
const statusOrder = ref<string>();
|
const statusOrder = ref<string>();
|
||||||
const orderName = ref<string>("");
|
const orderName = ref<string>("");
|
||||||
const orderStatusName = ref<string>("");
|
const orderStatusName = ref<string>("");
|
||||||
const dataGen = ref<any>();
|
|
||||||
|
|
||||||
const orderId = ref<string>(orderId_params.toString());
|
const orderId = ref<string>(orderId_params.toString());
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
@ -108,132 +106,81 @@ const getCommandDetail = async () => {
|
||||||
orderStatusName.value = data.orderStatusName;
|
orderStatusName.value = data.orderStatusName;
|
||||||
|
|
||||||
fetchReportCover("pdf", orderId.value);
|
fetchReportCover("pdf", orderId.value);
|
||||||
|
|
||||||
if (attachmentStatus.value) {
|
|
||||||
fetchReportAttachment("pdf", orderId.value);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
messageError($q, e);
|
messageError($q, e);
|
||||||
|
hideLoader();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// โหลดคำสั่ง
|
// โหลดคำสั่ง
|
||||||
const downloadCover = async (type: string) => {
|
const downloadCover = async (type: string) => {
|
||||||
showLoader();
|
genReport(dataCover.value, `คำสั่ง ${orderName.value}`, type);
|
||||||
|
|
||||||
if (!genReportStatus.value) {
|
|
||||||
await http
|
|
||||||
.get(config.API.fileCover(code.value, type, orderId.value), {
|
|
||||||
responseType: "blob",
|
|
||||||
})
|
|
||||||
.then(async (res) => {
|
|
||||||
downloadFile(res, `คำสั่ง ${orderName.value}.${type}`);
|
|
||||||
})
|
|
||||||
.catch(async (e) => {
|
|
||||||
messageError($q, JSON.parse(await e.response.data.text()));
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
hideLoader();
|
|
||||||
});
|
|
||||||
} else if (type === "docx") {
|
|
||||||
genReport(dataGen.value, `คำสั่ง ${orderName.value}`, "docx");
|
|
||||||
} else {
|
|
||||||
const link = document.createElement("a");
|
|
||||||
var fileName = `คำสั่ง ${orderName.value}.${
|
|
||||||
type === "docx" ? "docx" : "pdf"
|
|
||||||
}`;
|
|
||||||
link.href = orderCoverPdf.value;
|
|
||||||
link.setAttribute("download", fileName);
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
hideLoader();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// โหลด เอกสารแนบท้าย
|
// โหลด เอกสารแนบท้าย
|
||||||
const downloadAttachment = async (type: string) => {
|
const downloadAttachment = async (type: string) => {
|
||||||
|
genReport(dataAttachment.value, `คำสั่ง ${orderName.value}`, type);
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataCover = ref<any>();
|
||||||
|
// เรียกไฟล์ คำสั่ง
|
||||||
|
const fetchReportCover = async (type: string, orderId: string) => {
|
||||||
showLoader();
|
showLoader();
|
||||||
await http
|
await http
|
||||||
.get(config.API.fileAttachment(code.value, type, orderId.value), {
|
.get(config.API.reportOrderCover(type, orderId, code.value))
|
||||||
responseType: "blob",
|
.then(async (res: any) => {
|
||||||
})
|
genPDf(res.data.result);
|
||||||
.then(async (res) => {
|
dataCover.value = res.data.result;
|
||||||
downloadFile(res, `เอกสารแนบท้าย ${orderName.value}.${type}`);
|
|
||||||
})
|
})
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
messageError($q, JSON.parse(await e.response.data.text()));
|
messageError($q, e);
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
hideLoader();
|
hideLoader();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// เรียกไฟล์ คำสั่ง
|
|
||||||
const fetchReportCover = async (type: string, orderId: string) => {
|
const dataAttachment = ref<any>();
|
||||||
await http
|
|
||||||
.get(
|
|
||||||
config.API.reportOrderCover(type, orderId, code.value),
|
|
||||||
!genReportStatus.value
|
|
||||||
? {
|
|
||||||
responseType: "blob",
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
)
|
|
||||||
.then(async (res: any) => {
|
|
||||||
if (!genReportStatus.value) {
|
|
||||||
const blob = new Blob([res.data]);
|
|
||||||
const objectUrl = URL.createObjectURL(blob);
|
|
||||||
orderCoverPdf.value = objectUrl;
|
|
||||||
if (tab.value == "main") {
|
|
||||||
viewPDF(orderCoverPdf.value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// report template
|
|
||||||
dataGen.value = res.data.result;
|
|
||||||
await axios
|
|
||||||
.post(`${config.API.reportTemplate}/docx`, res.data.result, {
|
|
||||||
headers: {
|
|
||||||
accept: "application/pdf",
|
|
||||||
"content-Type": "application/json",
|
|
||||||
},
|
|
||||||
responseType: "blob",
|
|
||||||
})
|
|
||||||
.then((resReport) => {
|
|
||||||
const data = resReport.data;
|
|
||||||
if (data) {
|
|
||||||
const blob = new Blob([data]);
|
|
||||||
const objectUrl = URL.createObjectURL(blob);
|
|
||||||
orderCoverPdf.value = objectUrl;
|
|
||||||
viewPDF(orderCoverPdf.value);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(async (e) => {
|
|
||||||
messageError($q, JSON.parse(await e.response.data.text()));
|
|
||||||
})
|
|
||||||
.finally(() => {});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(async (e) => {
|
|
||||||
!genReportStatus.value
|
|
||||||
? messageError($q, JSON.parse(await e.response.data.text()))
|
|
||||||
: messageError($q, e);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
// เรียกไฟล์ เอกสารแนบท้าย
|
// เรียกไฟล์ เอกสารแนบท้าย
|
||||||
const fetchReportAttachment = async (type: string, orderId: string) => {
|
const fetchReportAttachment = async (type: string, orderId: string) => {
|
||||||
|
showLoader();
|
||||||
await http
|
await http
|
||||||
.get(config.API.reportOrderAttachment(type, orderId, code.value), {
|
.get(config.API.reportOrderAttachment(type, orderId, code.value))
|
||||||
|
.then(async (res) => {
|
||||||
|
genPDf(res.data.result);
|
||||||
|
dataAttachment.value = res.data.result;
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
messageError($q, e);
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function genPDf(data: any) {
|
||||||
|
axios
|
||||||
|
.post(config.API.reportTemplate + `/docx`, data, {
|
||||||
|
headers: {
|
||||||
|
accept: "application/pdf",
|
||||||
|
"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);
|
||||||
orderAttachmentPdf.value = objectUrl;
|
|
||||||
|
const pdfData = await usePDF(`${objectUrl}`);
|
||||||
|
showLoader();
|
||||||
|
setTimeout(() => {
|
||||||
|
pdfSrc.value = pdfData.pdf.value;
|
||||||
|
numOfPages.value = pdfData.pages.value;
|
||||||
|
hideLoader();
|
||||||
|
}, 1500);
|
||||||
})
|
})
|
||||||
.catch(async (e) => {
|
.catch(async (e) => {
|
||||||
messageError($q, JSON.parse(await e.response.data.text()));
|
messageError($q, e);
|
||||||
|
hideLoader();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
// Fetch file upload & detail
|
// Fetch file upload & detail
|
||||||
const fetchAttachment = async (orderId: string) => {
|
const fetchAttachment = async (orderId: string) => {
|
||||||
|
|
@ -241,6 +188,7 @@ const fetchAttachment = async (orderId: string) => {
|
||||||
.get(config.API.attachmentOrder(orderId))
|
.get(config.API.attachmentOrder(orderId))
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
let response = res.data.result;
|
let response = res.data.result;
|
||||||
|
|
||||||
order.value = response.orderNo;
|
order.value = response.orderNo;
|
||||||
years.value = Number(response.orderYear);
|
years.value = Number(response.orderYear);
|
||||||
if (response.signDate !== undefined && response.signDate != "") {
|
if (response.signDate !== undefined && response.signDate != "") {
|
||||||
|
|
@ -292,10 +240,10 @@ const viewPDFUpload = async (pdf: string) => {
|
||||||
|
|
||||||
watch(tab, () => {
|
watch(tab, () => {
|
||||||
if (tab.value === "main") {
|
if (tab.value === "main") {
|
||||||
viewPDF(orderCoverPdf.value);
|
fetchReportCover("pdf", orderId.value);
|
||||||
}
|
}
|
||||||
if (tab.value === "second") {
|
if (tab.value === "second") {
|
||||||
viewPDF(orderAttachmentPdf.value);
|
fetchReportAttachment("pdf", orderId.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -327,16 +275,6 @@ const onchangePage = () => {
|
||||||
vuePDFRef.value.reload();
|
vuePDFRef.value.reload();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// ดาวน์โหลดไฟล์
|
|
||||||
const downloadFile = (response: any, filename: string) => {
|
|
||||||
const link = document.createElement("a");
|
|
||||||
var fileName = filename;
|
|
||||||
link.href = window.URL.createObjectURL(new Blob([response.data]));
|
|
||||||
link.setAttribute("download", fileName);
|
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
};
|
|
||||||
|
|
||||||
// การอัพโหลดไฟล์คำสั่งและเอกสารแนบท้าย
|
// การอัพโหลดไฟล์คำสั่งและเอกสารแนบท้าย
|
||||||
const saveUpload = () => {
|
const saveUpload = () => {
|
||||||
|
|
@ -526,9 +464,6 @@ const viewFileUpload = async (url: string) => {
|
||||||
v-close-popup
|
v-close-popup
|
||||||
@click="downloadCover('pdf')"
|
@click="downloadCover('pdf')"
|
||||||
>
|
>
|
||||||
<!-- type="a"
|
|
||||||
:href="orderCoverPdf"
|
|
||||||
target="_blank" -->
|
|
||||||
<q-item-section avatar
|
<q-item-section avatar
|
||||||
><q-icon color="red" name="mdi-file-pdf"
|
><q-icon color="red" name="mdi-file-pdf"
|
||||||
/></q-item-section>
|
/></q-item-section>
|
||||||
|
|
@ -539,9 +474,6 @@ const viewFileUpload = async (url: string) => {
|
||||||
v-close-popup
|
v-close-popup
|
||||||
@click="downloadCover('docx')"
|
@click="downloadCover('docx')"
|
||||||
>
|
>
|
||||||
<!-- type="a"
|
|
||||||
:href="orderCoverDocs"
|
|
||||||
target="_blank" -->
|
|
||||||
<q-item-section avatar
|
<q-item-section avatar
|
||||||
><q-icon color="blue" name="mdi-file-word"
|
><q-icon color="blue" name="mdi-file-word"
|
||||||
/></q-item-section>
|
/></q-item-section>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue