<template>
    <div class="content"
        :class="{ 'content-bgc1': (state.chosdTab === 0 || state.chosdTab === 1 || state.chosdTab === 2 || state.chosdTab === 4), 'content-bgc2': state.chosdTab === 3, 'content-bgc3': state.chosdTab === 5 }">
        <div class="left-tab xl-flex xl-column xl-justify-start xl-between">
            <div class="tab-item xl-flex xl-column  xl-stretch xl-center" v-for="(item, index) in state.leftTab"
                :key="index" @click="goTab(item.name, index)" :class="{ 'chosedTab': state.chosdTab === index }">
                <span class="tab-item-name">{{ item.name }}</span>
                <div class="tab-item-value" v-if="item.value">
                    <span>{{ item.value }}</span>
                    <span>{{ item.unit }}</span>
                </div>
            </div>
        </div>
        <div class="content-bottom xl-flex xl-between">
            <div class="content-bottom-item" style="position: relative;">
                <div class="xl-card">
                    <div class="xl-card-title-444">能源好地方</div>
                    <div class="xl-card-body ">
                        <div class="goodPlace-ellipse">
                        </div>
                        <div>
                            <div class="goodPlace-item xl-flex xl-column" style="position:absolute;bottom:0;left:38%">
                                <div class="goodPlace-item-div xl-flex xl-center">
                                    <img src="@/assets/images/energyDataPanorama/bottom-wrapper-img-gaoYou.png" width="111"
                                        alt="" />
                                </div>
                                <span class="goodPlace-item-name">高邮能大</span>
                            </div>
                            <div class="goodPlace-item xl-flex xl-column" style="position:absolute;bottom:57px;left:4%">
                                <div class="goodPlace-item-div xl-flex xl-center">
                                    <img src="@/assets/images/energyDataPanorama/bottom-wrapper-img-gaoYou.png" width="111"
                                        alt="" />
                                </div>
                                <span class="goodPlace-item-name">高邮能大1</span>
                            </div>
                            <div class="goodPlace-item xl-flex xl-column" style="position:absolute;top:7px;left:38%">
                                <div class="goodPlace-item-div xl-flex xl-center">
                                    <img src="@/assets/images/energyDataPanorama/bottom-wrapper-img-gaoYou.png" width="111"
                                        alt="" />
                                </div>
                                <span class="goodPlace-item-name">高邮能大2</span>
                            </div>
                            <div class="goodPlace-item xl-flex xl-column" style="position:absolute;bottom:57px;right:4%">
                                <div class="goodPlace-item-div xl-flex xl-center">
                                    <img src="@/assets/images/energyDataPanorama/bottom-wrapper-img-gaoYou.png" width="111"
                                        alt="" />
                                </div>
                                <span class="goodPlace-item-name">高邮能大3</span>

                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="content-bottom-item">
                <div class="xl-card">
                    <div class="xl-card-title-444">企业能效中心</div>
                    <div class="xl-card-body  xl-flex xl-between">
                        <div class="enterpriseEnergyCenter xl-flex xl-center">
                            <div class="enterpriseEnergyCenter-left xl-flex xl-column xl-justify-start xl-between">
                                <div class="item-total">13493</div>

                                <div class="item-total-bgc xl-flex xl-center">
                                </div>
                                <div class="item-unit">三个产业本年度总用电量(亿千瓦)</div>
                                <div class="item-type xl-flex xl-between">
                                    <div class="item-type-item xl-flex xl-column xl-between">
                                        <span class="item-type-name">第一产业</span>
                                        <span class="item-type-value">80</span>
                                    </div>
                                    <div class="item-type-item xl-flex xl-column xl-between">
                                        <span class="item-type-name">第二产业</span>
                                        <span class="item-type-value">80</span>
                                    </div>
                                    <div class="item-type-item xl-flex xl-column xl-between">
                                        <span class="item-type-name">第三产业</span>
                                        <span class="item-type-value">80</span>
                                    </div>
                                </div>
                            </div>
                            <div class="enterpriseEnergyCenter-right xl-flex xl-column xl-justify-start xl-between">
                                <div class="item-total">13493</div>

                                <div class="item-total-bgc xl-flex xl-center">
                                </div>
                                <div class="item-unit">三个产业总企业总数量(万个)</div>
                                <div class="item-type xl-flex xl-between">
                                    <div class="item-type-item xl-flex xl-column xl-between">
                                        <span class="item-type-name">第一产业</span>
                                        <span class="item-type-value">80</span>
                                    </div>
                                    <div class="item-type-item xl-flex xl-column xl-between">
                                        <span class="item-type-name">第二产业</span>
                                        <span class="item-type-value">80</span>
                                    </div>
                                    <div class="item-type-item xl-flex xl-column xl-between">
                                        <span class="item-type-name">第三产业</span>
                                        <span class="item-type-value">80</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="content-bottom-item">
                <div class="xl-card">
                    <div class="xl-card-title-444">公共服务中心</div>
                    <div class="xl-card-body publicServiceCenter">
                        <div class="publicServiceCenter-title xl-flex xl-between">
                            <span class="title">商圈、景区、数据中心年用电量Top5排名</span>
                            <div class="select">
                                <el-select v-model="state.publicServiceCenterDataType" class="m-2" placeholder="Select"
                                    size="small" :popper-append-to-body="false" :teleported="false">
                                    <el-option value="商圈">商圈</el-option>
                                    <el-option value="景区">景区</el-option>
                                    <el-option value="数据中心">数据中心</el-option>
                                </el-select>

                            </div>
                        </div>
                        <div class="publicServiceCenter-content xl-flex xl-column xl-between xl-stretch xl-center">
                            <div class="item xl-flex xl-between " v-for="(item, index) in state.publicServiceCenterRank"
                                :key="index">
                                <div class="item-name xl-flex xl-between">
                                    <div class="number">{{ index + 1 }}</div>
                                    <div class="name xl-line">{{ item.name }}</div>
                                </div>
                                <el-progress class="item-progress" :percentage="item.value" color="#27A6FF" striped
                                    striped-flow :duration="8" :show-text="false"></el-progress>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="content-bottom-item">
                <div class="xl-card">
                    <div class="xl-card-title-444">数据共享中心</div>
                    <div class="xl-card-body dataSharingCenter xl-flex  xl-wrap xl-between">
                        <div class="dataSharingCenter-item xl-flex xl-center">
                            <div class="img xl-flex xl-center">
                                <img src="@/assets/images/energyDataPanorama/dataSharingCenter-blue-apply-img.png"
                                    width="26" alt="">
                            </div>
                            <div class="dataSharingCenter-item-content xl-flex xl-column xl-between">
                                <span class="number">20</span>
                                <span class="name">应用数量</span>
                            </div>
                        </div>
                        <div class="dataSharingCenter-item xl-flex xl-center">
                            <div class="img xl-flex xl-center">
                                <img src="@/assets/images/energyDataPanorama/dataSharingCenter-blue-out-img.png" width="26"
                                    alt="">
                            </div>
                            <div class="dataSharingCenter-item-content xl-flex xl-column xl-between">
                                <span class="number">20</span>
                                <span class="name">外部数据量</span>
                            </div>
                        </div>
                        <div class="dataSharingCenter-item xl-flex xl-center">
                            <div class="img xl-flex xl-center">
                                <img src="@/assets/images/energyDataPanorama/dataSharingCenter-blue-interface-img.png"
                                    width="26" alt="">
                            </div>
                            <div class="dataSharingCenter-item-content xl-flex xl-column xl-between">
                                <span class="number">20</span>
                                <span class="name">接口数量</span>
                            </div>
                        </div>
                        <div class="dataSharingCenter-item xl-flex xl-center">
                            <div class="img xl-flex xl-center">
                                <img src="@/assets/images/energyDataPanorama/dataSharingCenter-blue-in-img.png" width="26"
                                    alt="">
                            </div>
                            <div class="dataSharingCenter-item-content xl-flex xl-column xl-between">
                                <span class="number">20</span>
                                <span class="name">内部数据量</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="content-right-top">
            <div class="xl-card">
                <div class="xl-card-title-444">能源消费</div>
                <div class="xl-card-body energy-customer-content xl-flex xl-wrap xl-between">
                    <div class="energy-customer-content-item xl-flex xl-column xl-center">
                        <span class="item-title">用煤量</span>
                        <span class="item-value">123123<span class="item-unit">（万吨）</span></span>
                    </div>
                    <div class="energy-customer-content-item xl-flex xl-column xl-center">
                        <span class="item-title">用电量</span>
                        <span class="item-value">1233<span class="item-unit">（万Kwh）</span></span>
                    </div>
                    <div class="energy-customer-content-item xl-flex xl-column xl-center">
                        <span class="item-title">用油量</span>
                        <span class="item-value">123123<span class="item-unit">（万吨）</span></span>
                    </div>
                    <div class="energy-customer-content-item xl-flex xl-column xl-center">
                        <span class="item-title">用气量</span>
                        <span class="item-value">123123<span class="item-unit">（万m³）</span></span>
                    </div>
                    <div class="energy-customer-content-center-content xl-flex xl-column xl-center">
                        <span>能源消费总量</span>
                        <span>1531.0</span>
                        <span>万吨标准煤</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="content-right-bottom">
            <div class="xl-card">
                <div class="xl-card-title-444">能源生产</div>
                <div class="xl-card-body energy-produce xl-flex xl-column xl-between">
                    <div class="energy-produce-pie" ref="pie3d"></div>
                    <div class="energy-produce-detail xl-flex xl-wrap xl-between">
                        <div class="energy-produce-detail-item xl-flex xl-between">
                            <div class="xl-flex">
                                <div class="dot"></div>
                                <span>火力发电</span>
                            </div>
                            <span value>200MV</span>
                        </div>
                        <div class="energy-produce-detail-item xl-flex xl-between">
                            <div class="xl-flex">
                                <div class="dot"></div>
                                <span>火力发电</span>
                            </div>
                            <span value>200MV</span>
                        </div>
                        <div class="energy-produce-detail-item xl-flex xl-between">
                            <div class="xl-flex">
                                <div class="dot"></div>
                                <span>火力发电</span>
                            </div>
                            <span value>200MV</span>
                        </div>
                        <div class="energy-produce-detail-item xl-flex xl-between">
                            <div class="xl-flex">
                                <div class="dot"></div>
                                <span>火力发电</span>
                            </div>
                            <span value>200MV</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="middle">
            <router-view></router-view>
        </div>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref, toRefs } from "vue"
