Refactoring code module 06_retirement

This commit is contained in:
STW_TTTY\stwtt 2024-09-18 15:18:57 +07:00
parent 1225254062
commit ea921b39b0
29 changed files with 730 additions and 823 deletions

View file

@ -1,22 +1,18 @@
<script setup lang="ts">
import { ref, onMounted, reactive } from "vue";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import DialogHeader from "@/modules/04_registry/components/DialogHeader.vue";
import { useRouter, useRoute } from "vue-router";
import type { QInput, QForm } from "quasar";
import type { treeTab } from "@/modules/05_placement/interface/index/Main";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type { QTableProps } from "quasar";
import type {
requestSendNoti,
DataCopyOrder,
FormActive,
ResponseOrganiz,
OrgTree,
TreeMain,
} from "@/modules/06_retirement/interface/response/Deceased";
import { useRouter, useRoute } from "vue-router";
import DialogOrgSelectOneStep from "@/components/Dialogs/DialogOrgSelectOneStep.vue";
@ -45,7 +41,6 @@ const props = defineProps({
default: () => console.log("not function"),
},
});
const itemTaps = ref<string[]>();
const profileId = ref<string>(route.params.id.toString());
const next = () => props.next();
@ -55,24 +50,10 @@ const filterRef = ref<QInput>();
const filter = ref<string>("");
const modalSelectOrg = ref<boolean>(false);
const nodes = ref<Array<OrgTree>>([]);
const selectedModal = ref<any[]>([]);
const rows = ref<DataCopyOrder[]>([]);
const editRows = ref<DataCopyOrder[]>([]);
/** active form */
const formActive = reactive<FormActive>({
activeId: "",
activeName: "",
draftId: "",
draftName: "",
orgPublishDate: null,
isPublic: false,
});
/** คอลัมน์Modal */
const rowsModal = ref<ResponseOrganiz[]>([]);
/** selcet OPtion */
const optionSelect = ref<any>([
{ id: 1, name: "อีเมล" },
@ -139,13 +120,8 @@ const columns = ref<QTableProps["columns"]>([
},
]);
/** Hook */
onMounted(async () => {
await getData();
});
/** เรียกข้อมูลจาก api */
const getData = async () => {
async function getData() {
showLoader();
await http
.get(config.API.detailByidDeceased(profileId.value))
@ -189,7 +165,7 @@ const getData = async () => {
.finally(async () => {
hideLoader();
});
};
}
/**
*งก Save
@ -213,22 +189,22 @@ async function saveData() {
});
}
const resetFilter = () => {
function resetFilter() {
// reset X
filter.value = "";
filterRef.value!.focus();
};
}
/**
* class ดรปแบบแสดงระหวางขอมลทแกไขหรอแสดงเฉยๆ
* @param val อม input สำหรบแกไขหรอไม
*/
const getClass = (val: boolean) => {
function getClass(val: boolean) {
return {
"full-width inputgreen cursor-pointer": val,
"full-width cursor-pointer": !val,
};
};
}
/**
* กดปมเพมดานบน table
@ -243,67 +219,12 @@ function clickAdd() {
/**
* ลบขอม
*/
const clickDelete = (id: string) => {
function clickDelete(id: string) {
dialogRemove($q, () => deleteData(id));
};
/** ดึงข้อมูล active */
async function getActive() {
showLoader();
await http
.get(config.API.activeOrganization)
.then((res) => {
const data = res.data.result;
formActive.activeId = data.activeId;
formActive.activeName = data.activeName;
formActive.draftId = data.draftId;
formActive.draftName = data.draftName;
formActive.orgPublishDate = data.orgPublishDate;
formActive.isPublic = data.isPublic;
getTreeData(data.activeId);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/** ดึงข้อมูล หน่วยงาน */
async function getTreeData(id: string) {
showLoader();
await http
.get(config.API.orgByIdSystem(id, route.meta.Key as string))
.then((res) => {
const data = res.data.result;
nodes.value = data;
filterItemsTaps(data);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
function filterItemsTaps(data: TreeMain[]) {
let orgTreeIds: string[] = [];
for (const child of data) {
orgTreeIds.push(child.orgTreeId);
if (child.children) {
orgTreeIds = orgTreeIds.concat(filterItemsTaps(child.children));
}
}
itemTaps.value = orgTreeIds;
return orgTreeIds;
}
/**ลบข้อมูล */
const deleteData = async (id: string) => {
async function deleteData(id: string) {
await http
.delete(config.API.detailByidDeceased(id))
.then((res) => {
@ -315,12 +236,12 @@ const deleteData = async (id: string) => {
.finally(async () => {
await getData();
});
};
}
/**
* Save อม
*/
const saveDataCopyOrder = async () => {
async function saveDataCopyOrder() {
if (myForm.value !== null) {
myForm.value.validate().then(async (result: boolean) => {
if (result) {
@ -333,9 +254,9 @@ const saveDataCopyOrder = async () => {
}
});
}
};
}
// Save
const fetchSaveCopyOrder = async () => {
async function fetchSaveCopyOrder() {
let list: requestSendNoti[] = [];
rows.value.map((r: DataCopyOrder) => {
list.push({
@ -359,10 +280,16 @@ const fetchSaveCopyOrder = async () => {
hideLoader();
getData();
});
};
const updateData = (row: DataCopyOrder) => {
}
function updateData(row: DataCopyOrder) {
editRows.value.push(row);
};
}
/** Hook */
onMounted(async () => {
await getData();
});
</script>
<template>