<template>
    <div class="DPcomputer21Box">
        <!-- 采区产量统计 -->
        <div class="dataAnalysisScrView_leftView_title">采区产量统计</div>
        <div class="dataAnalysisScrView_leftView_content" style="position: relative;">
            <div id="echarts1View"></div>
        </div>
    </div>
</template>

<script>
import { Tools, HttpReq, CAMap} from '@/assets/js/common.js';
import * as echarts from 'echarts';
import "echarts-gl";
import { getPie3D } from "../../../components/echarts/bingtu3d";


export default {
    data(){
        return {
            DPcomputer21BoxTimer:null,
            //采取产量统计
            echarts1Data:[],
        }
    },
    mounted(){
        this.loadData();
    },
    methods:{
        loadData(){
            //采取产量统计图表
            HttpReq.truckDispatching.getApiHl1().then((res) => {
                if(res.code == 200){
                    let colorARR = ['#00A8FF','#8FDFFE','#F4F03A','#F5335C','#E68220','#00A8FF','#8FDFFE','#F4F03A','#F5335C','#E68220'];
                    let centerArray = [];
                    res.data.content.forEach((item,index)=>{
                        let a1 = {};
                        let a2 = {};
                        a1.name = item.name;
                        a1.value = item.num;
                        a2.opacity = 0.2,
                        a2.color = colorARR[index],
                        a1.itemStyle = a2;
                        centerArray.push(a1);
                    })
                    this.echarts1Data = centerArray;
                }
                this.echarts1_1Fn();
            })

            this.DPcomputer21BoxTimer = setInterval(() => {
                //采取产量统计图表
                HttpReq.truckDispatching.getApiHl1().then((res) => {
                    if(res.code == 200){
                        let colorARR = ['#00A8FF','#8FDFFE','#F4F03A','#F5335C','#E68220','#00A8FF','#8FDFFE','#F4F03A','#F5335C','#E68220'];
                        let centerArray = [];
                        res.data.content.forEach((item,index)=>{
                            let a1 = {};
                            let a2 = {};
                            a1.name = item.name;
                            a1.value = item.num;
                            a2.opacity = 0.2,
                            a2.color = colorARR[index],
                            a1.itemStyle = a2;
                            centerArray.push(a1);
                        })
                        this.echarts1Data = centerArray;
                    }
                    this.echarts1_1Fn();
                })
            },20000)

        },
        //采取产量统计
        echarts1_1Fn(){
            // 基于准备好的dom，初始化echarts实例
            echarts.init(document.getElementById('echarts1View')).dispose();
            let chartPanel = echarts.init(document.getElementById("echarts1View"));
            for (let i = 0; i < this.echarts1Data.length; i++) {
                delete this.echarts1Data[i].itemStyle.opacity;
            }
            // 传入数据生成 option
            let series = getPie3D(this.echarts1Data, 2);  
            let option = {
                tooltip: {
                    formatter: (params) => {
                        if (
                        params.seriesName !== "mouseoutSeries" &&
                        params.seriesName !== "pie2d"
                        ) {
                        return `<div style="padding:0 0px">${params.seriesName}：${(
                            option.series[params.seriesIndex].pieData.proportion * 100
                        ).toFixed(2)}%</div>`;
                        }
                    },
                },
                legend: {
                    data: this.echarts1Data,
                    top:'center',
                    orient: 'vertical',
                    right: '7%',
                    textStyle: {
                        color: "#fff",
                        fontSize: 14,
                    },
                },
                xAxis3D: {
                min: -1,
                max: 1,
                },
                yAxis3D: {
                min: -1,
                max: 1,
                },
                zAxis3D: {
                min: -1,
                max: 1,
                },
                grid3D: {
                show: false, //是否显示三维笛卡尔坐标系。
                boxHeight: 15, //三维笛卡尔坐标系在三维场景中的高度
                top: "1%",
                // bottom: "80%",
                // environment: "#021041", //背景
                viewControl: {
                    //用于鼠标的旋转，缩放等视角控制
                    alpha: 40, //角度
                    distance: 210, //调整视角到主体的距离，类似调整zoom 重要
                    rotateSensitivity: 0, //设置为0无法旋转
                    zoomSensitivity: 0, //设置为0无法缩放
                    panSensitivity: 0, //设置为0无法平移
                    autoRotate: false, //自动旋转
                },
                },
                series: series,
            };
            chartPanel.setOption(option);
        },
    },
    beforeDestroy(){
        if(this.DPcomputer21BoxTimer) {
			clearInterval(this.DPcomputer21BoxTimer);
            this.DPcomputer21BoxTimer = null;
		}
    }
}
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
}
.DPcomputer21Box{
    width: 20vw;
    height: 23.5vh;
    background-color: rgba(32,42,67,0.95);
    padding: 5px 7px;
    box-sizing: border-box;
    overflow: hidden;
}
.DPcomputer21Box .dataAnalysisScrView_leftView_title{
    margin-bottom: 5px;
    width: 100%;
    height: 3.5vh;
    background:no-repeat center center url('~@/assets/images/cutGraph/biaoti1.png');
	background-size:100% 100%;
    padding-left: 10px;
    box-sizing: border-box;
    font-size: 18px;
    line-height: 3.5vh;
    color: #FAFAFB;
    letter-spacing: 1px;
    text-shadow: 1px 1px 1px #92CBFF;
}
.DPcomputer21Box .dataAnalysisScrView_leftView_content{
    width: 100%;
    height: 19vh;
}
.DPcomputer21Box #echarts1View{
    position: absolute;
    left: -10vh;
    top: -7vh;
    width: 120%;
    height: 27vh;
}
</style>