iColumn.vue 3.34 KB
<template>
    <el-table-column v-if="loadingShow" :label="col.label" :column-key="col.prop" :sortable="col.key?'custom':false" :prop="col.prop" align="left" :border="false" :min-width="col.prop=='defaultOrg1'?'200':width" :fixed="col.fixed" :type="col.type" :formatter="formatter">
        <template #header="{column}">
            <span :class="[col.prop]">
                {{column.label}}
            </span>
        </template>
    </el-table-column>
    <el-table-column v-else :label="col.label" :column-key="col.prop" :sortable="col.key?'custom':false" :prop="col.prop" align="left" :border="false" :min-width="width" :fixed="col.fixed" :type="col.type" :formatter="formatter">
        <template #header="{column}">
            <span :class="[col.prop]">
                {{column.label}}
            </span>
        </template>
    </el-table-column>
</template>

<script>
const scaleVal = 0.5;
export default {
    name: 'iColumn',
    props: {
        col: {
           type: Object
        },
        loadingShow:{
          type: Number
        }
    },
    data(){
        return {
            width:'80'
        }
    },
    methods:{
        numFormat(val){
          return val>10?val:("0"+val)
        },
        getTime(seconds){
            if(isNaN(seconds))return seconds;
            // return parseInt(seconds/3600)+this.$t('format.hoursUnit')+parseInt(seconds%3600/60)+'分'+(seconds%60)+'秒';
            return this.numFormat(parseInt(seconds/3600))+':'+this.numFormat(parseInt(seconds%3600/60))+':'+this.numFormat(parseInt(seconds%60));
        },
        calW(value){

            if(this.col.max){
                let pval,max;
                if(typeof value =='string'){
                    pval = parseFloat(value);
                    max = parseFloat(this.col.max)
                }else{
                    pval = value;
                    max = this.col.max;
                }
                if(isNaN(pval)||isNaN(max))return 0;
                let percent = pval*100/max ;
                if(percent>100)return 0;
                return percent*scaleVal+'%'
            }
            return 0
        },
        calS(value){
            if(this.col.width){
               this.width = this.col.width + 'px';
            }
            if(this.col.type=='string'){
                return value
            }
            if(this.col.type=='integer'||this.col.type=='double'){
                return  this.toThousands(value)
            }
            if(this.col.type=='percent'){
                return value+'%'
            }
            if(this.col.type=='time'){
                return this.getTime(value)
            }

            if(this.col.type=='rank'){
                this.width = '50px';
                return value
            }

        },
        formatter(row, column, value, index) {
          if(this.loadingShow){
            // 是否展示进度条
            return (
                <div class={{icol:true,[column.type]:true}}>
                    <div class="v">{this.calS(value)}</div>
                </div>
            )
          }else{
            return (
                <div class={{icol:true,[column.type]:true}}>
                    <div class="p" style={{width:this.calW(value)}}></div>
                    <div class="v">{this.calS(value)}</div>
                </div>
            )
          }

        }
    }
}
</script>

<style>

</style>