import { formatTimeToStr } from '@/utils/date'
import { getDict } from '@/utils/dictionary'

export const formatBoolean = (bool) => {
  if (bool !== null) {
    return bool ? '是' : '否'
  } else {
    return ''
  }
}
export const formatDate = (time) => {
  if (time !== null && time !== '') {
    var date = new Date(time)
    return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
  } else {
    return ''
  }
}

export const formatBalance = (balance) => {
  return (balance / 1e8).toFixed(1)
}

export const formatStatus = (status) => {
  if (status === 0) {
    return '准备中'
  } else if (status === 1) {
    return '已发送'
  } else if (status === 2) {
    return '发送失败'
  } else if (status === 3) {
    return '交易成功'
  }
}

export const formatVerifyType = (status) => {
  if (status === 0) {
    return 'google验证'
  } else if (status === 1) {
    return '声纹识别'
  } else if (status === 2) {
    return '无验证'
  } else {
    return '其他验证'
  }
}

export const filterDict = (value, options) => {
  const rowLabel = options && options.filter(item => item.value === value)
  return rowLabel && rowLabel[0] && rowLabel[0].label
}

export const getDictFunc = async(type) => {
  const dicts = await getDict(type)
  return dicts
}
