import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { MainService } from '../../../services/main.service';
import { Router, ActivatedRoute } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { ToolService } from 'src/app/services/tool.service';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';

@Component({
  selector: 'app-incident-reject',
  templateUrl: './incident-reject.component.html',
  styleUrls: ['./incident-reject.component.less']
})
export class IncidentRejectComponent implements OnInit {
  @Output() closeModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性，当事件发生时，子组件利用该属性 emits(向上弹射)事件
  @Output() confirmModelHs = new EventEmitter<any>();//1.组件暴露一个 EventEmitter 属性，当事件发生时，子组件利用该属性 emits(向上弹射)事件

  @Input() id: any;

  constructor(
    private mainService: MainService,
    private router: Router,
    private route: ActivatedRoute,
    private message: NzMessageService,
    private tool: ToolService,
    private fb: FormBuilder,
  ) { }

  isLoading = false;

  ngOnInit() {
    this.initForm();
  }

  // 初始化新增form表单
  validateForm: FormGroup; //新增/编辑表单
  initForm() {
    this.validateForm = this.fb.group({
      rejectRemark: [null, [Validators.required]],//不受理原因
    });
    console.log(this.validateForm.controls)
  }

  // 关闭弹窗
  hideModal() {
    this.closeModelHs.emit(JSON.stringify({ show: false }));//emits(向上弹射)事件
  }

  // 表单提交
  maskFlag:any = false;
  submitForm(): void {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
      this.validateForm.controls[i].updateValueAndValidity();
    }
    if (this.validateForm.invalid) {
      return;
    }

    this.confirmModelHs.emit(this.validateForm.value.rejectRemark);
  }
}




