import { FormRules } from "element-plus";
import { isArray, validUpperCase } from "/@/utils/validate";
export const projectFormRules: FormRules = {
  company_id: {
    trigger: "change",
    required: true,
    message: "请选择公司"
  },
  card_id: {
    trigger: "change",
    required: true,
    message: "请选择卡类型"
  },
  headname: {
    trigger: "change",
    required: false,
    message: "请选择账号固定前缀"
  },
  username_prefix: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (value === "") return new Error("请输入字母段");
      if (!validUpperCase(value)) return new Error("字母段必须为大写字母！");
      return true;
    }
  },
  username_year: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (typeof value != "number") return new Error("请输入年份段");
      const num = Number(value + "");
      if (num < 0) return new Error("年份段不能低于0");
      return true;
    }
  },
  time: {
    trigger: "change",
    required: true,
    validator(_, value) {
      if (!isArray(value)) return new Error("请选择有效时间");
      const length = value.length;
      if (length === 0) return new Error("请选择有效时间");
      return true;
    }
  }
};