import { useRouter } from "vue-router";
import * as echarts from 'echarts'
import 'echarts-gl';

interface ILeftTab {
    name: string
    value: string | number
    unit?: string
}
interface IState {
    chosdTab: string | number
    publicServiceCenterDataType: string
    leftTab: Array<ILeftTab>
    publicServiceCenterRank: Array<{
        value: string
        name: string
    }>
    pieDom: any
    option?: any
    optionData: any
}
const router = useRouter();
const state: IState = reactive({
    chosdTab: 0,
    pieDom: null,
    option: '',
    publicServiceCenterDataType: '商圈',// 公共服务中心下拉的数据类型
    publicServiceCenterRank: [
        {
            name: '五彩世界',
            value: '10',
        },
        {
            name: '中集文昌商业中心',
            value: '20',
        },
        {
            name: '五彩世界',
            value: '10',
        },
        {
            name: '中集文昌商业中心',
            value: '20',
        },
        {
            name: '中集文昌商业中心',
            value: '90',
        },
    ],
    optionData: [
        {
            name: '火力发电',
            value: 10000,
            itemStyle: {
                color: '#ff744c',
            }
        }, {
            name: '风力发电',
            value: 12116,
            itemStyle: {
                color: '#27a6ff'
            }
        }, {
            name: '太阳能发电',
            value: 16616,
            itemStyle: {
                color: '#ffc572'
            }
        },
        {
            name: '生物质能发电',
            value: 16616,
            itemStyle: {
                color: '#05bd91'
            }
        }
    ],

    leftTab: [
        {
            name: '单位GDP能耗',
            value: 0.25,
            unit: '吨标准煤/万元'
        },
        {
            name: '总装机容量',
            value: 0.25,
            unit: '吨标准煤/万元'
        },
        {
            name: '年度社会用电量',
            value: 0.25,
            unit: '吨标准煤/万元'
        },
        {
            name: '能源消费总量',
            value: 0.25,
            unit: '吨标准煤/万元'
        },
        {
            name: '充电桩数量',
            value: 0.25,
            unit: '吨标准煤/万元'
        },
        {
            name: '页面介绍',
            value: '',
            unit: ''
        },
    ]
})
// 3d饼图dom
const pie3d = ref(null as HTMLInputElement | null)
const bindListen = (myChart: any) => {
    // 监听鼠标事件，实现饼图选中效果（单选），近似实现高亮（放大）效果。
    let selectedIndex = '';
    let hoveredIndex = '';
    // 监听点击事件，实现选中效果（单选）
    myChart.on('click', function (params) {
        // 从 option.series 中读取重新渲染扇形所需的参数，将是否选中取反。
        let isSelected = !state.option.series[params.seriesIndex].pieStatus.selected;
        let isHovered = state.option.series[params.seriesIndex].pieStatus.hovered;
        let k = state.option.series[params.seriesIndex].pieStatus.k;
        let startRatio = state.option.series[params.seriesIndex].pieData.startRatio;
        let endRatio = state.option.series[params.seriesIndex].pieData.endRatio;
        // 如果之前选中过其他扇形，将其取消选中（对 option 更新）
        if (selectedIndex !== '' && selectedIndex !== params.seriesIndex) {
            state.option.series[selectedIndex].parametricEquation = getParametricEquation(state.option.series[
                selectedIndex].pieData
                .startRatio, state.option.series[selectedIndex].pieData.endRatio, false, false, k, state.option.series[
                    selectedIndex].pieData
                .value);
            state.option.series[selectedIndex].pieStatus.selected = false;
        }
        // 对当前点击的扇形，执行选中/取消选中操作（对 option 更新）
        state.option.series[params.seriesIndex].parametricEquation = getParametricEquation(startRatio, endRatio,
            isSelected,
            isHovered, k, state.option.series[params.seriesIndex].pieData.value);
        state.option.series[params.seriesIndex].pieStatus.selected = isSelected;
        // 如果本次是选中操作，记录上次选中的扇形对应的系列号 seriesIndex
        isSelected ? selectedIndex = params.seriesIndex : null;
        // 使用更新后的 option，渲染图表
        myChart.setOption(state.option);
    });
    // 监听 mouseover，近似实现高亮（放大）效果
    myChart.on('mouseover', function (params) {
        // 准备重新渲染扇形所需的参数
        let isSelected;
        let isHovered;
        let startRatio;
        let endRatio;
        let k;
        // 如果触发 mouseover 的扇形当前已高亮，则不做操作
        if (hoveredIndex === params.seriesIndex) {
            return;
            // 否则进行高亮及必要的取消高亮操作
        } else {
            // 如果当前有高亮的扇形，取消其高亮状态（对 option 更新）
            if (hoveredIndex !== '') {
                // 从 option.series 中读取重新渲染扇形所需的参数，将是否高亮设置为 false。
                isSelected = state.option.series[hoveredIndex].pieStatus.selected;
                isHovered = false;
                startRatio = state.option.series[hoveredIndex].pieData.startRatio;
                endRatio = state.option.series[hoveredIndex].pieData.endRatio;
                k = state.option.series[hoveredIndex].pieStatus.k;
                // 对当前点击的扇形，执行取消高亮操作（对 option 更新）
                state.option.series[hoveredIndex].parametricEquation = getParametricEquation(startRatio, endRatio,
                    isSelected,
                    isHovered, k, state.option.series[hoveredIndex].pieData.value);
                state.option.series[hoveredIndex].pieStatus.hovered = isHovered;
                // 将此前记录的上次选中的扇形对应的系列号 seriesIndex 清空
                hoveredIndex = '';
            }
            // 如果触发 mouseover 的扇形不是透明圆环，将其高亮（对 option 更新）
            if (params.seriesName !== 'mouseoutSeries' && params.seriesName !== 'pie2d') {
                // 从 option.series 中读取重新渲染扇形所需的参数，将是否高亮设置为 true。
                isSelected = state.option.series[params.seriesIndex].pieStatus.selected;
                isHovered = true;
                startRatio = state.option.series[params.seriesIndex].pieData.startRatio;
                endRatio = state.option.series[params.seriesIndex].pieData.endRatio;
                k = state.option.series[params.seriesIndex].pieStatus.k;
                // 对当前点击的扇形，执行高亮操作（对 option 更新）
                state.option.series[params.seriesIndex].parametricEquation = getParametricEquation(startRatio, endRatio,
                    isSelected, isHovered, k, state.option.series[params.seriesIndex].pieData.value + 5);
                state.option.series[params.seriesIndex].pieStatus.hovered = isHovered;
                // 记录上次高亮的扇形对应的系列号 seriesIndex
                hoveredIndex = params.seriesIndex;
            }
            // 使用更新后的 option，渲染图表
            myChart.setOption(state.option);
        }
    });
    // 修正取消高亮失败的 bug
    myChart.on('globalout', function () {
        // 准备重新渲染扇形所需的参数
        let isSelected;
        let isHovered;
        let startRatio;
        let endRatio;
        let k;
        if (hoveredIndex !== '') {
            // 从 option.series 中读取重新渲染扇形所需的参数，将是否高亮设置为 true。
            isSelected = state.option.series[hoveredIndex].pieStatus.selected;
            isHovered = false;
            k = state.option.series[hoveredIndex].pieStatus.k;
            startRatio = state.option.series[hoveredIndex].pieData.startRatio;
            endRatio = state.option.series[hoveredIndex].pieData.endRatio;
            // 对当前点击的扇形，执行取消高亮操作（对 option 更新）
            state.option.series[hoveredIndex].parametricEquation = getParametricEquation(startRatio, endRatio,
                isSelected,
                isHovered, k, state.option.series[hoveredIndex].pieData.value);
            state.option.series[hoveredIndex].pieStatus.hovered = isHovered;
            // 将此前记录的上次选中的扇形对应的系列号 seriesIndex 清空
            hoveredIndex = '';
        }
        // 使用更新后的 option，渲染图表
        myChart.setOption(state.option);
    });
}
// 定义3d饼图的竖向的高度
const getHeight3D = (series: any, height: any) => {
    series.sort((a, b) => {
        return (b.pieData.value - a.pieData.value);
    })
    return height * 25 / series[0].pieData.value;
}

const fomatFloat = (num: any, n: any) => {
    var f = parseFloat(num);
    if (isNaN(f)) {
        return false;
    }
    f = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); // n 幂   
    var s = f.toString();
    var rs = s.indexOf('.');
    //判定如果是整数，增加小数点再补0
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + n) {
        s += '0';
    }
    return s;
}

const getParametricEquation = (startRatio: any, endRatio: any, isSelected: any, isHovered: any, k: any, h: any) => {
    // 计算
    let midRatio = (startRatio + endRatio) / 2;
    let startRadian = startRatio * Math.PI * 2;
    let endRadian = endRatio * Math.PI * 2;
    let midRadian = midRatio * Math.PI * 2;
    // 如果只有一个扇形，则不实现选中效果。
    if (startRatio === 0 && endRatio === 1) {
        isSelected = false;
    }
    // 通过扇形内径/外径的值，换算出辅助参数 k（默认值 1/3）
    k = typeof k !== 'undefined' ? k : 1 / 3;
    // 计算选中效果分别在 x 轴、y 轴方向上的位移（未选中，则位移均为 0）
    let offsetX = isSelected ? Math.cos(midRadian) * 0.1 : 0;
    let offsetY = isSelected ? Math.sin(midRadian) * 0.1 : 0;
    // 计算高亮效果的放大比例（未高亮，则比例为 1）
    let hoverRate = isHovered ? 1.05 : 1;
    // 返回曲面参数方程
    return {
        u: {
            min: -Math.PI,
            max: Math.PI * 3,
            step: Math.PI / 32
        },
        v: {
            min: 0,
            max: Math.PI * 2,
            step: Math.PI / 20
        },
        x: function (u, v) {
            if (u < startRadian) {
                return offsetX + Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
            }
            if (u > endRadian) {
                return offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
            }
            return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate;
        },
        y: function (u, v) {
            if (u < startRadian) {
                return offsetY + Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
            }
            if (u > endRadian) {
                return offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
            }
            return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate;
        },
        z: function (u, v) {
            if (u < -Math.PI * 0.5) {
                return Math.sin(u);
            }
            if (u > Math.PI * 2.5) {
                return Math.sin(u) * h * .1;
            }
            return Math.sin(v) > 0 ? 1 * h * .1 : -1;
        }
    };
}

