import type { FormRules } from 'element-plus'

export const validate_T_phone = (rule: any, value: any, callback: any) => {
  if (value === '') {
    callback(new Error('请输入手机号码'))
  } else {
    if (/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(value)) {
      callback()
    } else {
      callback(new Error('请输入正确的手机号码'))
    }
  }
}

let card_reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/

export const validate_T_id_card = (rule: any, value: any, callback: any) => {
  if (value === '') {
    callback(new Error('请输入身份证号码'))
  } else {
    if (card_reg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入正确的身份证号码'))
    }
  }
}

export const validate_T_spouse_phone = (rule: any, value: any, callback: any) => {
  if (/^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(value)) {
    callback()
  } else {
    callback(new Error('请输入正确的手机号码'))
  }
}
export const reuls_validator: FormRules = {
  T_power: [{ required: true, message: '请选择角色', trigger: 'change' }],
  T_name: [{ required: true, message: '请输入名字', trigger: 'blur' }],
  T_user: [{ required: true, message: '请输入账户', trigger: 'blur' }],
  T_pass: [{ required: true, message: '请输入密码', trigger: 'blur' }],
  T_dept: [{ required: true, message: '请选择部门', trigger: 'change' }],
  T_post: [{ required: true, message: '请选择岗位', trigger: 'change' }],
  T_sex: [{ required: true, message: '请选择性别', trigger: 'change' }],
  T_id_card: [{ required: true, validator: validate_T_id_card, trigger: 'blur' }],
  T_nation: [{ required: true, message: '请输入民族', trigger: 'blur' }],
  T_school: [{ required: true, message: '请输入毕业院校', trigger: 'blur' }],
  T_major: [{ required: true, message: '请输入专业', trigger: 'blur' }],
  T_education: [{ required: true, message: '请输入学历', trigger: 'blur' }],
  T_marry: [{ required: true, message: '请选择婚否', trigger: 'change' }],
  T_phone: [{ required: true, validator: validate_T_phone, trigger: 'blur' }],
  T_entry_time: [{ required: true, message: '请选择入职时间', trigger: 'blur' }],
  T_positive_time: [{ required: true, message: '请选择转正时间', trigger: 'blur' }],
  T_entry_type: [{ required: true, message: '请选择入职类型', trigger: 'change' }],
  T_contract_start_time: [{ required: true, message: '请选择开始时间', trigger: 'blur' }],
  T_contract_end_time: [{ required: true, message: '请选择结束时间', trigger: 'blur' }],
  T_expire: [{ required: true, message: '请选择是否到期', trigger: 'change' }],
  T_spouse_phone: [{ required: true, validator: validate_T_spouse_phone, trigger: 'blur' }],
  T_dept_leader: [{ required: true, message: '是否为部门负责人', trigger: 'change' }]
}

export const getEntry_type = (val: number) => {
  switch (val) {
    case 1:
      return '全职'
    case 2:
      return '兼职'
    case 3:
      return '实习生'
  }
}
