/**
 * Created by baoyinghai on 12/5/16.
 */
import validation from '../../../../utils/validation';
import { isEmpty } from '../../../../utils/EmptyUtils';

const validator = (record, value, formValues, form, opt = {}) => {
  const handle = validation.isRate;
  if (!isEmpty(value) && !handle(value)) {
    return new Error((opt.message) || '格式错误');
  }
  const { max, min } = opt;
  if (value > max) {
    return new Error((opt.message) || '最大不能超过' + max);
  } else if (min && value < min) {
    return new Error((opt.message) || '最小不能超过' + min);
  }
  return null;
};

export default validator;
