From 9fbbbd753f68ab6fb8079d1e1c2081023d43b2ce Mon Sep 17 00:00:00 2001 From: "STW_TTTY\\stwtt" Date: Mon, 2 Sep 2024 18:11:27 +0700 Subject: [PATCH] Refactoring code module 02_transfer --- src/modules/02_transfer/interface/Main.ts | 53 ++++++++++++ src/modules/02_transfer/views/AddTransfer.vue | 84 +++++++------------ src/modules/02_transfer/views/Main.vue | 82 +++++++++++------- 3 files changed, 135 insertions(+), 84 deletions(-) create mode 100644 src/modules/02_transfer/interface/Main.ts diff --git a/src/modules/02_transfer/interface/Main.ts b/src/modules/02_transfer/interface/Main.ts new file mode 100644 index 0000000..afe5a10 --- /dev/null +++ b/src/modules/02_transfer/interface/Main.ts @@ -0,0 +1,53 @@ +interface TransferMain { + id: string; + date: string; + status: string; + statustext: string; + position: string; + noPos: string; + rootShortNameOld: string; + level: string; + salary: number; + transfer: string; +} + +interface TransferList { + id: string; + profileId: string; + prefix: string; + firstName: string; + lastName: string; + rootOld: string; + rootOldId: string; + rootShortNameOld: string; + child1Old: string | null; + child1OldId: string | null; + child1ShortNameOld: string | null; + child2Old: string | null; + child2OldId: string | null; + child2ShortNameOld: string | null; + child3Old: string | null; + child3OldId: string | null; + child3ShortNameOld: string | null; + child4Old: string | null; + child4OldId: string | null; + child4ShortNameOld: string | null; + posMasterNoOld: number; + posTypeOldId: string; + posTypeNameOld: string; + posLevelOldId: string; + posLevelNameOld: string; + createdAt: Date | null; + organization: string; + reason: string; + status: string; + date: string | null; + salary: number | null; + positionTypeOld: string; + positionLevelOld: string; + positionNumberOld: string; + organizationPositionOld: string; + isActive: boolean; +} + +export type { TransferList, TransferMain }; diff --git a/src/modules/02_transfer/views/AddTransfer.vue b/src/modules/02_transfer/views/AddTransfer.vue index 131b182..55f63d8 100644 --- a/src/modules/02_transfer/views/AddTransfer.vue +++ b/src/modules/02_transfer/views/AddTransfer.vue @@ -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(null); -const { - fails, - success, - messageError, - showLoader, - hideLoader, - dialogConfirm, - dialogMessageNotify, -} = mixin; - -/** - * ตัวแปรที่ใช้งาน - */ const route = useRoute(); -const files = ref(); -const tranferOrg = ref(""); -const noteReason = ref(""); -const id = ref(""); -const nameFile = ref(""); -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(""); //id path +const files = ref(); //ไฟล์ +const tranferOrg = ref(""); //ชื่อหน่วยงานที่ขอโอนไป +const noteReason = ref(""); //เหตุผล +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([]); -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); + } +});