import {NzModalSubject} from 'ng-zorro-antd';
|
import {Component, OnInit} from '@angular/core';
|
import {HttpClient} from '@angular/common/http';
|
import {environment} from '../../../../../environments/environment';
|
import {FormGroup, FormBuilder, FormControl, Validators} from '@angular/forms';
|
import * as $ from 'jquery';
|
|
|
@Component({
|
selector: 'app-account-edit',
|
templateUrl: './account-edit.component.html',
|
styles: []
|
})
|
export class AccountEditComponent implements OnInit {
|
|
account: any;
|
validateForm: FormGroup;
|
searchOptions = [];
|
|
constructor(
|
private subject: NzModalSubject,
|
public http: HttpClient,
|
private formBuilder: FormBuilder
|
) {
|
|
}
|
|
ngOnInit() {
|
const account = this.account;
|
this.validateForm = this.formBuilder.group({
|
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() {
|
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', validateForm.value).subscribe(() => {
|
this.subject.next('true');
|
this.close();
|
});
|
} else {
|
for (const i in controls) {
|
controls[i].markAsDirty();
|
}
|
}
|
}
|
|
close() {
|
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;
|
});
|
}
|
}
|
}
|
|
}
|