const getPie3D = (pieData: any, internalDiameterRatio: any) => {
    //internalDiameterRatio:透明的空心占比
    let series = [];
    let sumValue = 0;
    let startValue = 0;
    let endValue = 0;
    let legendData = [];
    let legendBfb: any = [];
    let k = 1 - internalDiameterRatio;
    pieData.sort((a: any, b: any) => {
        return (b.value - a.value);
    });
    // 为每一个饼图数据，生成一个 series-surface 配置
    for (let i = 0; i < pieData.length; i++) {
        sumValue += pieData[i].value;
        let seriesItem = {
            name: typeof pieData[i].name === 'undefined' ? `series${i}` : pieData[i].name,
            type: 'surface',
            parametric: true,
            wireframe: {
                show: false
            },
            pieData: pieData[i],
            pieStatus: {
                selected: false,
                hovered: false,
                k: k
            },
            center: ['10%', '50%']
        };

        if (typeof pieData[i].itemStyle != 'undefined') {
            let itemStyle = {};
            typeof pieData[i].itemStyle.color != 'undefined' ? itemStyle.color = pieData[i].itemStyle.color : null;
            typeof pieData[i].itemStyle.opacity != 'undefined' ? itemStyle.opacity = pieData[i].itemStyle.opacity : null;
            seriesItem.itemStyle = itemStyle;
        }
        series.push(seriesItem);
    }

    // 使用上一次遍历时，计算出的数据和 sumValue，调用 getParametricEquation 函数，
    // 向每个 series-surface 传入不同的参数方程 series-surface.parametricEquation，也就是实现每一个扇形。
    legendData = [];
    legendBfb = [];
    for (let i = 0; i < series.length; i++) {
        endValue = startValue + series[i].pieData.value;
        series[i].pieData.startRatio = startValue / sumValue;
        series[i].pieData.endRatio = endValue / sumValue;
        series[i].parametricEquation = getParametricEquation(series[i].pieData.startRatio, series[i].pieData.endRatio,
            false, false, k, series[i].pieData.value);
        startValue = endValue;
        let bfb = fomatFloat(series[i].pieData.value / sumValue, 4);
        legendData.push({
            name: series[i].name,
            value: bfb
        });
        legendBfb.push({
            name: series[i].name,
            value: bfb
        });
    }
    let boxHeight = getHeight3D(series, 15);//通过传参设定3d饼/环的高度，26代表26px
    // 准备待返回的配置项，把准备好的 legendData、series 传入。
    let option = {
        title: [{
            text: '680',
            x: 'center',
            y: '0%',
            textStyle: {
                fontWeight: 'normal',
                color: '#fff',
                fontSize: '24'
            }
        }, {
            text: '总装机容量(MW)',
            x: 'center',
            y: '25%',
            textStyle: {
                fontWeight: 'normal',
                color: '#A1D1EF',
                fontSize: '14'
            }
        }],
        // legend: {
        //     data: legendData,
        //     orient: 'horizontal',
        //     left: 10,
        //     top: 10,
        //     itemGap: 10,
        //     textStyle: {
        //         color: '#A1E2FF',
        //     },
        //     show: false,  // 不显示 3d图的 图例
        //     icon: "circle",
        //     formatter: function (param) {
        //         let item = legendBfb.filter(item => item.name == param)[0];
        //         let bfs = fomatFloat(item.value * 100, 2) + "%";
        //         return `${item.name}  ${bfs}`;
        //     }
        // },
        // labelLine: {
        //     show: false,
        //     lineStyle: {
        //         color: '#7BC0CB'
        //     }
        // },
        // label: {
        //     show: false,
        //     position: 'outside',
        //     rich: {
        //         b: {
        //             color: '#7BC0CB',
        //             fontSize: 12,
        //             lineHeight: 20
        //         },
        //         c: {
        //             fontSize: 16,
        //         },
        //     },
        //     formatter: '{b|{b} \n}{c|{c}}{b|  亩}',

        // },
        xAxis3D: {
            min: -1,
            max: 1
        },
        yAxis3D: {
            min: -1,
            max: 1
        },
        zAxis3D: {
            min: -1,
            max: 1
        },
        grid3D: {
            // boxWidth: 250,

            show: false,
            boxHeight: boxHeight, //圆环的高度
            top: -15,// 距离容器的顶部的距离    
            viewControl: { //3d效果可以放大、旋转等，请自己去查看官方配置
                alpha: 25, //角度
                distance: 120,//调整视角到主体的距离，类似调整zoom
                rotateSensitivity: 0, //设置为0无法旋转
                zoomSensitivity: 0, //设置为0无法缩放
                panSensitivity: 0, //设置为0无法平移
                autoRotate: false //自动旋转
            }
        },
        series: series
    };
    return option;
}

