
// 确认代理级别
export function levelStatus(level) {
  if (!level && level !== 0) {
    return {
      name: '级别待定',
      color: '#909399'
    }
  }
  let out
  switch (level) {
    case 3:
      out = {
        name: '代理公司',
        color: '#f0a637'
      }
      break
    case 2:
      out = {
        name: '销售经理',
        color: '#67c23a'
      }
      break
    case 1:
      out = {
        name: '销售主管',
        color: '#1fd3c2'
      }
      break
    default:
      out = {
        name: '公司',
        color: '#409eff'
      }
  }
  return out
}
// 格式化时间
export function formatter(thistime, fmt) {
  const $this = new Date(thistime)
  const o = {
    'M+': $this.getMonth() + 1,
    'd+': $this.getDate(),
    'h+': $this.getHours(),
    'm+': $this.getMinutes(),
    's+': $this.getSeconds(),
    'q+': Math.floor(($this.getMonth() + 3) / 3),
    'S': $this.getMilliseconds()
  }
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, ($this.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
    }
  }
  return fmt
}
// 认证状态显示
export function certStatus(status) {
  let out
  switch (status) {
    case 0:
      out = '销售未实名认证'
      break
    case 1:
      out = '等待邀请人审核'
      break
    case 2:
      out = '等待上级审核'
      break
    case 3:
      out = '等待用户确认'
      break
    case 4:
      out = '邀请人审核驳回'
      break
    case 5:
      out = '上级审核驳回'
      break
    case 6:
      out = '授权成功'
      break
    default:
      out = status
  }
  return out
}
// 系统设置拆解
export function filterSet(arr, key) {
  if (arr.length < 1) {
    return null
  }
  return arr.filter(item => {
    return item.keys === key
  })[0]
}

// 数字千分位
export function getThousands(num, isDecimals) {
  if (!num) return 0
  const newNum = isDecimals ? num : parseFloat(num)
  return String(newNum).replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g, '$1,')
}
// 小数转百分比
export function toPercent(point) {
  if (point === '0') {
    return 0
  }
  const str = (Number(point * 100).toFixed()) + '%'
  return str
}
