|
| 1 | +<!-- 客户城市分布 --> |
| 2 | +<template> |
| 3 | + <!-- Echarts图 --> |
| 4 | + <el-card shadow="never"> |
| 5 | + <el-row :gutter="20"> |
| 6 | + <el-col :span="12"> |
| 7 | + <el-skeleton :loading="loading" animated> |
| 8 | + <Echart :height="500" :options="echartsOption" /> |
| 9 | + </el-skeleton> |
| 10 | + </el-col> |
| 11 | + <el-col :span="12"> |
| 12 | + <el-skeleton :loading="loading" animated> |
| 13 | + <Echart :height="500" :options="echartsOption2" /> |
| 14 | + </el-skeleton> |
| 15 | + </el-col> |
| 16 | + </el-row> |
| 17 | + </el-card> |
| 18 | +</template> |
| 19 | +<script lang="ts" setup> |
| 20 | +import { EChartsOption } from 'echarts' |
| 21 | +import china from '@/assets/map/json/china.json' |
| 22 | +import echarts from '@/plugins/echarts' |
| 23 | +import { |
| 24 | + CrmStatisticCustomerAreaRespVO, |
| 25 | + StatisticsCustomerApi |
| 26 | +} from '@/api/crm/statistics/customer' |
| 27 | +
|
| 28 | +defineOptions({ name: 'CustomerAddress' }) |
| 29 | +const props = defineProps<{ queryParams: any }>() // 搜索参数 |
| 30 | +
|
| 31 | +// 注册地图 |
| 32 | +echarts?.registerMap('china', china as any) |
| 33 | +
|
| 34 | +const loading = ref(false) // 加载中 |
| 35 | +const areaStatisticsList = ref<CrmStatisticCustomerAreaRespVO[]>([]) // 列表的数据 |
| 36 | +
|
| 37 | +/** 地图配置 */ |
| 38 | +const echartsOption = reactive<EChartsOption>({ |
| 39 | + title: { |
| 40 | + text: '全部客户', |
| 41 | + left: 'center' |
| 42 | + }, |
| 43 | + tooltip: { |
| 44 | + trigger: 'item', |
| 45 | + showDelay: 0, |
| 46 | + transitionDuration: 0.2 |
| 47 | + }, |
| 48 | + visualMap: { |
| 49 | + text: ['高', '低'], |
| 50 | + realtime: false, |
| 51 | + calculable: true, |
| 52 | + top: 'middle', |
| 53 | + inRange: { |
| 54 | + color: ['#fff', '#3b82f6'] |
| 55 | + } |
| 56 | + }, |
| 57 | + series: [ |
| 58 | + { |
| 59 | + name: '客户地域分布', |
| 60 | + type: 'map', |
| 61 | + map: 'china', |
| 62 | + roam: false, |
| 63 | + selectedMode: false, |
| 64 | + data: [] |
| 65 | + } |
| 66 | + ] |
| 67 | +}) as EChartsOption |
| 68 | +
|
| 69 | +/** 地图配置 */ |
| 70 | +const echartsOption2 = reactive<EChartsOption>({ |
| 71 | + title: { |
| 72 | + text: '成交客户', |
| 73 | + left: 'center' |
| 74 | + }, |
| 75 | + tooltip: { |
| 76 | + trigger: 'item', |
| 77 | + showDelay: 0, |
| 78 | + transitionDuration: 0.2 |
| 79 | + }, |
| 80 | + visualMap: { |
| 81 | + text: ['高', '低'], |
| 82 | + realtime: false, |
| 83 | + calculable: true, |
| 84 | + top: 'middle', |
| 85 | + inRange: { |
| 86 | + color: ['#fff', '#3b82f6'] |
| 87 | + } |
| 88 | + }, |
| 89 | + series: [ |
| 90 | + { |
| 91 | + name: '客户地域分布', |
| 92 | + type: 'map', |
| 93 | + map: 'china', |
| 94 | + roam: false, |
| 95 | + selectedMode: false, |
| 96 | + data: [] |
| 97 | + } |
| 98 | + ] |
| 99 | +}) as EChartsOption |
| 100 | +
|
| 101 | +/** 获取统计数据 */ |
| 102 | +const loadData = async () => { |
| 103 | + // 1. 加载统计数据 |
| 104 | + loading.value = true |
| 105 | + const areaList = await StatisticsCustomerApi.getCustomerArea(props.queryParams) |
| 106 | + areaStatisticsList.value = areaList.map((item: CrmStatisticCustomerAreaRespVO) => { |
| 107 | + return { |
| 108 | + ...item, |
| 109 | + areaName: item.areaName |
| 110 | + .replace('维吾尔自治区', '') |
| 111 | + .replace('壮族自治区', '') |
| 112 | + .replace('回族自治区', '') |
| 113 | + .replace('自治区', '') |
| 114 | + .replace('省', '') |
| 115 | + } |
| 116 | + }) |
| 117 | + builderLeftMap() |
| 118 | + builderRightMap() |
| 119 | + loading.value = false |
| 120 | +} |
| 121 | +defineExpose({ loadData }) |
| 122 | +
|
| 123 | +const builderLeftMap = () => { |
| 124 | + let min = 0 |
| 125 | + let max = 0 |
| 126 | + echartsOption.series![0].data = areaStatisticsList.value.map((item) => { |
| 127 | + min = Math.min(min, item.customerCount || 0) |
| 128 | + max = Math.max(max, item.customerCount || 0) |
| 129 | + return { ...item, name: item.areaName, value: item.customerCount || 0 } |
| 130 | + }) |
| 131 | + echartsOption.visualMap!['min'] = min |
| 132 | + echartsOption.visualMap!['max'] = max |
| 133 | +} |
| 134 | +
|
| 135 | +const builderRightMap = () => { |
| 136 | + let min = 0 |
| 137 | + let max = 0 |
| 138 | + echartsOption2.series![0].data = areaStatisticsList.value.map((item) => { |
| 139 | + min = Math.min(min, item.dealCount || 0) |
| 140 | + max = Math.max(max, item.dealCount || 0) |
| 141 | + return { ...item, name: item.areaName, value: item.dealCount || 0 } |
| 142 | + }) |
| 143 | + echartsOption2.visualMap!['min'] = min |
| 144 | + echartsOption2.visualMap!['max'] = max |
| 145 | +} |
| 146 | +/** 初始化 */ |
| 147 | +onMounted(() => { |
| 148 | + loadData() |
| 149 | +}) |
| 150 | +</script> |
0 commit comments