c3e19c719817a2b642968c8d7f829ff15aee0159.svn-base 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="tree" :style="{'height':height + 'px','width':width == 0 ? 250 : width + 'px'}">
  3. <el-tree
  4. class="el-treeWhite"
  5. :data="treeDataLists"
  6. :props="defaultProps"
  7. default-expand-all
  8. node-key="id"
  9. :filter-node-method="filterNode"
  10. :expand-on-click-node="false"
  11. @node-click = 'treeNodeClickHandler'
  12. @node-expand='treeNodeExpandHandler'
  13. ref="tree2"
  14. >
  15. </el-tree>
  16. </div>
  17. </template>
  18. <script>
  19. import request from '@util/gw_ajax_request.js';
  20. import {dateFormat} from "@util/gw_date";
  21. import {
  22. getTree
  23. } from "@api/InspectionReport.js";
  24. export default {
  25. components: {},
  26. props: ['height','width'],
  27. data() {
  28. return {
  29. treeDataLists: [],
  30. defaultProps: {
  31. children: 'children',
  32. label: 'pnm'
  33. },
  34. defaultExpanded:[],//树默认展开节点数组
  35. };
  36. },
  37. mounted: function () {
  38. if(this.width == undefined){
  39. this.width = '250';
  40. }
  41. if(this.height == undefined){
  42. this.height = '550';
  43. }
  44. this.getTreeData();
  45. },
  46. computed: {
  47. userId: function () {
  48. return localStorage.getItem("userid")
  49. ? localStorage.getItem("userid")
  50. : "1098101939614724096";
  51. }
  52. },
  53. methods: {
  54. //获取左侧树数据
  55. getTreeData:function(){
  56. let _self = this;
  57. request.post(`/tac/insp/year/batch/obj/getObjTreeListV2`,{
  58. "persId": _self.userId
  59. }).then(res =>{
  60. _self.treeDataLists = res.data.children;
  61. setTimeout(()=>{
  62. this.$refs.tree2.filter('初始化');
  63. },1000)
  64. })
  65. },
  66. //树节点点击事件
  67. treeNodeClickHandler:function(data,node,tree){
  68. if(node.level == 4){
  69. let currentNodeId = []
  70. data.children.forEach(ele=>{
  71. currentNodeId.push(ele.id)
  72. })
  73. currentNodeId = currentNodeId.join(',')
  74. let projectName = data.pnm;
  75. // let objId = data.objId;
  76. let inspGroupId = data.pid;
  77. this.$emit("provTreeSelectChange", {'id':currentNodeId,'pid':inspGroupId});
  78. }else{
  79. return;
  80. }
  81. },
  82. treeNodeExpandHandler:function(data,node,tree){
  83. let id = [];
  84. if(data != null){
  85. data.children.forEach((element) => {
  86. id.push(element.id);
  87. });
  88. }
  89. this.$emit("provTreeNodeExpand", {'id':id,'pid':data.id});
  90. },
  91. filterNode(value, data, node) {
  92. if (!value) return true;
  93. return node.level < 5;
  94. },
  95. }
  96. };
  97. </script>
  98. <style scoped>
  99. .tree{
  100. overflow-y: auto;
  101. overflow-x: auto;
  102. }
  103. .el-tree {
  104. min-width: 100%;
  105. display:inline-block !important;
  106. }
  107. </style>