HeatMap.nvue
4.81 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<template>
<view style="margin-bottom: 20rpx;">
<CardNvue :title="t('PreMallChart.mall_period_passenger_flow_heat.table')">
<template #filter>
<view class="filter filter-border transparent-bg" @tap="handleTapToChoose">
<text class="filter_text">{{ selectText || t('maintenance.common.select') }}</text>
<uv-icon name="arrow-right" color="#90949D" size="24rpx" />
</view>
</template>
<template #content>
<ChartsNvue ref="chartsRef" />
</template>
</CardNvue>
<uv-popup ref="typePopRef">
<view class="pop_header">
<view style="width: 22px;"></view>
<text class="pop_header_text">{{ t('app.title.kpiSelect') }}</text>
<uv-icon name="close" size="22" class="pop_header_icon" @tap="handleCloseTypeSelect"></uv-icon>
</view>
<view class="l_type">
<view class="l_type_item" v-for="(item,index) in getIndicator" :key="item.indexKey"
:class="{'l_type_item_active':index === checkIndex}" @tap="handleChangeCheckType(index)">
<text class="l_type_item_text"
:class="{'l_type_item_active_text':index === checkIndex}">{{ item.indexName }}</text>
</view>
</view>
</uv-popup>
</view>
</template>
<script setup>
import {
getThermodynamicMallApi
} from '@/api'
import CardNvue from './Card.nvue'
import ChartsNvue from '@/components/Charts.nvue'
import {
computed,
onMounted,
ref
} from 'vue'
import {
t
} from '@/plugins/index.js'
/**************************** pop选择相关 *********************************/
const typePopRef = ref(null)
const checkIndex = ref('')
const selectIndex = ref(0)
const selectText = computed(() => {
return getIndicator.value?.[selectIndex.value]?.indexName
})
const handleTapToChoose = () => {
checkIndex.value = selectIndex.value || 0
typePopRef.value?.open('bottom')
}
const handleCloseTypeSelect = () => {
typePopRef.value?.close()
}
const handleChangeCheckType = (index) => {
checkIndex.value = index
handleConfirmSelectType()
}
const handleConfirmSelectType = () => {
selectIndex.value = checkIndex.value
typePopRef.value?.close()
getTrendChartData()
}
const selfIndicators = ['PassByCount', 'EnterCount', 'CustomerMantime', 'CustomerNum']
const getIndicator = computed(() => {
return props.indicators.filter(item => selfIndicators.includes(item.indexKey))
})
const props = defineProps({
indicators: {
type: Array,
default: () => []
}
})
const chartsRef = ref(null)
const options = ref({})
const initData = (params) => {
options.value = params
getTrendChartData()
}
defineExpose({
initData
})
const getTrendChartData = async () => {
try {
// 参数设置位置:
const params = {
startDate: options.value.startDate,
endDate: options.value.endDate,
chartIds: 267,
orgIds: options.value.storeId,
index: getIndicator.value?.[selectIndex.value]?.indexKey || '',
}
const {
data
} = await getThermodynamicMallApi(params)
const {
TimeThermodynamic
} = data.body
renderCharts(TimeThermodynamic)
} catch (e) {
console.log(e);
}
}
const renderCharts = (val = {
series: [],
title: '',
xaxis: {
data: []
}
}) => {
// prettier-ignore
const days = val.series.map(el=> el.name) || [];
const daysDataMap = {}
const dataLength = val.xaxis.data.length
for (let item of val.series) {
daysDataMap[item.name] = item.data
}
const dataListByDays = days.map(day => {
return daysDataMap[day] || Array(dataLength).fill(0)
}) || []
const seriesVal = []
dataListByDays.map((_, yIndex) => {
_?.map((item, dataIndex) => {
seriesVal.push([parseInt(yIndex), dataIndex, item || "-"])
})
})
let max = 0
const data = seriesVal.map(function(item) {
max = Math.max(item[2] === '-' ? 0 : item[2], max)
return [item[1], item[0], item[2] || '-'];
});
const option = {
tooltip: {
position: 'top',
confine:true,
triggerOn:'click'
},
grid: {
top: 10,
bottom: 20,
right: 0,
left: 34,
},
xAxis: {
type: 'category',
data: val.xaxis.data,
splitArea: {
show: true
},
axisTick: {
show: false
}
},
yAxis: {
type: 'category',
data: days,
splitArea: {
show: true,
},
axisTick: {
show: false
}
},
visualMap: {
min: 0,
max: max || 1,
show:false,
calculable: true,
type: 'continuous',
orient: 'horizontal',
right: 0,
top: '0',
inRange: {
color: ["#99ddff", "#0022FF"]
}
},
series: [{
name: t('echarts.averageThermal'),
type: 'heatmap',
data: data,
label: {
show: false
},
// emphasis: {
// itemStyle: {
// shadowBlur: 10,
// shadowColor: 'rgba(0, 0, 0, 0.5)'
// }
// }
}]
};
chartsRef.value?.initCharts(option)
}
</script>
<style lang="scss">
@import '@/styles/normal.scss'
</style>