import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';

@Component({
    selector: 'smart-check',
    templateUrl: './check.component.html',
    styles: []
})
export class CheckComponent implements OnInit {

    isVisible = false;
    title: string;
    validateForm:FormGroup;

    constructor(private fb:FormBuilder) {
    }

    ngOnInit() {
        this.initForm();
    }

    initForm(){
        this.validateForm = this.fb.group({
            name:['',[Validators.required]],
            fontSize:['',[Validators.required]],
            group:['']
        })
    }

    showAddMOodal() {
        this.isVisible = true;
        this.title = '添加监测点';
    }

    showEditModal() {
        this.title = '编辑监测点';
        this.isVisible = true;
    }

    handleOk(){
        for(let i  in this.validateForm.controls){
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        if(this.validateForm.invalid){
            return false;
        }
        if(this.title == "添加监测点"){
            this.create();
        }
        if(this.title == "编辑监测点"){
            this.update();
        }
    }

    create(){}

    update(){}

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