// 类似金钱,首位不为0,最多2位小数...
export function checkNumPot2(rule, value, callback) {
  const reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  if (!value) {
    return callback(new Error("请填写数字"));
  } else if (value == 0) {
    return callback(new Error("请输入正数,最多2位小数"));
  } else if (!reg.test(value)) {
    return callback(new Error("请输入正数,最多2位小数"));
  } else {
    callback();
  }
}
//最多4位小数
export function checkNumPot4(rule, value, callback) {
  const reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,4})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  if (!value) {
    return callback(new Error("请填写数字"));
  } else if (value == 0) {
    return callback(new Error("请输入正数,最多4位小数"));
  } else if (!reg.test(value)) {
    return callback(new Error("请输入正数,最多4位小数"));
  } else {
    callback();
  }
}

// 整数
export function checkInterNum(rule, value, callback) {
  const reg = /^[0-9]*[1-9][0-9]*$/;
  if (!value) {
    return callback(new Error("请填写正整数"));
  } else if (!reg.test(value)) {
    return callback(new Error("请输入正整数"));
  } else {
    callback();
  }
}
export default {
  phone: [
    {
      required: true,
      pattern: /^1[34578]\d{9}$/,
      message: "目前只支持中国大陆的手机号码",
      trigger: "blur",
    },
  ],
  numPot2: [{ required: true, validator: checkNumPot2, trigger: "blur" }],
  numPot4: [{ required: true, validator: checkNumPot4, trigger: "blur" }],
  InterNum: [{ required: true, validator: checkInterNum, trigger: "blur" }],
  required: [{ required: true, message: "请输入", trigger: "blur" }],
  selectRequired: [{ required: true, message: "请输入", trigger: "change" }],
  dateRequired: [
    { required: true, message: "请输入日期", trigger: "blur", type: "date" },
  ],
};
