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