Refactoring code module 02_transfer
This commit is contained in:
parent
8a31554f38
commit
9fbbbd753f
3 changed files with 135 additions and 84 deletions
|
|
@ -2,47 +2,27 @@
|
|||
import { ref, onMounted } from "vue";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
import http from "@/plugins/http";
|
||||
import config from "@/app.config";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
import type { QForm } from "quasar";
|
||||
|
||||
const router = useRouter();
|
||||
const $q = useQuasar();
|
||||
const mixin = useCounterMixin();
|
||||
const myform = ref<QForm | null>(null);
|
||||
const {
|
||||
fails,
|
||||
success,
|
||||
messageError,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
dialogConfirm,
|
||||
dialogMessageNotify,
|
||||
} = mixin;
|
||||
|
||||
/**
|
||||
* ตัวแปรที่ใช้งาน
|
||||
*/
|
||||
const route = useRoute();
|
||||
const files = ref<any>();
|
||||
const tranferOrg = ref("");
|
||||
const noteReason = ref("");
|
||||
const id = ref<string>("");
|
||||
const nameFile = ref<string>("");
|
||||
const routeName = router.currentRoute.value.name;
|
||||
const router = useRouter();
|
||||
const mixin = useCounterMixin();
|
||||
const { success, messageError, showLoader, hideLoader, dialogConfirm } = mixin;
|
||||
|
||||
/**
|
||||
* เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้
|
||||
*/
|
||||
onMounted(() => {
|
||||
if (route.params.id !== undefined) {
|
||||
id.value = route.params.id.toString();
|
||||
fecthDataTransfer(id.value);
|
||||
}
|
||||
});
|
||||
const id = ref<string>(""); //id path
|
||||
const files = ref<any>(); //ไฟล์
|
||||
const tranferOrg = ref<string>(""); //ชื่อหน่วยงานที่ขอโอนไป
|
||||
const noteReason = ref<string>(""); //เหตุผล
|
||||
const routeName = router.currentRoute.value.name; //ชื่อ path
|
||||
|
||||
const saveData = async () => {
|
||||
/** Dialog Save */
|
||||
async function saveData() {
|
||||
dialogConfirm(
|
||||
$q,
|
||||
() => {
|
||||
|
|
@ -51,12 +31,10 @@ const saveData = async () => {
|
|||
"ยืนยันการยื่นข้อมูลการโอน",
|
||||
"ต้องการยื่นข้อมูลการโอนนี้ใช่หรือไม่"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชั่นสร้างขอโอน
|
||||
*/
|
||||
const createTransfer = async () => {
|
||||
/** ฟังก์ชั่นสร้างขอโอน */
|
||||
async function createTransfer() {
|
||||
showLoader();
|
||||
const formData = new FormData();
|
||||
formData.append("Organization", tranferOrg.value);
|
||||
|
|
@ -74,13 +52,13 @@ const createTransfer = async () => {
|
|||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชั่นเรียกข้อมูลจาก Api
|
||||
* @param id ไอดีของข้อมูล
|
||||
*/
|
||||
const fecthDataTransfer = async (id: string) => {
|
||||
async function fecthDataTransfer(id: string) {
|
||||
showLoader();
|
||||
await http
|
||||
.get(config.API.transferByid(id))
|
||||
|
|
@ -96,25 +74,25 @@ const fecthDataTransfer = async (id: string) => {
|
|||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* ฟังก์ชั่นดาว์โหลดอัปโหลดไฟล์
|
||||
* Func เปิดไฟล์
|
||||
* @param url URL File
|
||||
*/
|
||||
const fileDocDataUpload = ref<File[]>([]);
|
||||
const filesNull = () => {
|
||||
files.value = null;
|
||||
};
|
||||
//อัปโหลดไฟล์
|
||||
const fileUploadDoc = async (file: any) => {
|
||||
fileDocDataUpload.value.push(file);
|
||||
nameFile.value = file[0].name;
|
||||
files.value = file;
|
||||
};
|
||||
|
||||
function fileOpen(url: string) {
|
||||
window.open(url, "_blank");
|
||||
}
|
||||
|
||||
/**
|
||||
* เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้
|
||||
*/
|
||||
onMounted(() => {
|
||||
if (route.params.id !== undefined) {
|
||||
id.value = route.params.id.toString();
|
||||
fecthDataTransfer(id.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue