Skip to content
role.component.ts 1.56 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {
    AbstractControl,
    FormBuilder,
    FormControl,
    FormGroup,
    Validators
} from '@angular/forms';
import {SystemService} from '../../system.service';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'smart-role',
    templateUrl: './role.component.html',
    styles: []
})
export class RoleComponent implements OnInit {
    @Output() add = new EventEmitter<any>();

    title = '新增角色';
    isVisible = false;
    validateForm: FormGroup;

    constructor(private fb: FormBuilder, private message: NzMessageService,
                private systemSer: SystemService) {
    }

    ngOnInit() {
        this.validateForm = this.fb.group({
            name: [null, [Validators.required]],
            status: [null, [Validators.required]],
            comments: [null, [Validators.required]],
        });
    }

    showModal(): void {
        this.isVisible = true;
    }

    handleCancel(): void {
        this.isVisible = false;
    }

    handleOk(): void {
wangqinghua's avatar
wangqinghua committed
        for (let i in this.validateForm.controls) {
wangqinghua's avatar
wangqinghua committed
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        this.systemSer.addRole(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.isVisible = false;
                    this.add.emit();
                    this.message.info('新增成功');
                }
            }
        );
    }

}