|
@@ -35,51 +35,74 @@ export default {
|
|
|
this.params.callback && this.params.callback(this.unitPa);
|
|
|
this.$emit('close');
|
|
|
},
|
|
|
- treeClick(e) {
|
|
|
+ treeClick(e, node, obj) {
|
|
|
this.unitPa.type = e.type;
|
|
|
this.unitPa.ids = JSON.parse(JSON.stringify(e.id)).split('-');
|
|
|
- let thisJson = this.$refs.tenantstree.getNode(e);
|
|
|
if (e.type == 'building') {
|
|
|
this.unitPa.buildingName = e.name;
|
|
|
this.unitPa.buildingId = e.value;
|
|
|
} else if (e.type == 'unit') {
|
|
|
- this.unitPa.buildingName = thisJson.parent.data.name;
|
|
|
- this.unitPa.buildingId = thisJson.parent.data.value;
|
|
|
+ this.unitPa.buildingName = node.parent.data.name;
|
|
|
+ this.unitPa.buildingId = node.parent.data.value;
|
|
|
this.unitPa.unitName = e.name;
|
|
|
this.unitPa.unitId = e.value;
|
|
|
} else if (e.type == 'floor') {
|
|
|
- this.unitPa.buildingName = thisJson.parent.parent.data.name;
|
|
|
- this.unitPa.buildingId = thisJson.parent.parent.data.value;
|
|
|
- this.unitPa.unitName = thisJson.parent.data.name;
|
|
|
- this.unitPa.unitId = thisJson.parent.data.value;
|
|
|
+ this.unitPa.buildingName = node.parent.parent.data.name;
|
|
|
+ this.unitPa.buildingId = node.parent.parent.data.value;
|
|
|
+ this.unitPa.unitName = node.parent.data.name;
|
|
|
+ this.unitPa.unitId = node.parent.data.value;
|
|
|
this.unitPa.floor = e.name;
|
|
|
this.unitPa.floorId = e.value;
|
|
|
} else if (e.type == 'room') {
|
|
|
- this.unitPa.buildingName = thisJson.parent.parent.parent.data.name;
|
|
|
- this.unitPa.buildingId = thisJson.parent.parent.parent.data.value;
|
|
|
- this.unitPa.unitName = thisJson.parent.parent.data.name;
|
|
|
- this.unitPa.unitId = thisJson.parent.parent.data.value;
|
|
|
- this.unitPa.floor = thisJson.parent.data.name;
|
|
|
- this.unitPa.floorId = thisJson.parent.data.value;
|
|
|
+ this.unitPa.buildingName = this.unitPa.ids.length == 4 ? node.parent.parent.data.name : node.parent.parent.parent.data.name;
|
|
|
+ this.unitPa.buildingId = this.unitPa.ids.length == 4 ? node.parent.parent.data.value : node.parent.parent.parent.data.value;
|
|
|
+ this.unitPa.unitName = this.unitPa.ids.length == 4 ? '' : node.parent.parent.data.name;
|
|
|
+ this.unitPa.unitId = this.unitPa.ids.length == 4 ? '' : node.parent.parent.data.value;
|
|
|
+ this.unitPa.floor = node.parent.data.name;
|
|
|
+ this.unitPa.floorId = node.parent.data.value;
|
|
|
this.unitPa.roomName = e.name;
|
|
|
this.unitPa.roomId = e.value;
|
|
|
}
|
|
|
},
|
|
|
- dimension(arr, type, names) {
|
|
|
+ dimension(arr) {
|
|
|
arr.map((item, index) => {
|
|
|
- if (!!item.children & (item.type !== type)) {
|
|
|
- this.dimension(item.children, type, names);
|
|
|
- } else {
|
|
|
- if (item.name.indexOf(names) === -1) {
|
|
|
- item.name = item.name + names;
|
|
|
+ if (!!item.children) {
|
|
|
+ this.dimension(item.children);
|
|
|
+ if (item.type == 'unit') {
|
|
|
+ item.name = this.CheckChinese(item.name, '单元');
|
|
|
+ } else if (item.type == 'building') {
|
|
|
+ item.name = this.CheckChinese(item.name, '楼栋');
|
|
|
+ } else if (item.type == 'floor') {
|
|
|
+ item.name = this.CheckChinese(item.name, '楼');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ },
|
|
|
+ CheckChinese(val, name) {
|
|
|
+ var reg = new RegExp('[\\u4E00-\\u9FFF]+', 'g');
|
|
|
+ let newVal = val;
|
|
|
+ if (!reg.test(val)) {
|
|
|
+ newVal = val + name;
|
|
|
+ }
|
|
|
+ return newVal;
|
|
|
+ },
|
|
|
+ filterTreeData(trData) {
|
|
|
+ trData.map((item, index) => {
|
|
|
+ if (this.isNotEmpty(item.children)) {
|
|
|
+ item.disabled = true;
|
|
|
+ this.filterTreeData(item.children);
|
|
|
+ } else {
|
|
|
+ item.disabled = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ isNotEmpty(arr) {
|
|
|
+ return arr && Array.isArray(arr) && arr.length > 0;
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
- this.dimension(this.params.tenantsTree, 'unit', '单元');
|
|
|
- this.dimension(this.params.tenantsTree, 'floor', '楼');
|
|
|
+ this.dimension(this.params.tenantsTree);
|
|
|
+ this.filterTreeData(this.params.tenantsTree);
|
|
|
this.tenantsTree = this.params.tenantsTree;
|
|
|
}
|
|
|
};
|