From d4b436fb9d7c9a3b7534459b9b455c9e4b51e732 Mon Sep 17 00:00:00 2001 From: "STW_TTTY\\stwtt" Date: Tue, 23 Apr 2024 17:42:34 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B9=80=E0=B8=95?= =?UTF-8?q?=E0=B8=AD=E0=B8=A3=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/competency/03ListLinkGroup.vue | 122 +++++++++++++----- 1 file changed, 88 insertions(+), 34 deletions(-) diff --git a/src/modules/14_KPI/components/competency/03ListLinkGroup.vue b/src/modules/14_KPI/components/competency/03ListLinkGroup.vue index 35a681e92..53ae2353d 100644 --- a/src/modules/14_KPI/components/competency/03ListLinkGroup.vue +++ b/src/modules/14_KPI/components/competency/03ListLinkGroup.vue @@ -23,28 +23,12 @@ const groupName = ref(); const position = ref(null); const competency = ref(null); -const groupNameOp = ref([ - { - id: "ID1", - name: "กลุ่ม 1", - }, - { - id: "ID2", - name: "กลุ่ม 2", - }, -]); +const groupNameOp = ref([]); +const groupNameOpMain = ref([]); const positionOp = ref([]); const positionMainOp = ref([]); -const competencyOp = ref([ - { - id: "ID1", - name: "สมรรถนะ 1", - }, - { - id: "ID2", - name: "สมรรถนะ 2", - }, -]); +const competencyOp = ref([]); +const competencyOpMain = ref([]); const columns = ref([ { @@ -143,13 +127,24 @@ async function deleteData(id: string) { async function getListGroup() { showLoader(); await http - .get(config.API.kpiGroup) + .get(config.API.kpiGroup+`?pageSize=50`) .then(async (res) => { - const data = res.data.result.data; - groupNameOp.value = data.map((item: ListGroup) => ({ - id: item.id, - name: item.nameGroupKPI, - })); + const dataOp = res.data.result.data; + const uniqueNames = new Set(); + const filteredData = dataOp + .filter((item: any) => { + if (!uniqueNames.has(item.id)) { + uniqueNames.add(item.nameGroupKPI); + return true; + } + return false; + }) + .map((item: any) => ({ + id: item.id, + name: item.nameGroupKPI, + })); + + groupNameOpMain.value = filteredData; }) .catch((err) => { messageError($q, err); @@ -163,13 +158,24 @@ async function getListGroup() { async function getCompetency() { showLoader(); await http - .get(config.API.kpiCapacity + `?type=GROUP`) + .get(config.API.kpiCapacity + `?type=GROUP&pageSize=50`) .then(async (res) => { - const data = res.data.result.data; - competencyOp.value = data.map((item: any) => ({ - id: item.id, - name: item.name, - })); + const dataOp = res.data.result.data; + const uniqueNames = new Set(); + const filteredData = dataOp + .filter((item: any) => { + if (!uniqueNames.has(item.id)) { + uniqueNames.add(item.name); + return true; + } + return false; + }) + .map((item: any) => ({ + id: item.id, + name: item.name, + })); + + competencyOpMain.value = filteredData; }) .catch((err) => { messageError($q, err); @@ -264,6 +270,20 @@ function getOptions() { }); } +/** + * function ต้นหาข้อมูลของ Option + * @param val ค่าที่ต้องการฟิลเตอร์ + * @param update อัพเดทค่า + * @param refData ดาต้าที่ต้องการฟิลเตอร์ + */ +function filterOptionGroup(val: any, update: Function) { + update(() => { + groupNameOp.value = groupNameOpMain.value.filter( + (v: any) => v.name.indexOf(val) > -1 + ); + }); +} + /** * function ต้นหาข้อมูลของ Option * @param val ค่าที่ต้องการฟิลเตอร์ @@ -278,6 +298,20 @@ function filterOption(val: any, update: Function) { }); } +/** + * function ต้นหาข้อมูลของ Option + * @param val ค่าที่ต้องการฟิลเตอร์ + * @param update อัพเดทค่า + * @param refData ดาต้าที่ต้องการฟิลเตอร์ + */ +function filterOptionCompetency(val: any, update: Function) { + update(() => { + competencyOp.value = competencyOpMain.value.filter( + (v: any) => v.name.indexOf(val) > -1 + ); + }); +} + /** * function updatePagination * @param newPagination ข้อมูล Pagination ใหม่ @@ -459,7 +493,17 @@ onMounted(async () => { option-label="name" option-value="id" :options="groupNameOp" - /> + use-input + @filter="(inputValue:any,doneFn:Function) => filterOptionGroup(inputValue, doneFn) " + > +
{ option-label="name" option-value="id" :options="competencyOp" - /> + use-input + @filter="(inputValue:any,doneFn:Function) => filterOptionCompetency(inputValue, doneFn) " + > +