diff --git a/src/modules/02_organization/components/StructureOrgMain.vue b/src/modules/02_organization/components/StructureOrgMain.vue index d45b753b9..746a25d21 100644 --- a/src/modules/02_organization/components/StructureOrgMain.vue +++ b/src/modules/02_organization/components/StructureOrgMain.vue @@ -18,6 +18,8 @@ import { exportChartToPNG, } from "@/plugins/exportChart"; +import type { DataOption } from "@/modules/02_organization/interface/index/Main"; + const mixin = useCounterMixin(); const store = useOrganizational(); const storeOrg = useStructStore(); @@ -31,11 +33,15 @@ const dataSourceLock = ref(); // ข้อมูลตั้งต้นขอ const chartRef = ref(); // อ้างอิงไปที่ตัว chart const scrollContainer = ref(null); +const agencyId = ref(""); // id ของหน่วยงานที่เลือก +const agencyData = ref([]); // ข้อมูลรายการหน่วยงาน +const agencyOp = ref([]); // ตัวเลือกหน่วยงาน + /** fetch ข้อมูล Chart โครงสร้าง*/ -async function fetchOrgChart() { +async function fetchOrgChart(agencyId: string = "root") { if (rootOrgID.value) { showLoader(); - let urlRequest = config.API.orgChart(rootOrgID.value); + let urlRequest = config.API.orgChart(rootOrgID.value) + `/${agencyId}`; await http .get(urlRequest) .then(async (response) => { @@ -135,6 +141,50 @@ async function savePDF() { }, 500); } +/** ฟังก์ชันเลื่อน scroll ไปที่กึ่งกลาง*/ +async function scrollToCenter() { + const container = scrollContainer.value; + if (container) { + container.scrollLeft = (container.scrollWidth - container.clientWidth) / 2; + } +} + +async function fetchAgencyData(id: string) { + agencyId.value = ""; + await http + .get(config.API.orgByid(id)) + .then((res) => { + const data = res.data.result.data; + agencyData.value = data.map((item: any) => ({ + id: item.orgTreeId, + name: item.orgName, + })); + agencyOp.value = agencyData.value; + }) + .catch((err) => { + messageError($q, err); + }); +} + +function onSelectAgency(val: string) { + const id = val || "root"; // ถ้าไม่มีการเลือกหน่วยงาน ให้ใช้ root + fetchOrgChart(id); +} + +/** + * ฟังก์ชันต้นหาข้อมูลของ Option ขอสถานะ + * @param val ค่าที่ต้องการฟิลเตอร์ + * @param update อัพเดทค่า + * @param refData ดาต้าที่ต้องการฟิลเตอร์ + */ +function filterOption(val: string, update: Function) { + update(() => { + agencyOp.value = agencyData.value.filter( + (v: DataOption) => v.name.indexOf(val) > -1 + ); + }); +} + watch( [() => store.typeOrganizational, () => store.historyId], ([new1], [old1]) => { @@ -150,17 +200,10 @@ watch( : store.historyId; fetchOrgChart(); + fetchAgencyData(rootOrgID.value); } ); -/** ฟังก์ชันเลื่อน scroll ไปที่กึ่งกลาง*/ -async function scrollToCenter() { - const container = scrollContainer.value; - if (container) { - container.scrollLeft = (container.scrollWidth - container.clientWidth) / 2; - } -} - onMounted(async () => { rootOrgID.value = store.typeOrganizational === "current" @@ -171,6 +214,7 @@ onMounted(async () => { await fetchOrgChart(); await scrollToCenter(); + await fetchAgencyData(rootOrgID.value); }); onBeforeMount(() => { @@ -182,7 +226,7 @@ onBeforeMount(() => {
-
+
ดาวน์โหลด PNG @@ -195,6 +239,33 @@ onBeforeMount(() => { > ดาวน์โหลด PDF + + + + +