poptreeSelect.vue 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. },
  77. isNotEmpty(arr) {
  78. return arr && Array.isArray(arr) && arr.length > 0;
  79. }
  80. },
  81. created() {
  82. if (this.params.list.length !== 0) {
  83. this.params.list.forEach((item, index) => {
  84. if (this.params.num === 1) {
  85. this.defaultcheckedkeys.push(item.houseId);
  86. } else {
  87. this.defaultcheckedkeys.push(item.parkingId);
  88. }
  89. });
  90. }
  91. this.filterTreeData(this.params.tenantsTree);
  92. this.tenantsTree = this.params.tenantsTree;
  93. }
  94. };
  95. </script>