const myMixin = {
    props: {
        dataBody: {
            type: Array,
            required: true,
            default: function () {
                return []
            }
        },
        dataHeaders: {
            type: Array,
            required: true,
            default: function () {
                return []
            }
        },
        params: {
            type: [String, Object],
            required: false,
        }
    },
    computed: {
        proxy_params() {
            if ((typeof this.params === 'string' && this.$options.name == 'cube-echart') || typeof this.params == 'object') {
                return this.params
            } else {
                return JSON.parse(this.params);
            }
        }
    },
    methods: {
        filterValue(val, params,drill) {
            let result = val;
            
            if (typeof val === 'number') {
                switch (params.format) {
                    case 'original':
                        result = val;
                        break;
                    case 'decimal':
                        result = val.toFixed(params.fixed);
                        break;
                    case 'percent':
                        result = (val * 100).toFixed(params.fixed) + '%';
                        break;
                    case 'thousand':
                        result = (val).toFixed(params.fixed).replace(/\d+/, function (n) { // 先提取整数部分
                            return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) {
                                return $1 + ",";
                            });
                        });
                        break;
                    case 'unit':
                        result = (val / 10000).toFixed(params.fixed);
                        break;
                    case 'billion':
                        result = (val / 100000000).toFixed(params.fixed);
                        break;
                }
                // 是否添加变色
                if (params.addColor && params.colorNumber !== undefined) {
                    if (val == null) {
                        return '--'
                    } else {
                        if (val == 0) {
                            return 0
                        } else if (val >= params.colorNumber) {   //暂时  
                            if(drill){
                                return `<span>↑${result}</span>`
                            }else{
                                return `<span style="color:#ff3a3a">↑${result}</span>`
                            }
                            
                        } else if (val < params.colorNumber) {
                            if(drill){
                                return `<span>↓${result}</span>`
                            }else{
                                return `<span style="color:#27aa47">↓${result}</span>`
                            }
                            
                        }
                    }
                } else {
                    return result;
                }

            } else {

                if (val === null) {
                    return "--"
                } else {
                    return val;
                }

            }

        },
    }
}
export default myMixin;