poptreeSelect.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <el-scrollbar class="el-scrollbar-byself thisColor" style="width: 100%">
  3. <el-tree class="" :data="tenantsTree" @node-click="treeClick" node-key="value" :props="treedefaultProps" ref="tenantstree">
  4. </el-tree>
  5. </el-scrollbar>
  6. </template>
  7. <script>
  8. export default {
  9. props: ['params'],
  10. data() {
  11. return {
  12. tenantsTree: [],
  13. treedefaultProps: {
  14. children: 'children',
  15. label: 'name'
  16. },
  17. unitPa: {
  18. buildingName: '',
  19. buildingId: '',
  20. unitName: '',
  21. unitId: '',
  22. floor: '',
  23. floorId: '',
  24. roomName: '',
  25. roomId: '',
  26. type: '',
  27. ids: []
  28. }
  29. };
  30. },
  31. computed: {},
  32. mounted() {},
  33. methods: {
  34. submit() {
  35. this.params.callback && this.params.callback(this.unitPa);
  36. this.$emit('close');
  37. },
  38. treeClick(e, node, obj) {
  39. this.unitPa.type = e.type;
  40. this.unitPa.ids = JSON.parse(JSON.stringify(e.id)).split('-');
  41. if (e.type == 'building') {
  42. this.unitPa.buildingName = e.name;
  43. this.unitPa.buildingId = e.value;
  44. } else if (e.type == 'unit') {
  45. this.unitPa.buildingName = node.parent.data.name;
  46. this.unitPa.buildingId = node.parent.data.value;
  47. this.unitPa.unitName = e.name;
  48. this.unitPa.unitId = e.value;
  49. } else if (e.type == 'floor') {
  50. debugger;
  51. this.unitPa.buildingName = this.unitPa.ids.length == 4 ? node.parent.parent.data.name : node.parent.data.name;
  52. this.unitPa.buildingId = this.unitPa.ids.length == 4 ? node.parent.parent.data.value : node.parent.data.value;
  53. this.unitPa.unitName = this.unitPa.ids.length == 4 ? node.parent.data.name : '';
  54. this.unitPa.unitId = this.unitPa.ids.length == 4 ? node.parent.data.value : '';
  55. this.unitPa.floor = e.name;
  56. this.unitPa.floorId = e.value;
  57. } else if (e.type == 'room') {
  58. this.unitPa.buildingName = this.unitPa.ids.length == 4 ? node.parent.parent.data.name : node.parent.parent.parent.data.name;
  59. this.unitPa.buildingId = this.unitPa.ids.length == 4 ? node.parent.parent.data.value : node.parent.parent.parent.data.value;
  60. this.unitPa.unitName = this.unitPa.ids.length == 4 ? '' : node.parent.parent.data.name;
  61. this.unitPa.unitId = this.unitPa.ids.length == 4 ? '' : node.parent.parent.data.value;
  62. this.unitPa.floor = node.parent.data.name;
  63. this.unitPa.floorId = node.parent.data.value;
  64. this.unitPa.roomName = e.name;
  65. this.unitPa.roomId = e.value;
  66. }
  67. },
  68. dimension(arr) {
  69. arr.map((item, index) => {
  70. if (!!item.children) {
  71. this.dimension(item.children);
  72. if (item.type == 'unit') {
  73. item.name = this.CheckChinese(item.name, '单元');
  74. } else if (item.type == 'building') {
  75. item.name = this.CheckChinese(item.name, '楼栋');
  76. } else if (item.type == 'floor') {
  77. item.name = this.CheckChinese(item.name, '楼');
  78. }
  79. }
  80. });
  81. },
  82. CheckChinese(val, name) {
  83. var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
  84. let newVal = val;
  85. if (!reg.test(val)) {
  86. newVal = val + name;
  87. }
  88. return newVal;
  89. },
  90. filterTreeData(trData) {
  91. trData.map((item, index) => {
  92. if (this.isNotEmpty(item.children)) {
  93. item.disabled = true;
  94. this.filterTreeData(item.children);
  95. } else {
  96. item.disabled = false;
  97. }
  98. });
  99. },
  100. isNotEmpty(arr) {
  101. return arr && Array.isArray(arr) && arr.length > 0;
  102. }
  103. },
  104. created() {
  105. this.dimension(this.params.tenantsTree);
  106. this.filterTreeData(this.params.tenantsTree);
  107. this.tenantsTree = this.params.tenantsTree;
  108. }
  109. };
  110. </script>
  111. <style lang="scss" scoped>
  112. // .thisColor /deep/ .el-tree .is-current {
  113. // color: #56c6ff;
  114. // }
  115. </style>