fengxiang
2018-05-28 21ec9878f8687d3da75b4fd424ffa4ee8d73d448
src/app/routes/devices/basic-info/basic-info.component.ts
@@ -23,7 +23,7 @@
    { title: '名称', index: 'name' },
    { title: 'mac', index: 'mac' },
    { title: '型号', index: 'deviceVersion.name' },
    { title: '监控点', index: 'monitorPoint.name' },
    { title: '监控站点', index: 'monitorPoint.name' },
    { title: '维护人', index: 'operateUser.name' },
    { title: '生产时间', width: '100px', type: 'date', index: 'createTime' },
    { title: '安装时间', width: '100px', type: 'date', index: 'installTime' },
@@ -126,7 +126,7 @@
  }
  addOrModify(d) {
    const data = {};
    if (d != null) {
    if (d != null) {
      Object.assign(data, d);
    }
    this.modalHelper.static(DeviceEditComponent, { data }).subscribe(
@@ -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,
                        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('坐标配置成功!');
                }
              }
             );
      }
   );
  }
}