From 3bbe9a88d9ab747ee2e4f01128547efd1fc20038 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Mon, 29 Jan 2018 16:27:17 +0800
Subject: [PATCH] 编译精简完成

---
 src/app/routes/systems/account/account-edit/account-edit.component.ts |   59 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 31 insertions(+), 28 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 d91dcc6..01a6157 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
@@ -1,12 +1,8 @@
-import {NzModalSubject, NzMessageService} from 'ng-zorro-antd';
+import {NzModalSubject} from 'ng-zorro-antd';
 import {Component, OnInit} from '@angular/core';
-import {ModalHelper} from '@delon/theme';
 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';
+import {FormGroup, FormBuilder, FormControl, Validators} from '@angular/forms';
 
 @Component({
   selector: 'app-account-edit',
@@ -19,10 +15,8 @@
   validateForm: FormGroup;
   searchOptions = [];
 
-  constructor(private modalHelper: ModalHelper,
+  constructor(
     private subject: NzModalSubject,
-    public dateSrv: DateService,
-    public msgSrv: NzMessageService,
     public http: HttpClient,
     private formBuilder: FormBuilder
   ) {
@@ -30,30 +24,33 @@
   }
 
   ngOnInit() {
+    const account = this.account;
     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]
+      accountName: [account.accountName],
+      mobile: [account.mobile],
+      email: [account.email],
+      weixin: [account.weixin],
+      organizationId: [account.organizationId],
+      expireTime: [account.expireTime],
+      id: [account.id]
     });
-    this.searchOptions = this.account.organization ? [this.account.organization] : [];
+    this.searchOptions = account.organization ? [account.organization] : [];
   }
 
   save() {
-    if (this.validateForm.valid) {
-      for (const i in this.validateForm.controls) {
-        this.validateForm.controls[i].disable();
+    const validateForm = this.validateForm;
+    const controls = validateForm.controls;
+    if (validateForm.valid) {
+      for (const i in controls) {
+        controls[i].disable();
       }
-      this.http.post(environment.SERVER_BASH_URL + '/account/account', this.validateForm.value).subscribe(() => {
+      this.http.post(environment.SERVER_BASH_URL + '/account/account', validateForm.value).subscribe(() => {
         this.subject.next('true');
         this.close();
       });
     } else {
-      for (const i in this.validateForm.controls) {
-        this.validateForm.controls[i].markAsDirty();
+      for (const i in controls) {
+        controls[i].markAsDirty();
       }
     }
   }
@@ -63,11 +60,16 @@
   }
 
   check(accountName) {
-    this.http.get(environment.SERVER_BASH_URL + '/account/' + accountName).subscribe((res: any) => {
-      if (res.data > 0) {
-        this.validateForm.controls.accountName.setErrors({unique: true});
-      }
-    });
+    const controlsAccountName = this.validateForm.controls.accountName;
+    if (accountName) {
+      this.http.get(environment.SERVER_BASH_URL + '/account/' + accountName).subscribe((res: any) => {
+        if (res.data > 0) {
+          controlsAccountName.setErrors({unique: true});
+        }
+      });
+    } else {
+      controlsAccountName.setErrors({required: true});
+    }
   }
 
   searchChange(searchText) {
@@ -80,4 +82,5 @@
       }
     }
   }
+
 }

--
Gitblit v1.8.0