native.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div>
  3. <!-- class="filter-tree"
  4. :props="defaultProps"
  5. show-checkbox
  6. -->
  7. <!-- <el-tree
  8. class="filter-tree"
  9. :data="dataRes"
  10. @check="checkChange"
  11. node-key="value"
  12. :props="defaultProps"
  13. accordion
  14. check-strictly
  15. show-checkbox
  16. highlight-current
  17. :default-expanded-keys="defaultArr"
  18. :default-checked-keys="defaultArr"
  19. :filter-node-method="filterNode"
  20. ref="tree"
  21. >
  22. </el-tree> -->
  23. <el-scrollbar
  24. class="el-scrollbar-byself"
  25. style="width: 100%"
  26. >
  27. <el-tree
  28. :data="tenantsTree"
  29. show-checkbox
  30. node-key="value"
  31. :props="treedefaultProps"
  32. :default-checked-keys="defaultcheckedkeys"
  33. ref="tenantstree"
  34. @check-change="checkChange"
  35. >
  36. <div
  37. style="width: 100%"
  38. slot-scope="{ node, data }"
  39. @click="thisCheck($event, node, data)"
  40. >{{ data.name }}</div>
  41. </el-tree>
  42. </el-scrollbar>
  43. </div>
  44. </template>
  45. <script>
  46. export default {
  47. props: ['params'],
  48. data () {
  49. return {
  50. // defaultProps: {
  51. // children: 'children',
  52. // label: 'name'
  53. // },//过滤使用字段
  54. // dataRes: [],
  55. checkedData: {},//当前点击的数据
  56. Information: '',
  57. id: '',
  58. positionInformation: [],
  59. value: '',
  60. tenantsTree: [],
  61. treedefaultProps: {
  62. children: 'children',
  63. label: 'name'
  64. },
  65. defaultcheckedkeys: []
  66. }
  67. },
  68. methods: {
  69. /** 控制树形单选 */
  70. checkChange (data, checked) {
  71. this.checkedData = {}
  72. if (checked) {
  73. if (!!data.children && data.children.length > 0) {
  74. console.log("有子节点不可选")
  75. } else {
  76. this.checkedData = data;
  77. // 注意!!!
  78. //1、下方的id和属性中 node-key="id"必须是同一个字段
  79. //2、$refs.tree 也需要和上方的属性匹配 ref="tree"
  80. this.$refs.tenantstree.setCheckedKeys([data.value]);
  81. this.value = data.value;
  82. this.Information = data.name;
  83. }
  84. }
  85. this.value = this.checkedData.value;
  86. console.log("checked data", data, this.checkedData)
  87. this.Information = this.checkedData.name
  88. },
  89. submit () {
  90. if (this.Information != undefined) {
  91. this.positionInformation.push({ positionInformation: this.Information, id: this.id, value: this.value });
  92. this.params.callback(this.positionInformation);
  93. this.$emit('close');
  94. }
  95. },
  96. filterTreeData (trData) {
  97. console.log(trData)
  98. trData.map((item, index) => {
  99. if (this.isNotEmpty(item.children)) {
  100. item.disabled = true;
  101. this.filterTreeData(item.children);
  102. } else {
  103. item.disabled = false;
  104. }
  105. });
  106. },
  107. isNotEmpty (arr) {
  108. return arr && Array.isArray(arr) && arr.length > 0;
  109. },
  110. thisCheck (ev, node, data) {
  111. if (!data.disabled) {
  112. node.checked = node.checked;
  113. }
  114. },
  115. garage () {
  116. this.$http.get('/sc-community-web/assets/tree/garage/find').then(({ data, status, msg }) => {
  117. this.dataRes = data;
  118. this.filterTreeData(this.dataRes);
  119. this.tenantsTree = this.dataRes;
  120. })
  121. }
  122. },
  123. created () {
  124. // 数图
  125. this.garage();
  126. this.id = this.params.id;
  127. console.log(this.id);
  128. this.Information = this.params.positionInformation;
  129. debugger;
  130. this.value = this.params.value;
  131. // 显示
  132. this.defaultcheckedkeys = [this.params.value]
  133. }
  134. }
  135. </script>