From 008baf1470f2aaf6fe388a20b9a61069270a1471 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Tue, 15 May 2018 17:19:11 +0800
Subject: [PATCH] 监控坐标编辑功能完善

---
 src/app/routes/devices/basic-info/device-edit/device-edit.component.ts |  116 +++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 82 insertions(+), 34 deletions(-)

diff --git a/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts b/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts
index 8158269..15870e2 100644
--- a/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts
+++ b/src/app/routes/devices/basic-info/device-edit/device-edit.component.ts
@@ -3,12 +3,16 @@
 import { VersionService } from '@business/services/http/version.service';
 import { MonitorPointService } from '@business/services/http/monitor-point.service';
 import { NzModalSubject } from 'ng-zorro-antd';
-import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
 import { DeviceService } from '@business/services/http/device.service';
 import { Component, OnInit } from '@angular/core';
 import { Device} from '@business/entity/data';
 import { _Validators } from '@delon/abc';
-import { PageBean } from '@business/entity/grid';
+import { PageBean, ResultBean } from '@business/entity/grid';
+import { _HttpClient } from '@delon/theme';
+import { environment } from '@env/environment';
+import { ExampleService } from '@business/services/util/example.service';
+import { Observable } from 'rxjs/Observable';
 
 @Component({
   selector: 'app-device-edit',
@@ -16,58 +20,102 @@
   styles: []
 })
 export class DeviceEditComponent implements OnInit {
-  public monitorPoints:any [] = [];
-  public deviceVersions:any [] = [];
-  public operateUsers:any [] = [];
+  public monitorPoints: any [] = [];
+  public professions: any [] = [];
+  public deviceVersions: any [] = [];
+  public operateUsers: any [] = [];
   public isSaving = false;
   constructor(
     private subject: NzModalSubject,
     private formBuilder: FormBuilder,
-    private monitorPointService:MonitorPointService,
-    private versionService:VersionService,
-    private operateUserService:OperateUserService
+    private monitorPointService: MonitorPointService,
+    private versionService: VersionService,
+    private operateUserService: OperateUserService,
+    private deviceService:DeviceService,
+    private  http:_HttpClient
   ) { }
-  data:Device;
-  validateForm:FormGroup;
+  data: Device;
+  //������������������
+  originalData: Device = {};
+  validateForm: FormGroup;
   ngOnInit() {
+      debugger;
+    if(!!this.data){
+        Object.assign(this.originalData,this.data);
+    }    
     const data = this.data;
     this.monitorPointChange(null);
     this.deviceVersionChange(null);
     this.operateUserChange(null);
+    this.professionChange();
     if (this.data.createTime == null) {
         this.data.createTime = new Date().getTime();
     }
-    const validates:Device = {
-         name:[data.name,[Validators.required]],
-         mac:[data.mac,[Validators.required]],
-         deviceVersionId:[data.deviceVersionId],
-         monitorPointId:[data.monitorPointId],
-         operateUserId:[data.operateUserId],
-         address:[data.address],
-         id:[data.id],
-         longitude:[data.longitude],
-         latitude:[data.latitude],
-         createTime:[data.createTime],
-         installTime:[data.installTime]
+    const validates: Device = {
+         name: [data.name, [Validators.required]],
+         mac: [data.mac, [Validators.required],[this.macAsyncValidator]],
+         deviceVersionId: [data.deviceVersionId],
+         monitorPointId: [data.monitorPointId],
+         professionId: [data.professionId],
+         operateUserId: [data.operateUserId],
+         address: [data.address],
+         id: [data.id],
+         longitude: [data.longitude],
+         latitude: [data.latitude],
+         createTime: [data.createTime],
+         installTime: [data.installTime]
     };
     this.validateForm = this.formBuilder.group(
       validates
     );
   }
-  close(){
+  macAsyncValidator = (control: FormControl): any => {
+    return Observable.create(observer =>{
+        // ���������������mac���������
+        if(!!this.originalData&&this.originalData.mac === control.value){
+            observer.next(null);
+            observer.complete();
+        }else {
+            const exampleService = new ExampleService();
+            exampleService.or().andEqualTo({name:'mac',value:control.value});
+            this.deviceService.countByExample(exampleService).subscribe(
+                res => {
+                    debugger;
+                     if(!!res.code&&!!res.data){
+                         observer.next({ error: true, duplicated: true });
+                     }else{
+                        observer.next(null);
+                     }
+                     observer.complete();
+                }
+            );
+        }
+        
+    });
+  };
+  close() {
      this.subject.destroy();
    }
-   save($event, value, valid){
+   save($event, value, valid) {
     $event.preventDefault();
-    if(valid){
+    if (valid) {
       this.isSaving = true;
       this.data = value;
       this.subject.next( this );
-    }else{
+    } else {
         ToolsService.markAsDirty(this.validateForm);
     }
    }
-   monitorPointChange(text){
+   professionChange(){
+     this.http.get<ResultBean<any[]>>(environment.SERVER_BASH_URL+"profession/getall").subscribe(
+         result => {
+             if(!!result.code){
+                 this.professions = result.data;
+             }
+         }
+     );
+   }
+   monitorPointChange(text) {
     const pageBean: PageBean = {pageIndex: 0, pageSize: 20};
     this.monitorPointService.getPagingList(pageBean, text).subscribe(
       (res: PageBean) => {
@@ -81,14 +129,14 @@
                       return item.id === monitorPoint.id;
                    }
                );
-               if ( hasSelectedValue ) {
+               if ( !hasSelectedValue ) {
                   this.monitorPoints.push(monitorPoint);
                }
            }
       }
    );
    }
-   deviceVersionChange(text){
+   deviceVersionChange(text) {
     const pageBean: PageBean = {pageIndex: 0, pageSize: 20};
     this.versionService.getPagingList(pageBean, text).subscribe(
       (res: PageBean) => {
@@ -102,14 +150,14 @@
                       return item.id === deviceVersion.id;
                    }
                );
-               if ( hasSelectedValue ) {
-                  this.monitorPoints.push(deviceVersion);
+               if ( !hasSelectedValue ) {
+                  this.deviceVersions.push(deviceVersion);
                }
            }
       }
    );
    }
-   operateUserChange(text){
+   operateUserChange(text) {
     const pageBean: PageBean = {pageIndex: 0, pageSize: 20};
     this.operateUserService.getPagingList(pageBean, text).subscribe(
       (res: PageBean) => {
@@ -123,8 +171,8 @@
                       return item.id === operateUser.id;
                    }
                );
-               if ( hasSelectedValue ) {
-                  this.monitorPoints.push(operateUser);
+               if ( !hasSelectedValue ) {
+                  this.operateUsers.push(operateUser);
                }
            }
       }

--
Gitblit v1.8.0