AccountDistribution.vue 6.62 KB
<template>
    <a-row :gutter="16" class="ml-10">
        <a-col :span="8" style="text-align: center;">
            <a-statistic class="stat" title="今日活跃车商" :value="accountStat?.activeCount??0" :precision="0"></a-statistic>
        </a-col>
        <a-col :span="8" style="text-align: center;">
            <a-statistic class="stat" title="本周新增" :value="accountStat?.newCount??0" :precision="0"></a-statistic>
        </a-col>
        <a-col :span="8" style="text-align: center;">
            <a-statistic class="stat" title="本周首单" :value="accountStat?.dealCount??0" :precision="0"></a-statistic>
        </a-col>
    </a-row>
    <a-row :gutter="16">
        <a-col :span="16">
            <v-chart :option="option" style="height: 400px" autoresize theme="walden"/>
        </a-col>
        <a-col :span="8">
            <a-list item-layout="horizontal" :data-source="provinceAccounts" size="small" :bordered="false" class="mt-16">
                <template #renderItem="{ item,index }">
                    <a-list-item>
                        <template #actions>
                            {{ provincePercent(item.value).toFixed(0) }}%
                            <h3 style="width: 40px">{{ item.value }}</h3>
                        </template>
                        <a-list-item-meta>
                            <template #title>
                                {{ item.name }}
                            </template>
                            <template #description>

                            </template>
                            <template #avatar>
                                <a-avatar :style="{ backgroundColor: colors[index%13]  }" shape="square" :size="14">
                                </a-avatar>
                            </template>
                        </a-list-item-meta>
                    </a-list-item>
                </template>
            </a-list>
        </a-col>
    </a-row>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
import chinaGeo from '@/assets/china.json';
import * as echarts from 'echarts/core';
import {AccountController} from "@/api/AccountController";
import {getAreaNameByCode} from "@/common/chinaarea";
import {AccountTotalStat} from "lib/src/entity/account/domain/AccountTotalStat";

@Component({
    components: {}
})
export default class AccountDistribution extends Vue {

    colors = ['#5B8FF9', '#4CD8A0', '#5D7092', '#F6BD16', '#E8684A', '#52C2EB', '#9270CA', '#FF9D4D', '#269A99', '#FF99C3', '#4CBF82', '#33ADFF', '#CD92FE'];

    accountStat: AccountTotalStat = null;

    option = {
        tooltip: {
            trigger: 'item',
            formatter: function (params) {
                return `${params.name}<br/>用户数量:${params.value.toLocaleString() !== 'NaN' ? params.value.toLocaleString() : '0'} 人`;
            }
        },
        // legend: {show: true, data: ['广东省']},
        legend: {
            type: 'scroll', // 支持滚动(避免图例过多溢出)
            right: 10, // 靠右显示
            top: 'center', // 垂直居中
            orient: 'vertical', // 垂直排列
            data: [], // 图例名称(与userData对应)
            // textStyle: {color: '#333'}, // 图例文字颜色
        },
        // 图例(颜色对应数值范围)
        // visualMap: {
        //     type: 'piecewise', // 分段型视觉映射
        //     pieces: [
        //         {max: 1000, label: '1000以下', color: '#e0f2f1'},
        //         {min: 1000, max: 10000, label: '1000-1万', color: '#80cbc4'},
        //         {min: 10000, label: '1万以上', color: '#00897b'}
        //     ],
        //     left: 'left',
        //     bottom: 'bottom',
        //     textStyle: {fontSize: 12}
        // },
        // geo: {
        //     map: "china",
        // },
        series: [
            {
                type: 'map',
                mapType: 'china', // 使用中国地图
                // roam: false, // 允许缩放和平移
                // label: {
                //     show: false, // 显示省份名称
                //     fontSize: 12
                // },

                data: [], // 绑定用户数量数据
                emphasis: {
                    // 高亮样式(鼠标悬停时)
                    itemStyle: {areaColor: '#ffcc80', borderWidth: 2},
                    label: {fontSize: 14}
                }
            }
        ]
    };

    provinceAccounts = [];

    created() {
        AccountController.getDashboardAccountStat(this.axios).then((res) => {
            this.accountStat = res.data;
        });
    }

    mounted() {
        // 使用 registerMap 注册的地图名称。
        echarts.registerMap('china', chinaGeo);
        AccountController.getAccountCountGroupByProvince(this.axios).then(res => {
            const provinceData = res.data.map((item, index) => {
                return {
                    name: getAreaNameByCode(item.provinceCode), value: item.accountCount, label: {
                        normal: {
                            show: index < 5, color: '#999', fontSize: 12,
                            textStyle: {
                                borderColor: this.colors[index], // 边框颜色(与悬停背景色呼应)
                                borderWidth: 2,
                                padding: [4, 10],
                                backgroundColor: '#ffffff', // 标签背景色
                                borderRadius: 7
                            },
                            formatter: (params) => {
                                return params.value ? params.value.toLocaleString() : '';
                            }
                        }
                    }, itemStyle: {
                        normal: {
                            areaColor: this.colors[index]
                        }
                    }
                };
            });
            this.provinceAccounts = provinceData;
            const formattedData = provinceData.map(item => item.name);
            console.log(provinceData);
            this.option.legend.data = formattedData;
            this.option.series[0].data = provinceData;
        });
    }

    provincePercent(count: number): number {
        let total = 0;
        this.provinceAccounts.forEach(item => {
            total = total + item.value;
        });
        if (total > 0) {
            return (count / total) * 100;
        } else {
            return 0;
        }
    }
}
</script>

<style lang="less" scoped>
.stat {
    border-radius: 8px;
    background: linear-gradient(129.4deg, #F7FAFF 0%, #EBF3FF 36.53%, #F7FAFF 100%);
    padding: 12px 16px 12px 16px;
}
</style>