import {Component, OnInit, Input} from '@angular/core';
import {AbstractControl, FormGroup} from '@angular/forms';

@Component({
  selector: 'form-msg',
  templateUrl: './form-msg.component.html'
})
export class FormMsgComponent implements OnInit {
  @Input()
  valForm: FormGroup;
  @Input()
  fieldName: string;
  @Input()
  errorCode = 'required';
  @Input()
  errorMsg: string;


  constructor() {

  }

  ngOnInit(): void {
    if (this.errorMsg === undefined) {
      if (this.errorCode === 'required') {
        this.errorMsg = '此处为必填项';
      } else if (this.errorCode === 'minlength') {
        this.errorMsg = '字符太短';
      } else if (this.errorCode === 'maxlength') {
        this.errorMsg = '字符过长';
      } else if (this.errorCode === 'max') {
        this.errorMsg = '数字过大';
      } else if (this.errorCode === 'min') {
        this.errorMsg = '数字太小';
      } else if (this.errorCode === 'datetime') {
        this.errorMsg = '请使用 yyyy-MM-dd HH:mi:ss格式';
      } else if (this.errorCode === 'date') {
        this.errorMsg = '请使用 yyyy-MM-dd 格式';
      }

    }
  }


}
