/**
 * 手机号格式化
 * import formatPhone from '@/assets/js/public.js';
 * formatPhone.formatPhone(12345678900)
 * @param {String} phone
 */
const formatPhone = (phone) => {
  phone = phone.toString();
  return phone.substr(0, 3) + '****' + phone.substr(7, 11);
};

/**
 * 千分位格式化
 * @param {数字} val
 */
const toThousands = (val) => {
  let num = (val || 0).toString(),
    result = '';
  while (num.length > 3) {
    result = ',' + num.slice(-3) + result;
    num = num.slice(0, num.length - 3);
  }
  if (num) {
    result = num + result;
  }
  return result;
}

export default {
  formatPhone,
  toThousands
}
