From 21ec9878f8687d3da75b4fd424ffa4ee8d73d448 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Mon, 28 May 2018 11:48:34 +0800
Subject: [PATCH] 坐标完善

---
 src/app/routes/devices/basic-info/basic-info.component.ts |   79 +++++++++++++++++++++++----------------
 1 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/src/app/routes/devices/basic-info/basic-info.component.ts b/src/app/routes/devices/basic-info/basic-info.component.ts
index 01ff6f5..526253c 100644
--- a/src/app/routes/devices/basic-info/basic-info.component.ts
+++ b/src/app/routes/devices/basic-info/basic-info.component.ts
@@ -157,39 +157,54 @@
         );
       });
   }
-  configCoord(record: Device): void {  
-    Object.assign(this.coorPickerService.data, record);
-    const _data = this.coorPickerService.data;
-    this.monitorPointService.getEntity(record.monitorPointId).subscribe(
-         res => {
-            if (res != null && res.code === 1 && res.data != null) {
-                const areaNames = res.data.areaNames;
-                let adress = null;
-                if (areaNames != null) {
-                  adress = areaNames.provinceName + areaNames.cityName + areaNames.areaName + res.data.address;
+  configCoord(record: Device): void {
+     // ������������������������������������������adress������������
+     Object.assign(this.coorPickerService.data, record);
+     this.coorPickerService.data['describe'] = '������������';
+      // ������ ��������������� ������������������
+      if ((!record.latitude || !record.longitude) && !!record.monitorPointId) {
+            this.monitorPointService.getEntity(record.monitorPointId).subscribe(
+              res => {
+                if (res != null && res.code === 1 && res.data != null) {
+                    const areaNames = res.data.areaNames;
+                    let adress = '';
+                    if (areaNames != null) {
+                      adress += !!areaNames.provinceName ? areaNames.provinceName : '';
+                      adress += ' ';
+                      adress += !!areaNames.cityName ? areaNames.cityName : '';
+                      adress += ' ';
+                      adress += !!areaNames.areaName ? areaNames.areaName : '';
+                      adress += ' ';
+                      adress += !!res.data.address ? res.data.address : '';                  
+                    }
+                    this.coorPickerService.data.address = adress;
+                    this.openMap(record);              
                 }
-                this.coorPickerService.data.address = adress;
-                this.coorPickerService.data['describe'] = '������������';
-            }
-            this.modalHelper.static(CoordinatesPickerComponent).subscribe(
-              (staticComp) => {
-                     const data: Device = {
-                        id: record.id,
-                        mac: record.mac,
-                        longitude: _data.longitude,
-                        latitude: _data.latitude,
-                     };
-                     this.deviceService.save(data).subscribe(
-                      (resp: any) => {
-                        if (resp.code === 1) {
-                          this.load();
-                          this.msgSrv.success('���������������������');
-                        }
-                      }
-                     );                     
               }
-           );
-         }
-    );
+        );
+      }else {
+        this.openMap(record);
+      }
+  }
+  private openMap(record: Device) {
+    const _data = this.coorPickerService.data;    
+    this.modalHelper.static(CoordinatesPickerComponent).subscribe(
+      (staticComp) => {
+             const data: Device = {
+                id: record.id,
+                mac: record.mac,
+                longitude: _data.longitude,
+                latitude: _data.latitude,
+             };
+             this.deviceService.save(data).subscribe(
+              (resp: any) => {
+                if (resp.code === 1) {
+                  this.load();
+                  this.msgSrv.success('���������������������');
+                }
+              }
+             );                     
+      }
+   );
   }
 }

--
Gitblit v1.8.0