xufenglei
2018-06-21 9cd223e02abde85ba740ae8117e02f254c329167
src/app/routes/systems/account/account-edit/account-edit.component.ts
@@ -1,10 +1,10 @@
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} from '@angular/forms';
import {FormGroup, FormBuilder, FormControl, Validators} from '@angular/forms';
import * as $ from 'jquery';
@Component({
  selector: 'app-account-edit',
@@ -15,11 +15,10 @@
  account: any;
  validateForm: FormGroup;
  searchOptions = [];
  constructor(private modalHelper: ModalHelper,
  constructor(
    private subject: NzModalSubject,
    public dateSrv: DateService,
    public msgSrv: NzMessageService,
    public http: HttpClient,
    private formBuilder: FormBuilder
  ) {
@@ -27,29 +26,39 @@
  }
  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 = account.organization ? [account.organization] : [];
    $(document).keydown(function(event) {
      switch (event.keyCode) {
        case 13: return false;
      }
    });
  }
  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();
      }
    }
  }
@@ -58,4 +67,28 @@
    this.subject.destroy();
  }
  check(accountName) {
    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) {
    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;
        });
      }
    }
  }
}