poptreeSelect.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <el-scrollbar class="el-scrollbar-byself" style="width: 100%">
  3. <el-tree
  4. :data="tenantsTree"
  5. show-checkbox
  6. node-key="value"
  7. :props="treedefaultProps"
  8. :default-checked-keys="defaultcheckedkeys"
  9. ref="tenantstree"
  10. @check-change="checkChange"
  11. >
  12. </el-tree>
  13. </el-scrollbar>
  14. </template>
  15. <script>
  16. export default {
  17. props: ['params'],
  18. data() {
  19. return {
  20. tenantsTree: [],
  21. treedefaultProps: {
  22. children: 'children',
  23. label: 'name'
  24. },
  25. defaultcheckedkeys: []
  26. };
  27. },
  28. computed: {},
  29. mounted() {},
  30. methods: {
  31. submit() {
  32. let arrs = this.$refs.tenantstree.getCheckedNodes();
  33. let combination = [];
  34. arrs.forEach((item, index) => {
  35. let thisValue = this.$refs.tenantstree.getNode(item);
  36. let newValueIds = thisValue.data.id.split('-');
  37. let objArray = {};
  38. if (
  39. (item.children == null || item.children == undefined) &&
  40. !this.defaultcheckedkeys.includes(parseInt(thisValue.data.value))
  41. ) {
  42. if (thisValue.data.type === 'room') {
  43. objArray = {
  44. houseId: thisValue.data.value,
  45. buildingName: newValueIds.length === 4 ? thisValue.parent.parent.data.name : thisValue.parent.data.name,
  46. unitName: newValueIds.length === 4 ? thisValue.parent.data.name : '',
  47. roomNumber: thisValue.data.name
  48. };
  49. } else if (thisValue.data.type === 'parking') {
  50. objArray = {
  51. parkingId: thisValue.data.value,
  52. parkingNumber: thisValue.data.name,
  53. partitionName: newValueIds.length === 4 ? thisValue.parent.data.name : '',
  54. garageName: newValueIds.length === 4 ? thisValue.parent.parent.data.name : thisValue.parent.data.name
  55. };
  56. }
  57. combination.push(objArray);
  58. }
  59. });
  60. this.params.callback && this.params.callback(combination);
  61. this.$emit('close');
  62. },
  63. checkChange(data,checked){
  64. if(checked){
  65. }
  66. },
  67. filterTreeData(trData) {
  68. trData.map((item, index) => {
  69. if (this.isNotEmpty(item.children)) {
  70. item.disabled = true;
  71. this.filterTreeData(item.children);
  72. } else {
  73. item.disabled = false;
  74. }
  75. });
  76. // return trData.filter((item) => {
  77. // if (this.isNotEmpty(item.children)) {
  78. // item.disabled = false;
  79. // item.children = this.filterTreeData(item.children);
  80. // console.log(item.children);
  81. // } else {
  82. // item.disabled = true;
  83. // }
  84. // });
  85. },
  86. isNotEmpty(arr) {
  87. return arr && Array.isArray(arr) && arr.length > 0;
  88. }
  89. },
  90. created() {
  91. if (this.params.list.length !== 0) {
  92. this.params.list.forEach((item, index) => {
  93. if (this.params.num === 1) {
  94. this.defaultcheckedkeys.push(item.houseId);
  95. } else {
  96. this.defaultcheckedkeys.push(item.parkingId);
  97. }
  98. });
  99. }
  100. this.filterTreeData(this.params.tenantsTree);
  101. this.tenantsTree = this.params.tenantsTree;
  102. }
  103. };
  104. </script>