onMounted(() => {
    console.log(pie3d.value, '123123');

    let myChart = echarts.init(pie3d.value, { renderer: 'svg' });


    // 传入数据生成 option
    state.option = getPie3D(state.optionData, 0.8);
    myChart.setOption(state.option);
    //是否需要label指引线，如果要就添加一个透明的2d饼状图并调整角度使得labelLine和3d的饼状图对齐，并再次setOption
    state.option.series.push({
        name: 'pie2d',
        type: 'pie',
        labelLine: {
            show: false, // 不显示引导线
            length: 10,
            length2: 10
        },
        startAngle: -20, //起始角度，支持范围[0, 360]。
        clockwise: false,//饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
        radius: ['20%', '50%'],
        center: ['10%', '100%'],
        data: state.optionData,
        itemStyle: {
            opacity: 0
        }
    });
    myChart.setOption(state.option);
    bindListen(myChart);

})


// 左侧tab点击
const goTab = (item: string, index: number) => {
    // alert(item)
    state.chosdTab = index
    if (item == '单位GDP能耗') {
        router.push('/energyDataPanorama/GDP')
    }
    if (item == '总装机容量') {
        router.push('/energyDataPanorama/installedCapacity')
    }
    if (item == '年度社会用电量') {
        router.push('/energyDataPanorama/yearSocialElectricity')
    }
    if (item == '能源消费总量') {
        router.push('/energyDataPanorama/totalEnergyConsume')
    }
    if (item == '充电桩数量') {
        router.push('/energyDataPanorama/chargeStations')
    }
    if (item == '页面介绍') {
        router.push('/energyDataPanorama/pageIntroduce')
    }
}
</script>

