Browse Source

能源电水表

Shannon_mu 3 years ago
parent
commit
2d41ceef9c

+ 4 - 52
energyManagement/src/views/instrumentManagement/popups/addDeviceManagement.vue

@@ -146,72 +146,24 @@ export default {
                     title: '楼栋信息'
                 });
             }).then((e) => {
-                debugger;
                 let address = '';
+                this.formData.buildingId = e.buildingId;
+                this.formData.unitName = e.unitId;
+                this.formData.floorName = e.floorId;
+                this.formData.houseId = e.roomId;
                 if (!!e.roomId) {
                     this.formData.addressType = 5;
-                    this.formData.buildingId = e.buildingId;
-                    this.formData.unitName = e.unitId;
-                    this.formData.floorName = e.floorId;
-                    this.formData.houseId = e.roomId;
                     address = e.buildingName + '-' + e.unitName + '-' + e.floor + '-' + e.roomName;
                 } else if (!!e.floorId) {
                     this.formData.addressType = 4;
-                    this.formData.buildingId = e.buildingId;
-                    this.formData.unitName = e.unitId;
-                    this.formData.floorName = e.floorId;
-                    this.formData.houseId = '';
                     address = e.buildingName + '-' + e.unitName + '-' + e.floor;
                 } else if (!!e.unitId) {
                     this.formData.addressType = 3;
-                    this.formData.buildingId = e.buildingId;
-                    this.formData.unitName = e.unitId;
-                    this.formData.floorName = '';
-                    this.formData.houseId = '';
                     address = e.buildingName + '-' + e.unitName;
                 } else if (!!e.buildingId) {
                     this.formData.addressType = 2;
-                    this.formData.buildingId = e.buildingId;
-
-                    this.formData.unitName = '';
-                    this.formData.floorName = '';
-                    this.formData.houseId = '';
                     address = e.buildingName;
                 }
-                // console.log(e);
-                // debugger;
-                // if (e.ids.length) {
-                //     let lengthSum = e.ids.length;
-                //     switch (lengthSum) {
-                //         case 1:
-                //             this.formData.addressType = 1;
-                //             break;
-                //         case 2:
-                //             this.formData.addressType = 2;
-                //             this.formData.buildingId = e.ids[1];
-                //             break;
-                //         case 3:
-                //             this.formData.addressType = 3;
-                //             this.formData.buildingId = e.ids[1];
-                //             this.formData.unitName = e.ids[2];
-                //             break;
-                //         case 4:
-                //             this.formData.addressType = 4;
-                //             this.formData.buildingId = e.ids[1];
-                //             this.formData.unitName = e.ids[2];
-                //             this.formData.floorName = e.ids[3];
-                //             break;
-                //         case 5:
-                //             this.formData.addressType = 5;
-                //             this.formData.buildingId = e.ids[1];
-                //             this.formData.unitName = e.ids[2];
-                //             this.formData.floorName = e.ids[3];
-                //             this.formData.houseId = e.ids[4];
-                //             break;
-                //         default:
-                //             break;
-                //     }
-                // }
                 this.formData.address = address;
             });
         },

+ 45 - 22
energyManagement/src/views/instrumentManagement/popups/poptreeSelect.vue

@@ -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;
     }
 };