frelation.vue 6.24 KB
<!-- 楼层客流综合指标分布 -->
<template>
    <div>
        <!-- 顶部区域 S-->
        
        <el-row class="ipart ipart2" :gutter="12" v-loading="loading">
            <el-col :span="12">
                <div class="ipage_top">
                    <div class="tit"><img :src="bindIcon('xiansuo')"/>{{title||chartData.title}}</div>
                </div>
                <div class="ichart" :style="{opacity:isEmpty?0:1}">
                    <bar-chart @emitChart="chartClick" :cdata="chartData" tval="hbar"></bar-chart>
                </div>
            </el-col>
            <el-col :span="12" v-if="!isEmpty">
                <div class="ipage_top">
                    <div class="tit">{{floorName}}</div>
                </div>
                <span class="rose_tit">{{roseTitle}}</span>
                <pie-chart :cdata="chartData2"></pie-chart>
                <!-- <bar-chart :cdata="chartData" tval="hbar"></bar-chart> -->
                <!-- <bar-chart :cdata="chartData" tval="hbar"></bar-chart> -->
            </el-col>
            <div class="empty" v-if="isEmpty">
                <img src="/static/img/no_data.png">
                <p>{{$t('pholder.nodata')}}</p>
            </div>
        </el-row>
    </div>
</template>

<script>
import mixin from './mixin';
import mallData from '@/components/Echarts/data';
import _ from 'underscore';
const chartsConfig = {
    floor_gate_percentage:{ //默认
        otherConf:{
            isRose:true,
            labelShow:true,
            animation:true,
            yAxisLineHide:true,
            center:['40%','55%'],
            radius:['30%','80%'],
            legendObj:{
                show:true,
                right:0,
                orient:'vertical'
            },
        }
    }
};
export default {
    mixins: [mixin],
    data() {
        return {
            loading:true,
            isEmpty:true,
            chartData2:{},
            floorList:[],
            floorData:[],
            floorName:'',
            roseTitle:''
        }
    },
    created() {
        this.getFloorList().then(res=>{
            this.floorData = res.data.data;
        })
    },
    methods: {
        loadChartData(params){
            this.chartId = this.getChartId(this.ckey);
            this.loading = true;
            if(this.chartId){ 
               this.ajaxModuleData().then(data=>{
                  this.setChartData(data);
               });
            }else{
               this.setChartData(); 
            }
        },
        chartClick({name,dataIndex}){
            this.setCurrenRose({name,dataIndex});
        },
        setChartData(data){
            try{
                this.floorList = data.series[0].data;
                let floorData = JSON.parse(JSON.stringify({...data,yaxis:data.xaxis/*mallData.body.floorInAndOutLine*/}));
                this._color = this.getSeriesColor();
                floorData.series[0].data = floorData.series[0].data.map((value,i)=>{
                    if(value instanceof Object)return value;
                    let item =  {
                        value:value,
                        /*label:{
                            formatter:'{a}{b}{c}{d}'
                        },*/
                        itemStyle:{
                            color:this._color[i],
                        }
                    }
                    return item;
                })
                this.maxNum = (_.max(_.pluck(floorData.series[0].data,'value')))*1.35;
                floorData.series[1] = {
                    name: 'background',
                    type: 'bar',
                    label:{
                       show:false
                    },
                    itemStyle: {
                        normal: {
                            barBorderRadius: 0,
                            color: 'rgba(0, 0, 0, 0.1)'
                        }
                    },
                    barGap: '-100%',
                    z: 0,
                    data: new Array(floorData.series[0].data.length).fill(this.maxNum)
                };
                this.chartData = Object.assign({},floorData,{
                    otherConf:{
                        reverseAxis:true,
                        labelPosition:'right',
                        usePercent:true,
                        hideLoading:true
                    }
                });
                this.$nextTick(()=>{
                    setTimeout(()=>{
                        let dataIndex = 0;

                        this.chartClick({dataIndex,name:floorData.yaxis.data[dataIndex]});
                        this.loading = false;
                    },200)
                });
                this.isEmpty = false;
            }catch(err){
                this.chartData = {};
                this.isEmpty = true;
                this.loading = false;

            }
        },
        setCurrenRose({name,dataIndex}){
            let floorId = this.floorData.find(item=>item.name==name).id;
            let that = this,chartData = Object.assign({},this.chartData);
            chartData.series[1].data = chartData.series[1].data.map((item,idx)=>{
                if(idx!=dataIndex)return this.maxNum;
                return {
                    value:this.maxNum,
                    itemStyle:{
                        borderColor:that._color[idx],
                        borderWidth:2,
                        shadowColor:that._color[idx],
                        shadowBlur:10
                    } 
                };
            });
            this.chartData = Object.assign({},chartData,chartsConfig[this.ckey]);
            this.loadRoseChartData({name,floorId});
        },
        loadRoseChartData({name,floorId}){
            this.roseTitle = name;
            let key = 'floor_gate_percentage'
            let floorChartId = this.getChartId(key);
            this.floorName = this.getChartName(key);
            this.$api.ipageReport.bodyReport({...this.params,chartIds:floorChartId,floorIds:floorId}).then(res=>{
                let { data } = res.data;
                let charData2 = data[key];
                this.chartData2 = Object.assign({},charData2,chartsConfig[key]);
            })
        }
    }
}
</script>

<style  lang="less">

.rose_tit{
    position:absolute;
    left:1%;
    top:10%;
    font-size: 16px;
    z-index: 9;
}
</style>