import { FormRules } from "element-plus";
import {
  isChinese,
  isIDentityCard,
  isEmoticon,
  isEmail
} from "/@/utils/validate";

export const upload_invoice_rules: FormRules = {
  status: [
    {
      required: true,
      message: "请选择审核状态",
      trigger: "change"
    }
  ],
  open_type: [
    {
      required: true,
      message: "请选择开票类型",
      trigger: "change"
    }
  ],
  remark: [
    {
      required: true,
      message: "请输入审核备注",
      trigger: "blur"
    }
  ],
  input_type: [
    {
      required: true,
      message: "请选择输入类型",
      trigger: "change"
    }
  ],
  invCode: [
    {
      required: true,
      message: "请输入发票编号",
      trigger: "blur"
    }
  ],
  invNum: [
    {
      required: true,
      message: "请输入发票代码",
      trigger: "change"
    }
  ],
  open_date: [
    {
      required: true,
      message: "请选择开票日期",
      trigger: "change"
    }
  ],
  total_fee: [
    {
      required: true,
      message: "请输入税后金额",
      trigger: "blur"
    }
  ],

  subtotal_fee: [
    {
      required: true,
      message: "请输入税前金额",
      trigger: "blur"
    }
  ]
};

export const ADD_EDIT_FORM_RULES = {
  companyNo: [
    {
      required: true,
      message: "请选择销售方公司抬头",
      trigger: "change"
    }
  ],
  buy_id: [
    {
      required: true,
      message: "请选择购买方公司抬头",
      trigger: "change"
    }
  ],

  invtype: [
    {
      required: true,
      message: "请选择发票类型",
      trigger: "change"
    }
  ],

  email: [
    {
      required: true
    }
  ],
  id_number: [
    {
      validator(_, value) {
        return !value || isIDentityCard(value);
      },
      trigger: "blur",
      message: "身份证号格式不正确"
    }
  ],
  real_name: [
    {
      validator(_, value) {
        return !value || (isChinese(value) && !isEmoticon(value));
      },
      trigger: "blur",
      message: "真实姓名格式不正确"
    }
  ],
  exam_remark: [
    {
      required: true,
      message: "请输入申请备注",
      trigger: "blur"
    }
  ],
  remark: [
    {
      required: true,
      message: "请输入开票备注",
      trigger: "blur"
    }
  ]
};

export const requriedEmail = (_, value, callback: any) => {
  if (!value) {
    return callback(new Error("邮箱不能为空"));
  } else if (!isEmail(value)) {
    return callback(new Error("邮箱格式不正确"));
  }
  return true;
};
