fix step3

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-13 16:32:38 +07:00
parent 12b3f3569d
commit 5664b31fe4
2 changed files with 20 additions and 156 deletions

View file

@ -2,12 +2,13 @@
import DialogHeader from "@/components/DialogHeader.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
import { ref, watch, reactive } from "vue";
import { ref, watch, reactive, onMounted, onBeforeMount } from "vue";
import type { QInput, QTableProps } from "quasar";
import { useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useStructureTree } from "@/stores/structureTree";
import type {
OrgTree,
@ -18,6 +19,8 @@ import type {
TreeMain,
} from "@/interface/request/orgSelect/org";
const { fetchStructureTree } = useStructureTree();
const rows = ref<any[]>([]);
const filterRef = ref<QInput>();
const filterModal = ref<string>("");
@ -120,28 +123,23 @@ function close() {
filter.value = "";
isAll.value = false;
isBlank.value = false;
nodes.value = [];
expanded.value = [];
nodeLevel.value = 0;
nodeId.value = "";
rows.value = [];
selectedModal.value = [];
}
async function getDataTable(id: string, level: number = 0) {
//new
showLoader();
http
await http
.post(config.API.orgDeceasedProfile, {
nodeId: id,
node: level,
isAll: isAll.value,
})
.then((res) => {
const data = res.data.result.data;
.then(async (res) => {
const data = await res.data.result.data;
rows.value = data;
})
.catch((e) => {
@ -150,66 +148,6 @@ async function getDataTable(id: string, level: number = 0) {
.finally(() => {
hideLoader();
});
//old
// showLoader();
// const body = {
// node: level,
// nodeId: id,
// typeCommand: type.value,
// position: posType.value ? posType.value : "",
// posLevel: posLevel.value ? posLevel.value : "",
// posType: position.value ? position.value : "",
// isAll: isAll.value,
// isBlank: isBlank.value,
// };
// await http
// .post(config.API.orgPosPlacement, body)
// .then((res) => {
// const dataMain: PositionMain[] = [];
// posMasterMain.value = res.data.result.data;
// res.data.result.data.forEach((e: PositionNo) => {
// const p = e.positions;
// if (p.length !== 0) {
// const a = p.find((el: Positions) => el.positionIsSelected === true);
// const { id, ...rest } = a ? a : p[0];
// const data: any = { ...e, ...rest };
// dataMain.push(data);
// }
// });
// const listPosNo: DataPositionNo[] = dataMain.map((e: PositionMain) => ({
// id: e.id,
// isPosition: e.isPosition,
// posMasterNo:
// e.orgShortname +
// (e.posMasterNoPrefix != null ? e.posMasterNoPrefix : "") +
// e.posMasterNo +
// (e.posMasterNoSuffix != null ? e.posMasterNoSuffix : ""),
// positionName: e.positionName,
// posTypeName: e.posTypeName,
// posLevelName: e.posLevelName,
// positionIsSelected: e.positionIsSelected
// ? e.fullNameCurrentHolder
// : "-",
// isSit: e.isSit,
// positions: e.positions,
// node: e.node,
// nodeId: e.nodeId,
// }));
// positionNo.value = listPosNo;
// positionData.value = listPosNo;
// })
// .catch((err) => {
// messageError($q, err);
// })
// .finally(() => {
// setTimeout(() => {
// hideLoader();
// }, 1000);
// });
}
/**
@ -221,62 +159,18 @@ function updateSelected(data: DataTree) {
seletcId.value = "";
selectedPos.value = [];
datePos.value = new Date();
selectedModal.value = []
selectedModal.value = [];
nodeId.value = data.orgTreeId ? data.orgTreeId : "";
nodeLevel.value = data.orgLevel;
getDataTable(data.orgTreeId, data.orgLevel);
}
const isLoad = ref<boolean>(false);
/** ดึงข้อมูล active */
async function getActive() {
showLoader();
await http
.get(config.API.activeOrganization)
.then(async (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;
await getTreeData(data.activeId);
})
.catch((err) => {
messageError($q, err);
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;
async function getTreeData() {
nodes.value = await fetchStructureTree(route.meta.Key as string);
isLoad.value = true;
}
/**
@ -302,40 +196,11 @@ async function onClickSelectPos(id: string) {
}
}
/**
* function fetch อม expanded tree
* @param level levelTree
* @param id treeId
*/
async function fetchPosFind(level: number, id: string) {
showLoader();
const body = {
node: level,
nodeId: id,
};
await http
.post(config.API.orgPosFind, body)
.then((res) => {
const data = res.data.result;
expanded.value = data;
nodeId.value = id;
positionId.value = props?.dataRows?.posmasterId;
seletcId.value = props?.dataRows?.positionId;
datePos.value = props?.dataRows?.reportingDateFullDate;
getDataTable(nodeId.value, level);
})
.catch((e) => {
messageError($q, e);
hideLoader();
});
}
watch(
() => modal.value,
async (n) => {
if (n == true) {
getActive();
!isLoad.value && showLoader();
}
}
);
@ -367,7 +232,7 @@ watch(
}
);
function onSubmit() {
if (selectedModal.value?.length == 0) {
if (selectedModal.value?.length == 0) {
dialogMessageNotify($q, "กรุณาเลือกตำแหน่ง");
} else {
dialogConfirm($q, async () => {
@ -377,10 +242,9 @@ function onSubmit() {
}
}
function resetFilter() {
filter.value = "";
filterRef.value!.focus();
}
onMounted(async () => {
await getTreeData();
});
</script>
<template>
<q-dialog v-model="modal" persistent full-width>
@ -472,7 +336,7 @@ function resetFilter() {
v-if="filterModal !== ''"
name="clear"
class="cursor-pointer"
@click="resetFilter"
@click="filterModal = ''"
/>
</template>
</q-input>