fengxiang
2018-07-05 1bf1750a2c2cafdbd7413fe18d16915a7f71ff52
src/app/routes/devices/basic-info/basic-info.component.ts
@@ -11,6 +11,8 @@
import { Subject } from 'rxjs/Subject';
import { CoordinatesPickerComponent } from 'app/routes/map/coordinates-picker/coordinates-picker.component';
import { CoorPickerService } from 'app/routes/map/coordinates-picker/coordinates-picker.service';
import { OrganizationService } from '@business/services/http/organization.service';
import { ExampleService } from '@business/services/util/example.service';
@Component({
  selector: 'app-basic-info',
@@ -61,13 +63,19 @@
    }
  ];
  queryTextStream: Subject<string> = new Subject<string>();
  public queryMap: {orgId?: number, mpointId?: number, devMacOrName?: string}
  = {orgId: null, mpointId: null, devMacOrName: ''};
  extraParams = { queryParams: null };
  public orgOptions = [];
  public monitorPoints = [];
  constructor(
    private monitorPointService: MonitorPointService,
    private deviceService: DeviceService,
    private confirmServ: NzModalService,
    public msgSrv: NzMessageService,
    private modalHelper: ModalHelper,
    private coorPickerService: CoorPickerService
    private coorPickerService: CoorPickerService,
    private organizationService: OrganizationService
  ) { }
  ngOnInit() {
@@ -75,14 +83,14 @@
      .debounceTime(900)
      .distinctUntilChanged()
      .subscribe(value => {
        this.extraParams.queryParams = this.deviceService.getSqlParams(value);
        this.queryMap.devMacOrName = value;
        this.load();
      });
      this.orgSelectChange();
  }
  get listUrl() {
    return this.deviceService.getListUrl();
  }
  extraParams = { queryParams: null };
  queryText: string;
  selectedRows: any[] = [];
  checkboxChange(list: any[]) {
@@ -107,6 +115,7 @@
    });
  }
  load() {
    this.extraParams.queryParams = this.deviceService.getSqlParams(this.queryMap);
    this.selectedRows = [];
    this.simpleTable.load();
  }
@@ -129,7 +138,12 @@
    if (d != null) {  
      Object.assign(data, d);
    }
    this.modalHelper.static(DeviceEditComponent, { data }).subscribe(
    const configMap = this.queryMap;
    // Object.assign(configMap, this.queryMap);
    if (!!configMap['mpointId'] && !d['monitorPoint']) {
      data['monitorPoint'] = this.getMonitorPoint(configMap['mpointId']);
    }
    this.modalHelper.static(DeviceEditComponent, { data, configMap }).subscribe(
      (ret: { data: any, close: Function }) => {
        // 修改状态
        if (ret.data['id'] != null) {
@@ -157,39 +171,96 @@
        );
      });
  }
  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;
                }
                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('坐标配置成功!');
                        }
                      }
                     );
              }
           );
         }
    );
  private getMonitorPoint(mpointId: number) {
     return this.monitorPoints.find(
        mpoint => mpoint.id === mpointId
     );
  }
  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);
                }
              }
        );
      } 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('坐标配置成功!');
                }
              }
             );
      }
   );
  }
  public setOrgId(orgId) {
    this.queryMap.orgId = orgId;
    this.queryMap.mpointId = null;
    // this.queryMap.devMacOrName = null;
    this.monitorPointChange();
    this.load();
  }
  public setMpointId(mpointId) {
    this.queryMap.mpointId = mpointId;
    this.load();
  }
  orgSelectChange(text?: string) {
    const pageBean: PageBean = {pageIndex: 0, pageSize: 20};
    this.organizationService.getPagingList(pageBean, text).subscribe(
      (res: PageBean) => {
           if (res != null && res.data != null) {
               this.orgOptions = res.data;
           }
      }
   );
  }
    monitorPointChange(text?: string) {
      const pageBean: PageBean = {pageIndex: 0, pageSize: 20};
      const example = new ExampleService();
      const organizationId = !!this.queryMap.orgId ? this.queryMap.orgId : null;
      const mpointName = !!text ? '%' + text + '%' : null;
      example.or()
      .andEqualTo({name: 'organizationId', value: organizationId })
      .andLike({name: 'name', value: mpointName  });
      this.monitorPointService.getPageByExample(pageBean, example).subscribe(
        (res: PageBean) => {
            if (res != null && res.data != null) {
                this.monitorPoints = res.data;
            }
        }
    );
    }
}