import { Component, OnInit, Output, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { EventEmitter } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-template-name',
  templateUrl: './template-name.component.html',
  styleUrls: ['./template-name.component.less']
})
export class TemplateNameComponent implements OnInit {
  @Output() submitFormHand = new EventEmitter();
  @Output() cancelFlagHand = new EventEmitter();
  @Input() templateFlag: boolean = false;//模态框
  @Input() hosId: any;//院区id
  loading = false;//获取科室的loading
  validateForm: FormGroup;//表单
  constructor(
    private fb: FormBuilder,
    private message: NzMessageService,
  ) { }

  ngOnInit() {
    this.initForm()
  }
  // 隐藏模态框
  hideModal() {
    this.cancelFlagHand.emit(false)
    this.initForm()
  }
  // 初始化新增form表单
  initForm() {
    this.validateForm = this.fb.group({
      name: ['', [Validators.required]]
    });
  }
  // 表单提交
  submitForm(): void {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty({ onlySelf: true });
      this.validateForm.controls[i].updateValueAndValidity();
    }
    if (this.validateForm.invalid) return;
    this.submitFormHand.emit(this.validateForm.value.name);
  }
}

