diff --git a/src/components/shared/TreeView.vue b/src/components/shared/TreeView.vue index 3246b791..daae9c8c 100644 --- a/src/components/shared/TreeView.vue +++ b/src/components/shared/TreeView.vue @@ -39,6 +39,7 @@ type Props = { const props = defineProps(); const nodes = defineModel('nodes', { required: true }); +const filterText = defineModel('filterText', { required: false }); const emits = defineEmits<{ (e: 'checked'): void; @@ -91,6 +92,25 @@ function toggleExpand(node: Node, ancestor?: []) { node.opened = !node.opened; emits('open', node, ancestor); } + +function filterNode(text: string, node: Node, ancestor?: Node[]) { + if (!text) return; + + const getTitle = (n: Node): string => n[props.keyTitle || 'title']; + const getSubtitle = (n: Node): string => n[props.keySubtitle || 'subtitle']; + const recursiveFilter = (n: Node): boolean => { + if (!n.children) { + return getTitle(n).includes(text) || getSubtitle(n).includes(text); + } + return n.children.some((v) => recursiveFilter(v)); + }; + + return ( + ancestor?.some( + (v) => getTitle(v).includes(text) || getSubtitle(v).includes(text), + ) || recursiveFilter(node) + ); +} diff --git a/src/pages/05_quotation/ProductServiceForm.vue b/src/pages/05_quotation/ProductServiceForm.vue index 01b19094..fdc66237 100644 --- a/src/pages/05_quotation/ProductServiceForm.vue +++ b/src/pages/05_quotation/ProductServiceForm.vue @@ -540,6 +540,7 @@ watch( movable deleteable selectable + :filter-text="inputSearch" :selected-node="selectedNode" @move-up="(node) => toggleMove(node, 'up')" @move-down="(node) => toggleMove(node, 'down')"