organTree.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div class="organ-tree">
  3. <el-input v-model="filterText" placeholder="请输入机构名称"><i slot="suffix" class="el-icon-search"></i></el-input>
  4. <div class="tree-style-box no-scrollbar">
  5. <el-tree
  6. class="tree-style"
  7. :data="organList"
  8. ref="tree"
  9. node-key="id"
  10. :highlight-current="true"
  11. :props="defaultProps"
  12. :expand-on-click-node="false"
  13. @node-click="treeClick"
  14. default-expand-all
  15. :filter-node-method="filterNode"
  16. >
  17. </el-tree>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'organTree',
  24. data() {
  25. return {
  26. filterText: '',
  27. organList: [],
  28. defaultProps: {
  29. children: 'children',
  30. label: 'name'
  31. }
  32. };
  33. },
  34. watch: {
  35. filterText(val) {
  36. this.$refs.tree.filter(val);
  37. }
  38. },
  39. methods: {
  40. getOrgTreeList() {
  41. this.$http.get('/assets/tree/community/find').then(({ status, data, msg }) => {
  42. if (status === 0 && data) {
  43. this.organList = data;
  44. this.$nextTick().then(() => {
  45. const firstNode = document.querySelector('.el-tree-node');
  46. firstNode.click();
  47. });
  48. }
  49. });
  50. },
  51. filterNode(value, data) {
  52. if (!value) return true;
  53. return data.orgName.indexOf(value) !== -1;
  54. },
  55. treeClick(e) {
  56. let unitPa = {};
  57. if (e.value == 0) return;
  58. if (e.type == 'unit') {
  59. let parentV = this.$refs.tree.getNode(e).parent.data;
  60. unitPa = {
  61. parentValue: parentV.value,
  62. type: e.type,
  63. value: e.value
  64. };
  65. this.$emit('organId', unitPa);
  66. } else {
  67. this.$emit('organId', e);
  68. }
  69. }
  70. },
  71. created() {
  72. this.getOrgTreeList();
  73. }
  74. };
  75. </script>
  76. <style lang="scss" scoped>
  77. .organ-tree {
  78. width: 260px;
  79. background: #ffffff;
  80. padding: 20px;
  81. box-sizing: border-box;
  82. float: left;
  83. height: 100%;
  84. overflow: auto;
  85. &::before {
  86. clear: both;
  87. }
  88. .tree-style-box {
  89. margin-top: 20px;
  90. max-height: calc(100vh - 200px);
  91. overflow: scroll;
  92. }
  93. }
  94. </style>