520ec60e5dc62d447ed1c5523e1fb6ece718f68e.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-tree
  3. class="el-treeWhite"
  4. ref="elTreeWhite"
  5. :data="treeData"
  6. :props="treeProps"
  7. :expand-on-click-node="false"
  8. :check-strictly="checkStrictly"
  9. @check-change="handleCheckChange"
  10. node-key="code"
  11. :default-expanded-keys="tableDefaultExpandedKeys"
  12. lazy
  13. show-checkbox
  14. :load="loadAddvData"
  15. style="max-height:100%;overflow:auto;"
  16. ></el-tree>
  17. </template>
  18. <script>
  19. import { getOrgByPid } from "../api/duChaAPI.js";
  20. export default {
  21. components: {},
  22. props:{
  23. rootCode:{},
  24. orgIdLists:{},
  25. checkStrictly:{ //在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 false
  26. type: Boolean,
  27. default: false
  28. }
  29. },
  30. data() {
  31. return {
  32. treeData: [],
  33. tableDefaultExpandedKeys: [],
  34. treeProps: {
  35. label: "name",
  36. children: "children",
  37. disabled: false,
  38. expandOnClickNode: false ,
  39. first:true,
  40. }
  41. };
  42. },
  43. mounted: function() {
  44. this.loadTreeListData();
  45. },
  46. methods: {
  47. loadTreeListData:function(){
  48. let _this = this
  49. if(this.rootCode&&this.rootCode!=''){
  50. getOrgByPid(this.rootCode).then((res) =>{
  51. console.log(res);
  52. let children = [];
  53. res.data.forEach((element,index)=>{
  54. children.push({
  55. 'code':element.orgId,
  56. 'name':element.orgNm
  57. })
  58. });
  59. this.treeData = children;
  60. if(this.orgIdLists){
  61. this.$refs.elTreeWhite.setCheckedKeys(this.orgIdLists)
  62. setTimeout(()=>{
  63. let checkedNodes = _this.$refs.elTreeWhite.getCheckedNodes()
  64. // _this.$emit("provTreeSelectChange", checkedNodes); //第一次给树赋值不emit事件,父组件取当前拥有机构数据
  65. },0)
  66. }
  67. },(err) =>{});
  68. }else{
  69. getOrgByPid('1').then((res) =>{
  70. console.log(res);
  71. let children = [];
  72. res.data.forEach((element,index)=>{
  73. children.push({
  74. 'code':element.orgId,
  75. 'name':element.orgNm
  76. })
  77. });
  78. this.treeData = children;
  79. },(err) =>{});
  80. }
  81. },
  82. handleCheckChange(data) {
  83. // alert(data.code+data.name+data.type);
  84. let checkedNodes = this.$refs.elTreeWhite.getCheckedNodes()
  85. this.$emit("provTreeSelectChange", checkedNodes);
  86. },
  87. loadAddvData: function(node, resolve) {
  88. var _self = this;
  89. try {
  90. if(this.treeProps.first){
  91. this.treeProps.first = false;
  92. }else{
  93. getOrgByPid(node.data.code).then(
  94. response => {
  95. var data = response.data;
  96. let children = [];
  97. response.data.forEach((element,index)=>{
  98. children.push({
  99. 'code':element.orgId,
  100. 'name':element.orgNm
  101. })
  102. });
  103. resolve(children);
  104. },
  105. response => {}
  106. );
  107. }
  108. } catch (e) {
  109. }
  110. },
  111. }
  112. };
  113. </script>
  114. <style scoped>
  115. </style>