<style lang="less" scoped>
@keyframes rotate {
    0% {
        transform: rotateX(0deg) rotateZ(0);
    }

    100% {
        transform: rotateX(0deg) rotateZ(360deg);
    }
}

.content-bgc1 {
    background: url(@/assets/images/energyDataPanorama/content-bgc1.png) no-repeat center;
}

.content-bgc2 {
    background: url(@/assets/images/energyDataPanorama/content-bgc2.png) no-repeat center;
}

.content-bgc3 {
    background: pink url(@/assets/images/energyDataPanorama/content-bgc1.png) no-repeat center;
}

.content {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 22px 24px 24px;
    background-size: 100%;

    .middle {
        width: 1198px;
        height: 686px;
        left: 221px;
        position: absolute;
        top: 1px;
        z-index: 2;
    }

    .left-tab {
        position: absolute;
        width: 192px;
        height: 556px;
        box-shadow: inset 0px 0px 15px #138EE4;
        border-radius: 4px;
        left: 24px;
        top: 78px;
        padding: 12px;

        .tab-item {
            cursor: pointer;
            width: 168px;
            height: 82px;
            background: url(@/assets/images/energyDataPanorama/left-card-nochosed-bgc.png) no-repeat center;
            background-size: 100%;
            padding: 12px;
            padding-left: 15px;
            padding-right: 10px;

            .tab-item-name {
                font-style: normal;
                font-weight: 400;
                font-size: 14px;
                line-height: 20px;
                /* identical to box height */


                /* 二级字色 */
                color: #A1D1EF;
            }

            .tab-item-value span:first-child {
                font-style: normal;
                font-weight: 500;
                font-size: 24px;
                line-height: 34px;
                /* identical to box height */
                margin-right: 5px;


                /* 二级字色 */

                color: #A1D1EF;
            }

            .tab-item-value span:last-child {
                font-style: normal;
                font-size: 14px;

                color: #6699c1;
            }
        }

        .chosedTab {
            width: 168px;
            height: 82px;
            background: url(@/assets/images/energyDataPanorama/left-card-chosed-bgc.png) no-repeat center !important;
            background-size: 100% !important;
        }
    }

    .content-bottom {
        width: 1872px;
        height: 266px;
        position: absolute;
        bottom: 24px;
        padding: 16px 16px 0 16px;
        background: rgba(3, 31, 58, 0.3);
        backdrop-filter: blur(7.5px);
        border-radius: 4px;

        .content-bottom-item {
            width: 444px;
            height: 100%;

            .goodPlace-ellipse {
                width: 305px;
                height: 305px;
                border-radius: 50%;
                position: absolute;
                border: 2px #61b2eb solid;
                transform-style: preserve-3d;
                transform: rotateZ(90deg) rotateY(60deg) translateZ(-60px)translateY(-60px);


            }

            .goodPlace-item {
                cursor: pointer;

                .goodPlace-item-div {
                    width: 119px;
                    height: 90px;
                    border-radius: 10px;
                    border: 1px solid #6AC1FF;
                }

                .goodPlace-item-name {
                    font-weight: 500;
                    font-size: 14px;
                    line-height: 20px;
                    color: #A1D1EF;
                }
            }

            .enterpriseEnergyCenter {
                width: 100%;
                margin-top: 16px;
                height: 182px;

                .enterpriseEnergyCenter-left {
                    width: 204px;
                    height: 100%;
                    background: url(@/assets/images/energyDataPanorama/enterpriseEnergyCenter-left-bgc.png) no-repeat center;
                    background-size: 100%;
                    position: relative;
                    margin-right: 16px;

                    .item-total {
                        position: absolute;
                        top: 45px;
                        font-weight: 500;
                        font-size: 16px;
                        line-height: 22px;
                        text-align: center;

                        /* 一级字色 */

                        color: #FFFFFF;
                    }

                    .item-total-bgc {
                        width: 72px;
                        height: 72px;
                        margin-top: 9px;
                        background: url(@/assets/images/energyDataPanorama/enterpriseEnergyCenter-left-img.png) no-repeat center;
                        background-size: 100%;
                        animation: rotate 5s linear infinite;
                    }

                    .item-unit {
                        font-style: normal;
                        font-weight: 500;
                        font-size: 12px;
                        line-height: 17px;
                        text-align: center;
                        color: #FFFFFF;
                    }

                    .item-type {
                        width: 100%;
                        height: 46px;

                        .item-type-item {
                            width: 60px;
                            height: 46px;
                            padding: 4px 0;

                            .item-type-name {
                                font-weight: 400;
                                font-size: 12px;
                                line-height: 17px;
                                text-align: center;
                                color: #A1D1EF;
                            }

                            .item-type-value {
                                font-weight: 500;
                                font-size: 12px;
                                line-height: 17px;
                                text-align: center;
                                color: #FFFFFF;
                            }
                        }
                    }
                }

                .enterpriseEnergyCenter-right {
                    width: 204px;
                    height: 100%;
                    background: url(@/assets/images/energyDataPanorama/enterpriseEnergyCenter-right-bgc.png) no-repeat center;
                    background-size: 100%;
                    position: relative;

                    .item-total {
                        position: absolute;
                        top: 45px;
                        font-weight: 500;
                        font-size: 16px;
                        line-height: 22px;
                        text-align: center;

                        /* 一级字色 */

                        color: #FFFFFF;
                    }

                    .item-total-bgc {
                        width: 72px;
                        height: 72px;
                        margin-top: 9px;
                        background: url(@/assets/images/energyDataPanorama/enterpriseEnergyCenter-right-img.png) no-repeat center;
                        background-size: 100%;
                        animation: rotate 5s linear infinite;
                    }

                    .item-unit {
                        font-style: normal;
                        font-weight: 500;
                        font-size: 12px;
                        line-height: 17px;
                        text-align: center;
                        color: #FFFFFF;
                    }

                    .item-type {
                        width: 100%;
                        height: 46px;

                        .item-type-item {
                            width: 60px;
                            height: 46px;
                            padding: 4px 0;

                            .item-type-name {
                                font-weight: 400;
                                font-size: 12px;
                                line-height: 17px;
                                text-align: center;
                                color: #A1D1EF;
                            }

                            .item-type-value {
                                font-weight: 500;
                                font-size: 12px;
                                line-height: 17px;
                                text-align: center;
                                color: #FFFFFF;
                            }
                        }
                    }
                }
            }

            .dataSharingCenter {
                height: 132px;
                margin-top: 40px;
                padding: 0 70px;
                align-content: space-between;

                .dataSharingCenter-item:nth-of-type(1),
                .dataSharingCenter-item:nth-of-type(4) {
                    .img {
                        width: 44px;
                        height: 50px;
                        background: url(@/assets/images/energyDataPanorama/dataSharingCenter-blue-bgc.svg) no-repeat center;
                        background-size: 100%;
                    }

                    .dataSharingCenter-item-content {
                        margin-left: 10px;

                        .number {
                            font-style: normal;
                            font-weight: 500;
                            font-size: 22px;
                            line-height: 31px;
                            color: #27A6FF;
                        }

                        .name {
                            font-style: normal;
                            font-weight: 500;
                            font-size: 14px;
                            line-height: 20px;
                            color: #A1D1EF;
                        }
                    }

                }

                .dataSharingCenter-item:nth-of-type(2),
                .dataSharingCenter-item:nth-of-type(3) {
                    .img {
                        width: 44px;
                        height: 50px;
                        background: url(@/assets/images/energyDataPanorama/dataSharingCenter-yellow-bgc.svg) no-repeat center;
                        background-size: 100%;
                    }

                    .dataSharingCenter-item-content {
                        margin-left: 10px;

                        .number {
                            font-style: normal;
                            font-weight: 500;
                            font-size: 22px;
                            line-height: 31px;
                            color: #FF744C;
                        }

                        .name {
                            font-style: normal;
                            font-weight: 500;
                            font-size: 14px;
                            line-height: 20px;
                            color: #A1D1EF;
                        }
                    }

                }
            }

            .publicServiceCenter {
                height: 190px;
                margin-top: 10px;

                .publicServiceCenter-title {
                    .title {
                        font-weight: 500;
                        font-size: 14px;
                        line-height: 20px;
                        color: #A1D1EF;
                    }

                    .select {
                        width: 69px;
                        height: 28px;
                        // background: pink;

                        /deep/ .el-input__wrapper {
                            background: transparent;
                            border: 1px solid rgba(39, 166, 255, 0.3);
                            border-radius: 2px;
                            padding: 0 5px;
                            font-weight: 500;
                            font-size: 14px;
                            line-height: 28px;
                            height: 28px;
                            color: #A1D1EF;
                            box-shadow: none;
                        }

                        /deep/ .el-input__inner {
                            color: #A1D1EF;
                            line-height: 28px;
                            height: 28px;
                        }

                        /deep/ .el-input__suffix-inner>:first-child {
                            margin-left: 0;
                        }

                        /deep/.ant-select-selection-item {
                            line-height: 28px;
                        }
                    }
                }

                .publicServiceCenter-content {
                    margin-top: 21px;
                    height: calc(190px - 28px - 21px);

                    .number {
                        margin-right: 12px;

                    }

                    .name {
                        font-style: normal;
                        font-weight: 500;
                        font-size: 14px;
                        line-height: 20px;
                        color: #6699C1;
                        max-width: 112px;
                    }

                    .item {
                        height: 18px;
                    }

                    .item-progress {
                        width: 290px;
                        height: 6px;

                        /deep/ .el-progress-bar__outer {
                            background: rgba(39, 166, 255, 0.2);
                            ;
                        }
                    }

                    .item:nth-of-type(1) {
                        .number {
                            width: 18px;
                            height: 18px;
                            background: conic-gradient(from 180deg at 50% 50%, rgba(255, 197, 114, 0) 0deg, rgba(255, 197, 114, 0.8) 90deg, rgba(255, 197, 114, 0) 360deg);
                            border-radius: 2px;
                            text-align: center;
                            line-height: 18px;
                            font-weight: 500;
                            font-size: 13px;
                            color: #FFFFFF;
                        }
                    }

                    .item:nth-of-type(2) {
                        .number {
                            width: 18px;
                            height: 18px;
                            background: conic-gradient(from 180deg at 50% 50%, rgba(255, 116, 76, 0) 0deg, rgba(255, 116, 76, 0.8) 90deg, rgba(255, 116, 76, 0) 360deg);
                            border-radius: 2px;
                            text-align: center;
                            line-height: 18px;
                            font-weight: 500;
                            font-size: 13px;
                            color: #FFFFFF;
                        }
                    }

                    .item:nth-of-type(3) {
                        .number {
                            width: 18px;
                            height: 18px;
                            background: conic-gradient(from 180deg at 50% 50%, rgba(106, 193, 255, 0) 0deg, rgba(106, 193, 255, 0.8) 90deg, rgba(106, 193, 255, 0) 360deg);
                            border-radius: 2px;
                            text-align: center;
                            line-height: 18px;
                            font-weight: 500;
                            font-size: 13px;
                            color: #FFFFFF;
                        }
                    }

                    .item:nth-of-type(4) {
                        .number {
                            width: 18px;
                            height: 18px;
                            border-radius: 2px;
                            background: conic-gradient(from 180deg at 50% 50%, rgba(85, 244, 239, 0) 0deg, rgba(85, 244, 239, 0.8) 90deg, rgba(85, 244, 239, 0) 360deg);
                            text-align: center;
                            line-height: 18px;
                            font-weight: 500;
                            font-size: 13px;
                            color: #FFFFFF;
                        }
                    }

                    .item:nth-of-type(5) {
                        .number {
                            width: 18px;
                            height: 18px;
                            border-radius: 2px;
                            background: conic-gradient(from 180deg at 50% 50%, rgba(39, 166, 255, 0) 0deg, rgba(39, 166, 255, 0.8) 90deg, rgba(39, 166, 255, 0) 360deg);
                            text-align: center;
                            line-height: 18px;
                            font-weight: 500;
                            font-size: 13px;
                            color: #FFFFFF;
                        }
                    }
                }
            }
        }
    }

    .content-right-top {
        width: 476px;
        height: 326px;
        position: absolute;
        top: 22px;
        right: 24px;

        background: rgba(3, 31, 58, 0.3);
        backdrop-filter: blur(7.5px);
        border-radius: 4px;
        padding: 16px;

        .energy-customer-content {
            width: 424px;
            height: 189px;
            background: red;
            margin-top: 48px;
            background: url(@/assets/images/energyDataPanorama/energy-customer-bgc.svg) no-repeat center;
            background-size: 100%;
            align-content: space-between;

            .energy-customer-content-center-content {
                position: absolute;
                width: 186px;
                height: 188px;
                left: 137px;

                span:nth-of-type(1) {
                    font-style: normal;
                    font-weight: 500;
                    font-size: 20px;
                    line-height: 28px;
                    color: #FFFFFF;
                }

                span:nth-of-type(2) {
                    font-style: normal;
                    font-weight: 600;
                    font-size: 32px;
                    line-height: 45px;
                    color: #FF744C;
                }

                span:nth-of-type(3) {
                    font-style: normal;
                    font-weight: 500;
                    font-size: 16px;
                    line-height: 22px;
                    color: #A1D1EF;
                }
            }

            .energy-customer-content-item {
                width: 194px;
                height: 68px;
                position: relative;



                // background: pink;
                .item-title {
                    font-style: normal;
                    font-weight: 400;
                    font-size: 14px;
                    line-height: 20px;
                    color: #A1D1EF;
                }

                .item-value {
                    font-style: normal;
                    font-weight: 400;
                    font-size: 20px;
                    line-height: 28px;
                    color: #FFFFFF;

                    .item-unit {
                        font-style: normal;
                        font-weight: 400;
                        font-size: 12px;
                        line-height: 17px;
                        color: #6699C1;

                    }
                }
            }

            .energy-customer-content-item:nth-child(2n) {
                padding-left: 55px;
            }

            .energy-customer-content-item:nth-child(2n-1) {
                padding-right: 55px;
            }
        }

    }

    .content-right-bottom {
        width: 476px;
        height: 312px;
        position: absolute;
        top: 364px;
        right: 24px;
        background: rgba(3, 31, 58, 0.3);
        backdrop-filter: blur(7.5px);
        border-radius: 4px;
        padding: 16px;

        .energy-produce {
            margin-top: 41px;
            width: 100%;
            height: 200px;

            .energy-produce-pie {
                width: 260px;
                height: 105px;
                background: url(@/assets/images/energyDataPanorama/pie3d-bgc.png) no-repeat center;
                background-size: 100%;
            }

            .energy-produce-detail {
                width: 430px;
                height: 64px;
                align-content: space-between;

                .energy-produce-detail-item {
                    width: 211px;
                    height: 28px;
                    background: rgba(24, 97, 183, 0.15);
                    border: 1px solid rgba(24, 97, 183, 0.5);
                    border-radius: 1px;
                    padding: 6px;

                    .dot {
                        margin-right: 8px;
                    }

                    span:nth-of-type(1) {
                        font-style: normal;
                        font-weight: 400;
                        font-size: 12px;
                        line-height: 16px;
                        color: #A1D1EF;
                    }

                    span[value] {
                        font-style: normal;
                        font-weight: 500;
                        font-size: 12px;
                        line-height: 16px;
                        text-align: right;
                        color: #FF6E11;
                    }
                }

                .energy-produce-detail-item:nth-of-type(1) {
                    .dot {
                        width: 12px;
                        height: 12px;
                        background: #FF744C;
                        border-radius: 1px;
                    }
                }

                .energy-produce-detail-item:nth-of-type(2) {
                    .dot {
                        width: 12px;
                        height: 12px;
                        background: #27A6FF;
                        border-radius: 1px;
                    }
                }

                .energy-produce-detail-item:nth-of-type(3) {
                    .dot {
                        width: 12px;
                        height: 12px;
                        background: #FFC572;
                        border-radius: 1px;
                    }
                }

                .energy-produce-detail-item:nth-of-type(4) {
                    .dot {
                        width: 12px;
                        height: 12px;
                        background: #05BD91;
                        border-radius: 1px;
                    }
                }
            }
        }
    }
}
</style>
