search_tree.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div>
  3. <a-input-search style="margin: 10px;width: 90%" placeholder="搜索" @change="onChange" />
  4. <el-tree
  5. class="filter-tree"
  6. :data="treeData"
  7. :props="defaultProps" :default-expand-all="false"
  8. :filter-node-method="filterNode" highlight-current @node-click="checkChange"
  9. ref="tree">
  10. </el-tree>
  11. </div>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. filterText: '',
  18. defaultProps: {
  19. children: 'children',
  20. label: 'label'
  21. }
  22. };
  23. },
  24. props:{
  25. treeData:Array
  26. },
  27. methods: {
  28. onChange(e){
  29. this.$refs.tree.filter(e.target.value);
  30. if(e.target.value==''){
  31. for(let i=0;i<this.$refs.tree.$children.length;i++){
  32. this.$refs.tree.$children[i].expanded = false;
  33. }
  34. }
  35. },
  36. filterNode(value, data) {
  37. if (!value) return true;
  38. return data.label.indexOf(value) !== -1;
  39. },
  40. checkChange(data) {
  41. this.$emit('getTreeId',data.id)
  42. },
  43. }
  44. };
  45. </script>
  46. <style scoped lang="less">
  47. .filter-tree{
  48. padding: 0 10px;
  49. /deep/ .el-tree-node__content{
  50. height:38px;
  51. }
  52. /deep/.el-tree-node:focus >.el-tree-node__content {
  53. background-color: #E1F2FF!important;
  54. color: #0091FF!important;
  55. }
  56. }
  57. </style>