organTree.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="organ-tree">
  3. <el-input v-model="filterText" placeholder="请输入关键字" suffix-icon="el-icon-search"></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('/sc-community/assets/tree/community/find').then(({ status, data, msg }) => {
  42. if (status === 0 && data) {
  43. this.dimension(data);
  44. this.organList = data;
  45. this.$nextTick().then(() => {
  46. const firstNode = document.querySelector('.el-tree-node');
  47. firstNode.click();
  48. });
  49. }
  50. });
  51. },
  52. dimension(arr) {
  53. arr.map((item, index) => {
  54. if (!!item.children & (item.type !== 'unit')) {
  55. this.dimension(item.children);
  56. } else {
  57. if (item.name.indexOf('单元') === -1) {
  58. item.name = item.name + '单元';
  59. }
  60. }
  61. });
  62. },
  63. filterNode(value, data) {
  64. if (!value) return true;
  65. return data.name.indexOf(value) !== -1;
  66. },
  67. treeClick(e) {
  68. let unitPa = {
  69. id: e.id,
  70. communityName: '',
  71. communityId: '',
  72. buildingName: '',
  73. buildingId: '',
  74. unitName: '',
  75. unitId: '',
  76. houseName: '',
  77. houseId: '',
  78. type: e.type
  79. };
  80. let thisObj = this.$refs.tree.getNode(e);
  81. if (e.type == 'building') {
  82. unitPa.communityName = thisObj.parent.data.name;
  83. unitPa.communityId = thisObj.parent.data.value;
  84. unitPa.buildingName = e.name;
  85. unitPa.buildingId = e.value;
  86. } else if (e.type == 'unit') {
  87. unitPa.communityName = thisObj.parent.parent.data.name;
  88. unitPa.communityId = thisObj.parent.parent.data.value;
  89. unitPa.buildingName = thisObj.parent.data.name;
  90. unitPa.buildingId = thisObj.parent.data.value;
  91. unitPa.unitName = e.name;
  92. unitPa.unitId = e.value;
  93. } else if (e.type == 'room') {
  94. unitPa.communityName = thisObj.parent.parent.parent.data.name;
  95. unitPa.communityId = thisObj.parent.parent.parent.data.value;
  96. unitPa.buildingName = thisObj.parent.parent.data.name;
  97. unitPa.buildingId = thisObj.parent.parent.data.value;
  98. unitPa.unitName = thisObj.parent.data.name;
  99. unitPa.unitId = thisObj.parent.data.value;
  100. unitPa.houseName = e.name;
  101. unitPa.houseId = e.value;
  102. } else {
  103. unitPa.communityName = e.name;
  104. unitPa.communityId = e.value;
  105. }
  106. this.$emit('organId', unitPa);
  107. }
  108. },
  109. created() {
  110. this.getOrgTreeList();
  111. }
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. .organ-tree {
  116. width: 260px;
  117. background: #ffffff;
  118. padding: 20px;
  119. box-sizing: border-box;
  120. float: left;
  121. height: 100%;
  122. overflow: auto;
  123. &::before {
  124. clear: both;
  125. }
  126. .tree-style-box {
  127. margin-top: 20px;
  128. max-height: calc(100vh - 200px);
  129. overflow: scroll;
  130. }
  131. }
  132. </style>