diff --git a/src/modules/10_order/components/step/step04.vue b/src/modules/10_order/components/step/step04.vue index b2747c8cd..0ac4959ff 100644 --- a/src/modules/10_order/components/step/step04.vue +++ b/src/modules/10_order/components/step/step04.vue @@ -8,6 +8,7 @@ import { useQuasar } from "quasar"; import { useRoute } from "vue-router"; import http from "@/plugins/http"; import config from "@/app.config"; +import { aW } from "@fullcalendar/core/internal-common"; const mixin = useCounterMixin(); const { @@ -47,23 +48,24 @@ const orderStatusName = ref(""); const orderId = ref(orderId_params.toString()); onMounted(async () => { if (orderId.value) { - fetchAttachment(orderId.value); - fecthstatusOrder(orderId.value); - getType(); + showLoader() + await fetchAttachment(orderId.value); + await fecthstatusOrder(); + await getCommandDetail(); + hideLoader() } }); -const getType = async () => { - showLoader(); +const getCommandDetail = async () => { await http .get(config.API.detailOrder(orderId.value)) .then(async (res) => { - const data = res.data.result; - const orderTypeCode = data.orderTypeCode; + const data = await res.data.result; + const orderTypeCode = await data.orderTypeCode; code.value = orderTypeCode ?? ""; orderName.value = res.data.result.orderTitle; orderStatusName.value = data.orderStatusName; - console.log(orderStatusName.value); + // console.log(orderStatusName.value); fetchReportCover("pdf", orderId.value); fetchReportAttachment("pdf", orderId.value); @@ -71,9 +73,6 @@ const getType = async () => { .catch((e) => { messageError($q, e); }) - .finally(() => { - hideLoader(); - }); }; const downloadCover = async (type: string) => { @@ -111,27 +110,22 @@ const downloadAttachment = async (type: string) => { }; const fetchReportCover = async (type: string, orderId: string) => { - showLoader(); await http .get(config.API.reportOrderCover(type, orderId, code.value), { responseType: "blob", }) - .then(async (res) => { + .then((res) => { const blob = new Blob([res.data]); const objectUrl = URL.createObjectURL(blob); orderCoverPdf.value = objectUrl; viewPDF(orderCoverPdf.value); }) .catch((e) => { - // messageError($q, e); + messageError($q, e); }) - .finally(() => { - hideLoader(); - }); }; const fetchReportAttachment = async (type: string, orderId: string) => { - showLoader(); await http .get(config.API.reportOrderAttachment(type, orderId, code.value), { responseType: "blob", @@ -142,15 +136,12 @@ const fetchReportAttachment = async (type: string, orderId: string) => { orderAttachmentPdf.value = objectUrl; }) .catch((e) => { - // messageError($q, e); + messageError($q, e); }) - .finally(() => { - hideLoader(); - }); }; +// Fetch file upload & detail const fetchAttachment = async (orderId: string) => { - showLoader(); await http .get(config.API.attachmentOrder(orderId)) .then(async (res) => { @@ -171,14 +162,11 @@ const fetchAttachment = async (orderId: string) => { .catch((e) => { messageError($q, e); }) - .finally(() => { - hideLoader(); - }); }; -const fecthstatusOrder = async (orderId: string) => { +const fecthstatusOrder = async () => { await http - .get(config.API.orderReady(orderId)) + .get(config.API.orderReady(orderId.value)) .then((res) => { let status = res.data.result; statusOrder.value = status.result; @@ -187,6 +175,7 @@ const fecthstatusOrder = async (orderId: string) => { messageError($q, e); }); }; + const viewPDF = async (pdf: string) => { const pdfData = await usePDF(`${pdf}`); showLoader(); @@ -224,6 +213,7 @@ const page = ref(1); const vuePDFRef = ref(null); const myForm = ref(null); +const myFormUpload = ref(null); const props = defineProps({ next: { @@ -256,16 +246,33 @@ const downloadFile = (response: any, filename: string) => { document.body.removeChild(link); }; -const save = () => { +const saveUpload = () => { + if (myFormUpload.value !== null) { + myFormUpload.value!.validate().then((success: Boolean) => { + if (success) { + dialogConfirm($q, async () => { + showLoader() + await postfileOrder(); + await postfileTailer(); + await fetchAttachment(orderId.value); + await fecthstatusOrder(); + hideLoader() + }); + } + }); + } +}; + +const saveDetail = () => { if (myForm.value !== null) { myForm.value!.validate().then((success: Boolean) => { if (success) { dialogConfirm($q, async () => { + showLoader(); await putOrderData(); - await postfileOrder(); - await postfileTailer(); - await fetchAttachment(orderId.value); - await fecthstatusOrder(orderId.value); + await fetchReportCover("pdf", orderId.value); + await fecthstatusOrder(); + hideLoader(); }); } }); @@ -293,45 +300,60 @@ const postfileOrder = async () => { formData.append("File", fileOrder.value); await http .post(config.API.attachmentOrderId(orderId.value), formData) - .then(() => { - // fileOrder.value = null - }); + .catch((e) => { + messageError($q, e) + }) }; + const postfileTailer = async () => { const formData = new FormData(); formData.append("File", fileTailer.value); await http .post(config.API.attachmentFileId(orderId.value), formData) - .then(() => { - //fileTailer.value = null - }); + .then(()=>{ + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((e) => { + messageError($q, e) + }) }; const clickExecute = async (id: string) => { dialogConfirm( $q, async () => { + showLoader() await http .put(config.API.executeOrder(id)) .then((res) => { - console.log(res); + success($q, "ออกคำสั่งสำเร็จ"); }) .catch((e) => { messageError($q, e); - }); + }).finally(async()=> { + await fecthstatusOrder() + await getCommandDetail() + hideLoader(); + }) }, "ยืนยันการออกคำสั่ง", "ต้องการยืนยันการออกคำสั่งนี้ใช่หรือไม่?" ); }; -const validateForm = () => { +const validateFormUpload = () => { return ( fileOrder.value !== null && - fileOrder.value !== null && + fileTailer.value !== null + ); +}; + +const validateForm = () => { + return ( order.value.trim() !== "" ); }; + const getClass = (val: boolean) => { return { "card-header-active q-px-lg q-py-md cursor-pointer": val, @@ -354,105 +376,60 @@ const viewFileUpload = async (url: string) => {