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

@Component({
  selector: 'form-valid',
  templateUrl: './form-valid.html'
})
export class FormValid implements OnInit {

  @Input()
  form: FormGroup;
  @Input()
  fieldName: string;
  @Input()
  errorCode = 'required';
  @Input()
  errorMsg: string;


  private code: string;

  constructor() {

  }

  ngOnInit(): void {
    this.code = (this.errorCode.toLowerCase());
    if (this.errorMsg === undefined) {
      if (this.code === 'required') {
        this.errorMsg = '此处为必填项';
      } else if (this.code === 'minlength') {
        this.errorMsg = '字符太短';
      } else if (this.code === 'maxlength') {
        this.errorMsg = '字符过长';
      } else if (this.code === 'max') {
        this.errorMsg = '数字过大';
      } else if (this.code === 'min') {
        this.errorMsg = '数字太小';
      } else if (this.code === 'datetime') {
        this.errorMsg = '请使用 yyyy-MM-dd HH:mi:ss格式';
      } else if (this.code === 'date') {
        this.errorMsg = '请使用 yyyy-MM-dd 格式';
      } else if (this.code === 'ename') {
        this.errorMsg = '只能使用a-z,A-Z,0-9和下划线';
      } else if (this.code === 'mobile') {
        this.errorMsg = '请输入正确的手机号';
      } else if (this.code === 'password') {
        this.errorMsg = '两次密码不一致';
      }else
        this.errorMsg = '数据格式错误';


    }
  }


}
