import Vue from "vue";
import numeral from "numeral";
import dayjs from "dayjs";

// 格式化和操作数字
Vue.filter("numberFormat", (value, format) => {
  if (value == null) return "--";
  return numeral(value || 0).format(format);
});

// 格式时间
Vue.filter("dateFilter", (value, format = "YYYY-MM-DD") => {
  if (value == null) return "--";
  return dayjs(value).format(format);
});

Vue.filter("getUserStatus", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "已启用";
    case 2:
      return "已禁用";
    case 3:
      return "已冻结";
  }
});

Vue.filter("getRiskLevel", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "低风险";
    case 2:
      return "中低风险";
    case 3:
      return "中风险";
    case 4:
      return "中高风险";
    case 5:
      return "高风险";
  }
});

Vue.filter("getProductType", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "观点包";
    case 2:
      return "观点";
    case 7:
      return "投资组合";
    case 8:
      return "股票池";
    case 9:
      return "套餐";
    case 21:
      return "增值产品";
    case 22:
      return "三方-课程";
    case 23:
      return "EFT专区";
    case 24:
      return "选股工具";
    case 25:
      return "小飞机理财";
    case 31:
      return "投资课堂";
    case 32:
      return "课程";
  }
});

Vue.filter("getStatus", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "待提交";
    case 2:
      return "待一级审核";
    case 11:
      return "待二级审核";
    case 12:
      return "待三级审核";
    case 3:
      return "已上架";
    case 4:
      return "已驳回";
    case 5:
      return "已下架";
  }
});

Vue.filter("getCommissionStatus", value => {
  // if (value == null) return '--'
  switch (value) {
    case 0:
      return "无信用账号";
    case 1:
      return "成功";
    case -1:
      return "失败";
    case 2:
      return "查询失败";
    default:
      return "--";
  }
});

Vue.filter("getAuthType", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "公开可见";
    case 2:
      return "登录手机可见";
    case 3:
      return "登录资金账号可见";
    case 4:
      return "付费可见";
    case 5:
      return "仅供签约客户查看";
  }
});

Vue.filter("getPeriodType", value => {
  if (value == null) return "--";
  switch (value) {
    case 0:
      return "免费永久,单品提拥";
    case 7:
      return "周";
    case 14:
      return "月";
    case 16:
      return "季度";
    case 19:
      return "半年";
    case 20:
      return "年";
    case 99:
      return "收费永久,单篇收费";
    case 98:
      return "收费永久,整体提拥";
  }
});

Vue.filter("getCustomRiskLevel", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "C1保守型";
    case 2:
      return "C2谨慎型";
    case 3:
      return "C3稳健型";
    case 4:
      return "C4积极型";
    case 5:
      return "C5激进型";
  }
});

Vue.filter("getPayType", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "支付宝";
    case 5:
      return "微信";
    case 13:
      return "提佣支付";
    case 14:
      return "保证金";
  }
});

Vue.filter("getOrderStatus", (value, type) => {
  if (value == null) return "--";
  if (type === 13) {
    switch (value) {
      case 70:
        return "签约失败";
      case 95:
        return "解约中";
      case 100:
        return "已解约";
      case 180:
        return "新订单";
      case 220:
        return "已签约";
    }
  } else {
    switch (value) {
      case 220:
        return "支付成功";
      case 70:
        return "支付取消";
      case 95:
        return "退款中";
      case 100:
        return "退款成功";
      case 180:
        return "新订单";
      case 80:
        return "已过期";
      case 90:
        return "已关闭";
    }
  }
});

Vue.filter("getRefundStatus", (value, type) => {
  if (value == null) return "--";
  let mould = "";
  if (type === 13) {
    mould = "解约";
  } else {
    mould = "退款";
  }
  switch (value) {
    case 180:
      return `申请${mould}`;
    case 200:
      return `${mould}审核通过`;
    case 210:
      return `${mould}失败`;
    case 220:
      return `已${mould}`;
  }
});

Vue.filter("getChannel", value => {
  if (value == null) return "--";
  switch (value) {
    case 1:
      return "APP";
    case 2:
      return "小程序";
  }
});

Vue.filter("formatPhone", phone => {
  // console.log(phone)
  // if(!phone) return phone
  // if (typeof phone == 'number') {
  //   phone = phone.toString();
  // }
  // return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
  return phone;
});

Vue.filter("formatRatio", (value, unit = true, num = 2) => {
  if (value == null || value == "--") {
    return "";
  }
  return (Number(value) * 100).toFixed(num) + (unit ? "%" : "");
});
