Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {
AbstractControl,
FormBuilder,
FormControl,
FormGroup,
Validators
} from '@angular/forms';
import {SystemService} from '../../system.service';
import {NzMessageService, NzTreeNode} from 'ng-zorro-antd';
import {LayoutService} from '../../../layouts/layout.service';
import {CommonService} from '../../../shared/common/common.service';
@Component({
selector: 'smart-role',
templateUrl: './role.component.html',
styles: []
})
export class RoleComponent implements OnInit {
@Output() add = new EventEmitter<any>();
constructor(private fb: FormBuilder, private message: NzMessageService,
private systemSer: SystemService,private layoutSer:LayoutService,private commonSer:CommonService) {
this.validateForm = this.fb.group({
name: [null, [Validators.required]],
status: [null, [Validators.required]],
this.menuList =this.commonSer.listToTree('id','parentId',res.data);
this.menuList.forEach(res => {
res.title = res.name;
res.key = res.id;
res.children.forEach((child)=>{
child.title = child.name;
child.key = child.id;
child.isLeaf = true;
})
});
this.toNode(this.menuList);
}
}
)
}
toNode(data) {
this.nodes = data.map(res => {
return new NzTreeNode(res);
});
}
showEditModal(id){
this.title = "编辑角色";
this.isVisible = true;
this.systemSer.getRole(id).subscribe(
(res)=>{
if(res.errCode == 10000){
data.status += "";
this.validateForm.patchValue(data);
}
}
)
}
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if(this.title == "新增角色"){
this.create();
}
if(this.title == "编辑角色"){
this.update();
}
}
//新增
create(){
const data = {
role:{
name:this.validateForm.value.name,
status:this.validateForm.value.status,
(res) => {
if (res.errCode == 10000) {
this.isVisible = false;
this.add.emit();
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
this.ininForm();
this.message.success('新增成功');
}else{
this.message.error(res.errMsg);
}
}
);
}
//编辑
update(){
const data = {
role:{
id:this.roleId,
name:this.validateForm.value.name,
status:this.validateForm.value.status,
comment:this.validateForm.value.comment,
},
modules:[],
resources:[]
};
this.systemSer.editRole(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.isVisible = false;
this.add.emit();
this.ininForm();
this.message.success('修改成功');
}else{
this.message.error(res.errMsg);