/**
 * 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.isAmount;
  if (!isEmpty(value) && !handle(value, opt.amountType)) {
    return new Error((opt.message) || '格式错误');
  }
  const { max, min, decimal, digit } = opt;
  if (max && value > max) {
    return new Error('数值不能大于' + max);
  } else if (min && value < min) {
    return new Error('数值不能小于' + parseInt(min + 0, 10));
  }
  // TODO 小数校验
  return null;
};

export default validator;
