import type { FormRules } from 'element-plus'

export const floatReg = /^[-\+]?\d+(\.\d+)?$/

const validate_float = (rule: any, value: any, callback: any) => {
  if (value === '') {
    callback(new Error('请输入金额'))
  } else {
    if (floatReg.test(value) || /\d+/.test(value)) {
      callback()
    } else {
      callback(new Error('金额必须是数字或小数'))
    }
  }
}

export const reuls_validator: FormRules = {
  T_base: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_post: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_seniority: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_Perf: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_Perf_score: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_back_payment: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_tax: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_attendance: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_cut_payment: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_pension_insurance: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_unemployment_insurance: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_medical_insurance: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_Large_medical_insurance: [{ required: true, validator: validate_float, trigger: 'blur' }],
  T_housing_fund: [{ required: true, validator: validate_float, trigger: 'blur' }]
}
