import { showToast, Toast } from 'vant';

export const phoneRule = /^1(3|4|5|6|7|8|9)\d{9}$/;

export const verifyPhone = (data: any) => {
  let options = {
    value: '',
    hint: true,
    message: ''
  };
  if (typeof data === 'string') {
    options.value = data;
  } else if (typeof data === 'object') {
    options = { ...options, ...data };
    return false;
  }
  const { value = '', hint, message } = options;
  let result = true;
  let msg = '';
  if (!value) {
    result = false;
    msg = message || '请输入手机号';
  }
  if (value.length !== 11) {
    result = false;
    msg = message || '请输入正确的手机号';
  }
  if (hint !== false && msg) {
    showToast(msg);
  }
  return result;
};
