fengxiang
2018-06-15 565f5b26ee306966f0b4b9447b7a8f9b04a9fe00
src/app/routes/devices/basic-info/device-edit/device-edit.component.ts
@@ -31,8 +31,8 @@
    private monitorPointService: MonitorPointService,
    private versionService: VersionService,
    private operateUserService: OperateUserService,
    private deviceService:DeviceService,
    private  http:_HttpClient
    private deviceService: DeviceService,
    private  http: _HttpClient
  ) { }
  data: Device;
  //原始数据记录
@@ -40,8 +40,8 @@
  validateForm: FormGroup;
  ngOnInit() {
      debugger;
    if(!!this.data){
        Object.assign(this.originalData,this.data);
    if (!!this.data) {
        Object.assign(this.originalData, this.data);
    }    
    const data = this.data;
    this.monitorPointChange(null);
@@ -53,7 +53,7 @@
    }
    const validates: Device = {
         name: [data.name, [Validators.required]],
         mac: [data.mac, [Validators.required],[this.macAsyncValidator]],
         mac: [data.mac, [Validators.required], [this.macAsyncValidator]],
         deviceVersionId: [data.deviceVersionId],
         monitorPointId: [data.monitorPointId],
         professionId: [data.professionId],
@@ -70,20 +70,20 @@
    );
  }
  macAsyncValidator = (control: FormControl): any => {
    return Observable.create(observer =>{
    return Observable.create(observer => {
        // 编辑状态,mac未改变
        if(!!this.originalData&&this.originalData.mac === control.value){
        if (!!this.originalData && this.originalData.mac === control.value) {
            observer.next(null);
            observer.complete();
        }else {
        } else {
            const exampleService = new ExampleService();
            exampleService.or().andEqualTo({name:'mac',value:control.value});
            exampleService.or().andEqualTo({name: 'mac', value: control.value});
            this.deviceService.countByExample(exampleService).subscribe(
                res => {
                    debugger;
                     if(!!res.code&&!!res.data){
                     if (!!res.code && !!res.data) {
                         observer.next({ error: true, duplicated: true });
                     }else{
                     } else {
                        observer.next(null);
                     }
                     observer.complete();
@@ -92,7 +92,7 @@
        }
        
    });
  };
  }
  close() {
     this.subject.destroy();
   }
@@ -106,10 +106,10 @@
        ToolsService.markAsDirty(this.validateForm);
    }
   }
   professionChange(){
     this.http.get<ResultBean<any[]>>(environment.SERVER_BASH_URL+"profession/getall").subscribe(
   professionChange() {
     this.http.get<ResultBean<any[]>>(environment.SERVER_BASH_URL + 'profession/getall').subscribe(
         result => {
             if(!!result.code){
             if (!!result.code) {
                 this.professions = result.data;
             }
         }