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) " + > +