From 904bca110bbd3cd7775c7dcbfabf0447f03e4c91 Mon Sep 17 00:00:00 2001
From: xufenglei <xufenglei>
Date: Mon, 08 Jan 2018 11:55:21 +0800
Subject: [PATCH] 账户 管理

---
 src/app/routes/systems/account/account-edit/account-edit.component.ts |   66 +++++++++++++++++++++++++++++---
 1 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/src/app/routes/systems/account/account-edit/account-edit.component.ts b/src/app/routes/systems/account/account-edit/account-edit.component.ts
index 52ec4e7..4101709 100644
--- a/src/app/routes/systems/account/account-edit/account-edit.component.ts
+++ b/src/app/routes/systems/account/account-edit/account-edit.component.ts
@@ -4,6 +4,9 @@
 import {HttpClient} from '@angular/common/http';
 import {environment} from '../../../../../environments/environment';
 import {DateService} from '../../../../core/services/date.service';
+import {FormGroup, FormBuilder, Validators, FormControl} from '@angular/forms';
+import {Jsonp} from '@angular/http';
+import {Observable} from 'rxjs';
 
 @Component({
   selector: 'app-account-edit',
@@ -13,25 +16,74 @@
 export class AccountEditComponent implements OnInit {
 
   account: any;
+  validateForm: FormGroup;
+  searchOptions = [];
 
   constructor(private modalHelper: ModalHelper,
     private subject: NzModalSubject,
     public dateSrv: DateService,
     public msgSrv: NzMessageService,
-    public http: HttpClient) {}
+    public http: HttpClient,
+    private formBuilder: FormBuilder
+  ) {
+
+  }
 
   ngOnInit() {
-  }
-  
-  save() {
-    this.http.post(environment.SERVER_BASH_URL + '/account/account', this.account).subscribe(() => {
-      this.subject.next('true');
-      this.close();
+    this.validateForm = this.formBuilder.group({
+      accountName: [this.account.accountName],
+      mobile: [this.account.mobile],
+      email: [this.account.email],
+      weixin: [this.account.weixin],
+      organizationId: [this.account.organizationId],
+      expireTime: [this.account.expireTime],
+      id: [this.account.id]
     });
+    this.searchOptions = this.account.organization ? [this.account.organization] : [];
+  }
+
+  save() {
+    if (this.validateForm.valid) {
+      for (const i in this.validateForm.controls) {
+        this.validateForm.controls[i].disable();
+      }
+      this.http.post(environment.SERVER_BASH_URL + '/account/account', this.validateForm.value).subscribe(() => {
+        this.subject.next('true');
+        this.close();
+      });
+    } else {
+      for (const i in this.validateForm.controls) {
+        this.validateForm.controls[i].markAsDirty();
+      }
+    }
   }
 
   close() {
     this.subject.destroy();
   }
 
+  check(accountName) {
+    if (accountName) {
+      this.http.get(environment.SERVER_BASH_URL + '/account/' + accountName).subscribe((res: any) => {
+        if (res.data > 0) {
+          this.validateForm.controls.accountName.setErrors({unique: true});
+        } else {
+          this.validateForm.controls.accountName.reset;
+        }
+      });
+    } else {
+      this.validateForm.controls.accountName.setErrors({required: true});
+    }
+  }
+
+  searchChange(searchText) {
+    if (searchText) {
+      const query = encodeURI(searchText);
+      if (query) {
+        this.http.get(environment.SERVER_BASH_URL + '/organization/list/' + query).subscribe((res: any) => {
+          this.searchOptions = res.data;
+        });
+      }
+    }
+  }
 }

--
Gitblit v1.8.0