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

export const upload_invoice_rules: FormRules = {
  status: [
    {
      required: true,
      message: "请选择审核状态",
      trigger: "change"
    }
  ],
  open_type: [
    {
      required: true,
      message: "请选择开票类型",
      trigger: "change"
    }
  ],
  remark: [
    {
      required: false,
      message: "请输入审核备注",
      trigger: "blur"
    }
  ],
  input_type: [
    {
      required: true,
      message: "请选择输入类型",
      trigger: "change"
    }
  ],
  invCode: [
    {
      required: true,
      message: "发票代码格式不正确",
      trigger: "blur",
      validator(_, value) {
        if (!value) {
          return new Error("发票代码不能为空");
        }

        return isnumber(value);
      }
    }
  ],
  invNum: [
    {
      required: true,
      message: "发票号码格式不正确",
      trigger: "blur",
      validator(_, value) {
        if (!value) {
          return new Error("发票号码不能为空");
        }

        return isnumber(value);
      }
    }
  ],
  open_date: [
    {
      required: true,
      message: "请选择开票日期",
      trigger: "change"
    }
  ],
  total_fee: [
    {
      required: true,
      message: "请输入税后金额",
      trigger: "blur"
    }
  ],

  subtotal_fee: [
    {
      required: true,
      message: "请输入税前金额",
      trigger: "blur"
    }
  ],
  checkCode: [
    {
      required: false,
      message: "请输入校验码",
      trigger: "change"
    }
  ]
};

//金税开票
export const jsRequiredKeys = ["status", "open_type"];

export const noPassRequiredKeys = ["status", "remark"];

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

  invtype: [
    {
      required: true,
      message: "请选择发票类型",
      trigger: "change"
    }
  ],
  email: [
    {
      required: true,
      message: "请输入电子邮箱",
      trigger: "change"
    }
  ],
  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;
};

export const mapInvoiceType = [
  {
    label: "纸质专用发票",
    map_value: "04",
    value: "1"
  },
  {
    label: "纸质普通发票",
    map_value: "07",
    value: "2"
  },
  {
    label: "电子普通发票",
    map_value: "26",
    value: "3"
  },
  {
    label: "电子专用发票",
    map_value: "27",
    value: "4"
  }
];
