hbar.vue 3.97 KB
<!-- 逛店数量统计 -->
<!-- 停留时长统计 -->
<template>
    <div>
        <!-- 顶部区域 S-->
        <div class="ipage_top">
            <div class="tit"><img :src="bindIcon('renyuan')"/>{{title||chartData.title}}</div>
            <div class="acts"></div>
        </div>
        <el-row class="ipart ipart2" :gutter="12">
            <el-col>
                <p v-if="ckey=='zone_visited_statistics'" class="ctitle">{{$t('iPage.zoneaverage')}}<span v-html="countVal"></span></p>
                <!-- <p v-if="ckey=='stay_time_statistics'" class="ctitle">{{$t('iPage.stayaverage')}}<span v-html="countVal"></span></p> -->
                <div class="ichart">
                    <bar-chart ref="chart" :cdata="chartData" tval="hbar"></bar-chart>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import mixin from './mixin';
import mallData from '@/components/Echarts/data';
/**********************************************************/
import _ from 'underscore';
const chartsConfig = {
    default:{ //默认
        otherConf:{
            _color:['#90BDFF'],
            reverseAxis:true,
            labelPosition:'right',
            grid:{
                top: 40, right:20, bottom: 20, left: 40
            },
            showCount:false,
            usePercent:true
        }
    }
};
/*******************************************************/
export default {
    mixins: [mixin],
    data() {
        return {
           countVal:'',
           configObj:{} 
        }
    },
    created() {
        
    },
    methods: {
        getChartsConfig(){
            return chartsConfig;
        },
        loadChartData(params){
            this.chartId = this.getChartId(this.ckey);
            if(this.chartId){
               this.ajaxModuleData().then(data=>{
                  this.setChartData(data);
               });
            }else{
               this.setChartData(); 
            }
        },
        setChartData(data){
            try{
                let countVal = _.findWhere(data.series,{name:'avg'}).data[0];
                data.series = _.filter(data.series,item=>item.name!='avg');
                if(countVal||countVal==0){
                    this.countVal = typeof countVal=='string'?countVal.replace('分',' mins').replaceAll(/\d+/g,'<em>$&</em>'):`<em>${countVal}</em>${this.$t('iPage.number')}`;
                }
                let floorData = JSON.parse(JSON.stringify({...data,yaxis:data.xaxis}));
                if(floorData.series[0].data.length){
                    this.maxNum = (_.max(floorData.series[0].data))*1.25;
                    floorData.series[1] = {
                        name: 'background',
                        type: 'bar',
                        label:{
                           show:true
                        },
                        itemStyle: {
                            normal: {
                                barBorderRadius: 0,
                                color: '#F5F7F9'
                            }
                        },
                        /*emphasis:{
                           itemStyle:{
                               color: '#F5F7F9'
                           }
                        },*/
                        barGap: '-100%',
                        z: 0,
                        data: new Array(floorData.series[0].data.length).fill(this.maxNum)
                    };
                }else{
                   floorData.series = []; 
                }
                this.chartData = Object.assign({},floorData,{
                    otherConf:this.configObj.otherConf||{}
                });
            }catch(err){
                this.chartData = {otherConf:{}}
            }
        }
    }
}
</script>

<style  lang="less" scoped>
.ctitle{
    position:absolute;
    left:3%;
    top:2%;
    font-size: 14px;
    z-index: 9;
    em{
        font-size: 16px;
        font-weight: 600;
        font-style:normal;
        margin-left: 5px;
        margin-right: 2px;
    }
}
</style>