refactor(position-condition): fetchStructureTree

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-02-11 15:42:03 +07:00
parent b083bcb0ca
commit 55ca5d64a7
3 changed files with 13 additions and 44 deletions

View file

@ -47,8 +47,8 @@ function onSubmit() {
formData
)
.then(async () => {
await props.fetchData?.();
onCloseDialog();
await props.fetchData?.();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {

View file

@ -7,7 +7,7 @@ export default [
component: mainView,
meta: {
Auth: true,
Key: "COMMAND",
Key: "SYS_POS_CONDITION",
Role: "STAFF",
},
},

View file

@ -1,8 +1,11 @@
<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { useQuasar } from "quasar";
import { storeToRefs } from "pinia";
import { useCounterMixin } from "@/stores/mixin";
import { useRoute } from "vue-router";
import { useStructureTree } from "@/stores/structureTree";
import http from "@/plugins/http";
import config from "@/app.config";
@ -17,12 +20,15 @@ import LoadView from "@/components/LoadView.vue";
import DialogCondition from "@/modules/19_condition/components/DialogCondition.vue";
const $q = useQuasar();
const route = useRoute();
const { showLoader, hideLoader, messageError } = useCounterMixin();
const { fetchStructureTree, fetchTreeStrategy } = useStructureTree();
const { activeId } = storeToRefs(useStructureTree());
const isLoadTable = ref<boolean>(false);
//Tree
const activeId = ref<string>("");
// const activeId = ref<string>("");
const filter = ref<string>("");
const orgTreeId = ref<string>("");
const nodeTree = ref<OrgTree[]>([]);
@ -193,46 +199,9 @@ const columnsExpand = ref<QTableProps["columns"]>([
},
]);
/**
* function เรยกขอมลโครงสราง แบบป
*/
async function fetchOrgActive() {
showLoader();
http
.get(config.API.activeOrganization)
.then(async (res) => {
const data = res.data.result;
if (data) {
activeId.value = data.activeId;
await fetchDataTree(data.activeId);
}
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* function fetch อมลของ Tree
* @param id id โครงสราง
*/
async function fetchDataTree(id: string) {
showLoader();
await http
.get(config.API.orgByid(id))
.then((res) => {
const data = res.data.result;
nodeTree.value = data.data;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
/** function fetch ข้อมูลของ Tree*/
async function fetchDataTree() {
nodeTree.value = await fetchStructureTree(route.meta.Key as string, true);
}
function onSelectedOrgTree(data: OrgTree) {
@ -302,7 +271,7 @@ watch(pageSize, () => {
});
onMounted(async () => {
await fetchOrgActive();
await fetchDataTree();
});
</script>