
import { division } from './index'

export function payStatusText(value) {
  const status = [{
    value: -1,
    label: '其它'
  }, {
    value: 0,
    label: '待付款'
  }, {
    value: 1,
    label: '待发货'
  }, {
    value: 2,
    label: '发货中'
  }, , {
    value: 3,
    label: '已发货'
  }, {
    value: 9,
    label: '已完成'
  }, {
    value: 10,
    label: '已取消'
  }]
  const obj = status.find((e) => e?.value == value) ?? {}
  return obj?.label ?? value
}

//售后提示文字
export function saleText(value) {
  const status = [
    {
      value: 1,
      label: '待补充资料'
    },
    {
      value: 2,
      label: '待客服审核中'
    },
    {
      value: 3,
      label: '待客户确认中'
    },
    {
      value: 4,
      label: '待处理'
    },
    {
      value: 5,
      label: '已完成'
    },
    {
      value: 7,
      label: '已取消'
    },
  ]
  const obj = status.find((e) => e?.value == value) ?? {}
  return obj?.label ?? value
}
//物流状态
export function LogisticsText(value) {
  const status = [
    {
      value: 0,
      label: '在途'
    },
    {
      value: 1,
      label: '揽收'
    },
    {
      value: 2,
      label: '疑难'
    },
    {
      value: 3,
      label: '签收'
    },
    {
      value: 4,
      label: '退签'
    },
    {
      value: 5,
      label: '派件'
    },
    {
      value: 6,
      label: '拒签'
    },
    {
      value: 10,
      label: '未知'
    },
    {
      value: 11,
      label: '签收'
    },
  ]
  const obj = status.find((e) => e?.value == value) ?? {}
  return obj?.label ?? value
}
export function typeList(value) {
  let status = [
    {
      value: 1,
      label: '退款退货',
    },
    {
      value: 2,
      label: '退款',
    },
    {
      value: 3,
      label: '换货',
    },
    {
      value: 4,
      label: '漏发',
    },
    {
      value: 5,
      label: '其他',
    },
  ]
  const obj = status.find((e) => e?.value == value) ?? {}
  return obj?.label ?? value
}
//支付方式
export function payment(val) {
  let pay
  switch (val) {
    case "wxpay":
      pay = "微信支付"
      break;
    case "alipay":
      pay = "支付宝"
      break;
    case "wallet":
      pay = "可提"
      break;
    case "balance":
      pay = "余额"
      break;
    case "offline":
      pay = "线下支付"
      break;
  }
  return pay
}
export function formatDate(timestamp, fmt = 'yyyy-MM-dd HH:mm:ss') {
  const date = new Date(timestamp)
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  const o = {
    'M+': date.getMonth() + 1,
    'd+': date.getDate(),
    'H+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds(),
    'f+': date.getMilliseconds()
  }
  for (const k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      const str = o[k] + ''
      fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : _pad(str))
    }
  }
  return fmt
}

export function _pad(n, z = 2) {
  return ('00' + n).slice(-z)
}
//性别
export function filterGender(val) {
  let gender
  switch (val) {
    case "unknown":
      gender = "未知 "
      break;
    case 'male':
      gender = "男"
      break;
    case 'female':
      gender = "女"
      break
  }
  return gender
}

//截取小数点后面的数字
export function intercept(val) {
  return String(val).split('.')[0]
}
//手机号处理
export function showPhone(val) {
  return val?.replace(/^(\d{3})\d+(\d{4})$/, '$1****$2')
}
//银行卡处理
export function hideBankCard(value) {
  if (value && value.length > 8) {
    return `${value.substring(0, 4)} ${"*".repeat(value.length - 8).replace(/(.{4})/g, `$1 `)}${value.length % 4 ? " " : ""}${value.slice(-4)}`;
  }
  return value;
}

//价格格式化
export function numFormat(num, n = 2) {
  if (num >= 10000) {
    num = parseFloat(division(num , 10000).toFixed(n)) + 'W';
  }
  return num;
}
