Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {
AbstractControl, Form,
FormBuilder,
FormControl,
FormGroup,
Validators
} from '@angular/forms';
@Component({
selector: 'smart-user',
templateUrl: './user.component.html',
styles: []
})
export class UserComponent implements OnInit {
constructor(private fb:FormBuilder,private systemSer:SystemService,
private message:NzMessageService) {
name:[null,[Validators.required,Validators.minLength(6),Validators.maxLength(16)]],
phoneNumber:[null,[Validators.required,Validators.minLength(11),Validators.maxLength(11)]],
organizationId:[null,[Validators.required]],
position:[null,[Validators.required]],
this.title = title;
}
showEditModal(data,title,id){
this.userId = id;
this.groupList = data;
this.isVisible = true;
this.title = title;
this.systemSer.getUser(this.userId).subscribe(
(res)=>{
if(res.errCode == 10000){
this.validateForm.patchValue(res.data);
}
}
)
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
this.validateForm.value.gender = Number(this.validateForm.value.gender);
// this.validateForm.value.status = Number(this.validateForm.value.status);
if(this.title == "新增用户"){
this.create();
}
if(this.title == "编辑用户"){
this.update();
}
}
create(){
this.systemSer.adduser(this.validateForm.value).subscribe(
(res)=>{
if(res.errCode == 10000){
this.isVisible = false;
this.initForm();
this.done.emit();
}
)
}
update(){
this.validateForm.addControl('id',new FormControl(this.userId));
this.systemSer.updateUser(this.validateForm.value).subscribe(
(res)=>{
if(res.errCode == 10000){
this.isVisible = false;
this.initForm();
this.done.emit();