poptreeSelect.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. >
  11. </el-tree>
  12. </el-scrollbar>
  13. </template>
  14. <script>
  15. export default {
  16. props: ['params'],
  17. data() {
  18. return {
  19. tenantsTree: [],
  20. treedefaultProps: {
  21. children: 'children',
  22. label: 'name'
  23. },
  24. defaultcheckedkeys: []
  25. };
  26. },
  27. computed: {},
  28. mounted() {},
  29. methods: {
  30. submit() {
  31. let arrs = this.$refs.tenantstree.getCheckedNodes();
  32. let combination = [];
  33. arrs.forEach((item, index) => {
  34. let thisValue = this.$refs.tenantstree.getNode(item);
  35. let objArray = {};
  36. if (
  37. (item.children == null || item.children == undefined) &&
  38. !this.defaultcheckedkeys.includes(parseInt(thisValue.data.value))
  39. ) {
  40. if (thisValue.data.type === 'room') {
  41. objArray = {
  42. houseId: thisValue.data.value,
  43. buildingName: thisValue.parent.parent.data.name,
  44. unitName: thisValue.parent.data.name,
  45. roomNumber: thisValue.data.name
  46. };
  47. } else if (thisValue.data.type === 'parking') {
  48. objArray = {
  49. parkingId: thisValue.data.value,
  50. parkingNumber: thisValue.data.name
  51. };
  52. }
  53. combination.push(objArray);
  54. }
  55. });
  56. this.params.callback && this.params.callback(combination);
  57. this.$emit('close');
  58. }
  59. },
  60. created() {
  61. if (this.params.list.length !== 0) {
  62. this.params.list.forEach((item, index) => {
  63. if (this.params.num === 1) {
  64. this.defaultcheckedkeys.push(item.houseId);
  65. } else {
  66. this.defaultcheckedkeys.push(item.parkingId);
  67. }
  68. });
  69. }
  70. this.tenantsTree = this.params.tenantsTree;
  71. }
  72. };
  73. </script>