UEquipmentTree.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="equipment-tree-container">
  3. <div>
  4. <a-button type="primary" icon="plus" style="width:13%;"/>
  5. <a-input-search style="width:85%;margin-left:2%" placeholder="请输入" @change="onChange" />
  6. </div>
  7. <div class="tree-container">
  8. <a-tree
  9. :expanded-keys="expandedKeys"
  10. auto-expand-parent
  11. :tree-data="tpmTreeData"
  12. @expand="onExpand"
  13. :replace-fields="replaceFields"
  14. @select="selectNode"
  15. >
  16. <!-- :filter-tree-node="filterTreeNode" -->
  17. </a-tree>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. import { getAction } from '@api/manage'
  23. export default({
  24. name: 'UEquipmentTree',
  25. components: {
  26. },
  27. data () {
  28. return {
  29. expandedKeys: [],
  30. searchValue: '',
  31. autoExpandParent: true,
  32. tpmListData: [], // 原始数据
  33. // tpmTreeData: [], // 树形列表使用数据
  34. tpmTreeData: [], // 树形列表使用数据
  35. replaceFields: {
  36. children: 'children',
  37. title: 'interlockName',
  38. },
  39. }
  40. },
  41. created() {
  42. this.getTpmTreeData()
  43. },
  44. methods: {
  45. getTpmTreeData(){
  46. // 现版本
  47. // getAction(`/base/interlockBase/lever12`).then(res=>{
  48. // 原版本
  49. getAction(`/base/interlockBase/list`).then(res=>{
  50. // if (res.success) {
  51. console.log('11111',res)
  52. // 防止res.result对tpmListData造成地址赋值的问题
  53. this.tpmListData = JSON.parse(JSON.stringify(res))
  54. // 现版本
  55. // this.tpmTreeData = this.tpmListData
  56. // 原版本
  57. this.tpmTreeData = this.handleTree(res, "id", "pid")
  58. console.log(this.tpmTreeData)
  59. // } else {
  60. // }
  61. })
  62. },
  63. filterTreeNode(node) {
  64. // console.log(node)
  65. // if (!inputValue) return true;
  66. return node.title.indexOf('设备') !== -1;
  67. },
  68. onExpand(expandedKeys) {
  69. this.expandedKeys = expandedKeys;
  70. this.autoExpandParent = false;
  71. },
  72. onChange(e) {
  73. const value = e.target.value;
  74. // 筛选后数据
  75. var filterData = []
  76. // 筛选符合条件的数据:包含当前搜索的项
  77. console.log('原数据',this.tpmListData)
  78. filterData = this.tpmListData.filter(item => (item.interlockName.indexOf(value) !== -1))
  79. // var data = []
  80. // filterData.forEach(item => {
  81. // var arr = this.tpmListData.filter(data => item.pid === data.id)
  82. // console.log('父级', arr)
  83. // // filterData = [...filterData, ...arr]
  84. // })
  85. // 循环寻找父级
  86. // console.log(this.findParents(this.tpmTreeData, '287813167808513'))
  87. // 原版本
  88. this.tpmTreeData = this.handleTree(filterData, "id", "pid")
  89. // 现版本
  90. // this.tpmTreeData = filterData
  91. // const expandedKeys = dataList.map(item => {
  92. // if (item.name.indexOf(value) > -1) {
  93. // // return getParentKey(item.key, gData);
  94. // return this.filterNode(item.key, gData);
  95. // }
  96. // return null;
  97. // }).filter((item, i, self) => item && self.indexOf(item) === i);
  98. // Object.assign(this, {
  99. // expandedKeys,
  100. // searchValue: value,
  101. // autoExpandParent: true,
  102. // });
  103. },
  104. // findParents(treeData,id){
  105. // let allparents = []
  106. // if(treeData.length==0){
  107. // return
  108. // }
  109. // let findele = (data,id) => {
  110. // if(!id) return
  111. // data.forEach((item,index) => {
  112. // if(item.id == id){
  113. // allparents.unshift(item.id)
  114. // findele(treeData,item.parentid)
  115. // }else{
  116. // if(!!item.children){
  117. // findele(item.children,id)
  118. // }
  119. // }
  120. // })
  121. // }
  122. // findele(treeData,id)
  123. // return allparents
  124. // },
  125. selectNode(selectedKeys, e){
  126. this.$emit('select', selectedKeys, e)
  127. },
  128. },
  129. })
  130. </script>
  131. <style lang="less" scoped>
  132. .equipment-tree-container{
  133. width: 100%;
  134. height: 100%;
  135. background-color: #fff;
  136. padding: 15px;
  137. .tree-container{
  138. width: 100%;
  139. height: calc(100% - 40px);
  140. overflow: auto;
  141. }
  142. }
  143. </style>