import Vue from 'vue';
import { staticUrl } from '@/config.js';
import { priceFormat, formatTime, staticPath } from '@/apps//mobile/utils/util';
/**
 * 相对路径过滤器(主要用于后端接口返回的静态资源)
 * @param {String} url
 */
Vue.filter('pathPipe', function (url) {
    return staticPath(url);
});

/**
 * @desc   数字过滤器
 * @param  {undefined|null} val null或者undefined
 * @return {Number}
 */
Vue.filter('numberPipe', (val) => {
    if (val === '' || val === undefined || val === null) {
        return 0;
    }
    return val;
});

/**
 * @desc    价格过滤器
 * @param   {[Number|String]}   arg      原始参数
 * @param   {[Number]}          num      小数点位
 * @param   {[String]}          symbol   符号
 * @param   {[Boolean]}         spilt    是否进行逗号分隔
 * @return  {[String]}
 */
Vue.filter('pricePipe', function (arg, num, symbol, spilt) {
    return priceFormat(arg, num, symbol, spilt);
});

// 全局时间处理过滤器
Vue.filter('formatTimePipe', function (time, format) {
    // 返回处理后的值
    if (time) {
        return formatTime(time, format);
    }
});

// 文件类型
Vue.filter('fileTypePipe', (type) => {
    let str = '';
    switch (type) {
        case 1:
            str = 'tsg';
            break;
        case 2:
            str = '品牌资料';
            break;
        case 3:
            str = '系统资料';
            break;
        default:
            break;
    }
    return str;
});

// 卡券类型
Vue.filter('couponTypePipe', (type) => {
    let str = '';
    switch (type) {
        case 1:
            str = '折扣券';
            break;
        case 2:
            str = '红包';
            break;
        default:
            break;
    }
    return str;
});

// 卡券使用类型
Vue.filter('couponUsePipe', (type) => {
    let str = '';
    switch (type) {
        case 1:
            str = '出诊问诊';
            break;
        case 2:
            str = '题库';
            break;
        case 3:
            str = '视频';
            break;
        default:
            break;
    }
    return str;
});

// 卡券审核状态
Vue.filter('couponAuditPipe', (status) => {
    let str = '';
    switch (status) {
        case 0:
            str = '驳回';
            break;
        case 1:
            str = '通过';
            break;
        case 2:
            str = '待审核';
            break;
        default:
            break;
    }
    return str
})

// 诊单类型
Vue.filter('diagnosisPipe', type => {
    let str = ''
    switch (type) {
        case 1:
            str = '问诊'
            break
        case 2:
            str = '出诊'
            break
        case 3:
            str = '私聊'
            break
        default:
            break
    }
    return str
})


// 小数转为百分数 num保留几位小数
Vue.filter('toPercent', (val, num = 1) => {
    let str = Number(val * 100).toFixed(num);
    str += '%';
    return str;
});

// 会员标志
Vue.filter('vipFlagPipe', status => {
    let str = ''
    switch (status) {
        case 1:
            str = '非会员'
            break
        case 2:
            str = '会员'
            break
        case 3:
            str = '超级会员'
            break
        default:
            break
    }
    return str
})


// 会员标志
Vue.filter('educationPipe', status => {
    let str = ''
    switch (status) {
        case 1:
            str = '高中'
            break
        case 2:
            str = '大专'
            break
        case 3:
            str = '本科'
            break
        case 4:
            str = '硕士'
            break
        case 5:
            str = '博士'
            break
        default:
            break
    }
    return str
})



// 诊单状态
Vue.filter('caseStatusPipe', (status, type) => {
    // type: 1.问诊 2.出诊 3.私聊
    let str = null;
    if (type === 1) {
        switch (status) {
            case 0:
                str = '待付款'
                break
            case 1:
                str = '待接单'
                break
            case 2:
                str = '已接单'
                break
            case 3:
                str = '专家确认完成'
                break
            case 4:
                str = '用户确认完成'
                break
            case 5:
                str = '待归档'
                break
            case 6:
                str = '已完成'
                break
            case 7:
                str = '申诉中'
                break
            case 8:
                str = '拒绝接单'
                break
            default:
                break
        }
    } else if (type === 2) {
        switch (status) {
            case 0:
                str = '待接单'
                break
            case 1:
                str = '已接单'
                break
            case 2:
                str = '待付款'
                break
            case 3:
                str = '已付款'
                break
            case 4:
                str = '专家确认完成'
                break
            case 5:
                str = '用户确认完成'
                break
            case 6:
                str = '已完成'
                break
            case 7:
                str = '申诉中'
                break
            case 8:
                str = '拒绝接单'
                break
            default:
                break
        }
    } else {
        return null;
    }
    return str;
})



// 业务类型
Vue.filter('businessType', type => {
    let str = ''
    switch (type) {
        case 1:
            str = '充值会员'
            break
        case 2:
            str = '打赏'
            break
        case 3:
            str = '充值'
            break
        case 4:
            str = '诊单业务'
            break
        case 5:
            str = '提现'
            break
        case 6:
            str = '提现失败退款'
            break
        case 7:
            str = '余额消费'
            break
        case 8:
            str = '拒绝接单退款'
            break
        case 9:
            str = '专家惩罚'
            break
        case 10:
            str = '申诉退款'
            break
        case 11:
            str = '粉丝充值返利'
            break
        case 12:
            str = '现金支付'
            break
        case 13:
            str = '差旅费'
            break
        default:
            break
    }
    return str
})
