import Vue from 'vue';
import { priceFormat, formatTime, staticPath } from '@/apps/mobile/utils/util';
import constants from '@/apps/mobile/constants/index';

function getConstLabel(list, type) {
    for (let i = 0; i < list.length; i++) {
        if (list[i].value === type) {
            return list[i].label;
        }
    }
    return '';
}

/**
 * 相对路径过滤器(主要用于后端接口返回的静态资源)
 * @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('couponUsedFlagPipe', (type) => {
    let str = '';
    switch (type) {
        case 0:
            str = '已失效';
            break;
        case 1:
            str = '未使用';
            break;
        case 2:
            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
            case 9:
                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
            case 9:
                str = '已取消'
                break
            default:
                break
        }
    } else {
        return null;
    }
    return str;
})



// 业务类型
Vue.filter('businessType', type => {
    const typeList = constants.BUSINESS_TYPE_LIST;
    return getConstLabel(typeList, type) || '';
})

// 支付类型
Vue.filter('payType', type => {
    const typeList = constants.PAY_TYPE_LIST;
    return getConstLabel(typeList, type) || '';
})