xufenglei
2018-01-08 904bca110bbd3cd7775c7dcbfabf0447f03e4c91
src/app/routes/systems/account/account-edit/account-edit.component.ts
@@ -4,7 +4,9 @@
import {HttpClient} from '@angular/common/http';
import {environment} from '../../../../../environments/environment';
import {DateService} from '../../../../core/services/date.service';
import {FormGroup, FormBuilder, Validators} from '@angular/forms';
import {FormGroup, FormBuilder, Validators, FormControl} from '@angular/forms';
import {Jsonp} from '@angular/http';
import {Observable} from 'rxjs';
@Component({
  selector: 'app-account-edit',
@@ -15,6 +17,7 @@
  account: any;
  validateForm: FormGroup;
  searchOptions = [];
  constructor(private modalHelper: ModalHelper,
    private subject: NzModalSubject,
@@ -34,8 +37,9 @@
      weixin: [this.account.weixin],
      organizationId: [this.account.organizationId],
      expireTime: [this.account.expireTime],
      id:[this.account.id]
      id: [this.account.id]
    });
    this.searchOptions = this.account.organization ? [this.account.organization] : [];
  }
  save() {
@@ -58,4 +62,28 @@
    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;
        });
      }
    }
  }
}