a45aa7f7ee662aa4594bffbed16d351ba39b1718.svn-base 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <el-tree
  3. highlight-current
  4. class="el-treeWhite"
  5. :data="treeData"
  6. :props="treeProps"
  7. :expand-on-click-node="false"
  8. @node-click="nodeClick"
  9. node-key="id"
  10. :default-expanded-keys="tableDefaultExpandedKeys"
  11. lazy
  12. :load="loadAddvData"
  13. style="max-height:100%;overflow:auto;"
  14. ></el-tree>
  15. </template>
  16. <script>
  17. import { getOrgByPid } from "../api/duChaAPI.js";
  18. export default {
  19. components: {},
  20. props:['rootCode'],
  21. data() {
  22. return {
  23. treeData: [],
  24. tableDefaultExpandedKeys: [],
  25. treeProps: {
  26. label: "name",
  27. children: "children",
  28. disabled: false,
  29. expandOnClickNode: false ,
  30. first:true,
  31. }
  32. };
  33. },
  34. mounted: function() {
  35. this.loadTreeListData();
  36. },
  37. methods: {
  38. loadTreeListData:function(){
  39. if(this.rootCode&&this.rootCode!=''){
  40. getOrgByPid(this.rootCode).then((res) =>{
  41. console.log(res);
  42. let children = [];
  43. res.data.forEach((element,index)=>{
  44. children.push({
  45. 'code':element.orgId,
  46. 'name':element.orgNm
  47. })
  48. });
  49. this.treeData = children;
  50. // if(children.length && children[0].code != '11' && children[0].code != '12'){
  51. // this.$emit("provTreeSelectChange", { code:children[0].code, name: children[0].name});
  52. // }
  53. },(err) =>{});
  54. }else{
  55. getOrgByPid("").then((res) =>{
  56. console.log(res);
  57. let children = [];
  58. res.data.forEach((element,index)=>{
  59. children.push({
  60. 'code':element.orgId,
  61. 'name':element.orgNm
  62. })
  63. });
  64. this.treeData = children;
  65. },(err) =>{});
  66. }
  67. },
  68. nodeClick: function(data) {
  69. // alert(data.code+data.name+data.type);
  70. this.$emit("provTreeSelectChange", { code:data.code, name: data.name});
  71. },
  72. loadAddvData: function(node, resolve) {
  73. var _self = this;
  74. try {
  75. if(this.treeProps.first){
  76. this.treeProps.first = false;
  77. }else{
  78. getOrgByPid(node.data.code).then(
  79. response => {
  80. var data = response.data;
  81. let children = [];
  82. response.data.forEach((element,index)=>{
  83. children.push({
  84. 'code':element.orgId,
  85. 'name':element.orgNm
  86. })
  87. });
  88. resolve(children);
  89. },
  90. response => {}
  91. );
  92. }
  93. } catch (e) {
  94. }
  95. },
  96. }
  97. };
  98. </script>
  99. <style scoped>
  100. /deep/.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  101. background-color: #beceeb;
  102. }
  103. </style>