StoreRank.nvue
9.97 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<template>
<view style="margin-bottom: 20rpx;">
<CardNvue :title="t(cardProps.title)" style="padding-bottom: 0;" :auto-height="true">
<template #filter>
<view class="filter filter-border noBg" @tap="handleTapToChoose" v-if="!hide">
<uv-text :text="selectText || t('maintenance.common.select')" align="center" size="26rpx" color="#90949D" :lines="1"></uv-text>
<uv-icon name="arrow-right" color="#90949D" size="12" />
</view>
</template>
<template #content>
<StoreRankListNvue :data="sourceData" :indicatorKey="xAxisFields[checkIndex || 0]?.key||''"></StoreRankListNvue>
</template>
</CardNvue>
<uv-popup ref="typePopRef" round="24rpx" @maskClick="handleMaskClick">
<view class="pop_header">
<view style="width: 22px;" />
<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>
<scroll-view scroll-y="true" style="height: 240px;">
<view class="l_type">
<view class="l_type_item" v-for="(item,index) in xAxisFields" :key="item.key"
: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.name }}</text>
</view>
</view>
</scroll-view>
</uv-popup>
</view>
</template>
<script setup>
import {
getStoreRankApi
} from '@/api'
import CardNvue from './Card.nvue'
import ChartsNvue from '@/components/Charts.nvue'
import StoreRankListNvue from '../../../components/StoreRankList.nvue'
import {
computed,
onMounted,
ref,
Fragment,
nextTick
} from 'vue'
import {
getStageObj,
rpx2Px,
formatIndicatorValue
} from '@/utils'
import { t } from '@/plugins/index.js'
const props = defineProps({
cardProps: {
type: Object,
default: () => ({
title: 'PreMenu.regionalRanking', // '门店排行',
titleIcon: true,
pageSize: 5,
height: '506px'
})
}
})
const rankingRef = ref(null)
const options = ref({})
const initData = async (params) => {
options.value = params
renderChartData()
}
// 所有能排序的数据
const xAxisFields = ref([])
// 当前选中的数据
const selectIndex = ref(0)
const selectText = computed(() => {
return xAxisFields.value[selectIndex.value]?.name || ''
})
const hide = ref(false)
const hideFilter = () => {
hide.value = true
}
// 渲染数据
const sourceData = ref([])
// 渲染图表
const renderChartData = async () => {
try {
const account = await getStageObj('account')
const params = {
page: 1,
pageSize: props.cardProps.pageSize || 5,
startDate: options.value.startDate,
sortKey: checkIndex.value ? xAxisFields.value[checkIndex.value].key : '',
sortType: 'desc',
endDate: options.value.endDate,
groupId: options.value.groupId ? options.value.groupId : -1,
orgIds: account.id,
chartIds: 100,
accountIds: account.id
}
if (!params.sortKey) {
delete params.sortKey
}
const {
data
} = await getStoreRankApi(params)
const {
mall_ranking
} = data
// 设置源数据
let keyIndex = 0
let flag = false
// 根据maxVal设置排行百分比值
xAxisFields.value = mall_ranking.xaxis.data
.map((item, index) => {
const parseItem = JSON.parse(item)
// 获取第一个排行数据的索引
if (keyIndex === 0 && parseItem.key && !flag) {
keyIndex = index
flag = true
}
return {
...parseItem,
originalIndex: index
}
})
.filter(item => item.key)
sourceData.value = getSortedSeriesData(mall_ranking.series || [], keyIndex)
} catch (e) {
console.log(e);
}
}
// 获取排序后的源数据
const getSortedSeriesData = (list, keyIndex) => {
return (list
?.map(item => {
const rawValue = item.data[selectIndex.value + keyIndex]
let value = 0
// 处理特殊值(根据你的数据类型可能需要扩展)
if (typeof rawValue === 'number') {
value = rawValue
} else if (!isNaN(parseFloat(rawValue))) {
value = parseFloat(rawValue)
}
return {
name: item.data[1], // 获取门店名称
value: value
}
}) || []).sort((a, b) => {
return b.value - a.value
})
}
/**************************** pop选择相关 *********************************/
const typePopRef = ref(null)
const checkIndex = ref('')
const handleTapToChoose = () => {
uni.hideTabBar()
checkIndex.value = selectIndex.value || 0
typePopRef.value?.open('bottom')
}
const handleMaskClick = () => {
uni.showTabBar()
}
const handleCloseTypeSelect = () => {
handleMaskClick()
typePopRef.value?.close()
}
const handleChangeCheckType = (index) => {
checkIndex.value = index
handleConfirmSelectType()
}
const handleConfirmSelectType = () => {
handleMaskClick()
selectIndex.value = checkIndex.value
typePopRef.value?.close()
renderChartData()
// renderRankingCharts(getSortedSeriesData())
}
/**************************** 图表渲染相关 *********************************/
const renderRankingCharts = (val) => {
const option = rightCenterBarConfig(val, '', 15)
rankingRef.value?.initCharts(option)
}
function rightCenterBarConfig(val) {
const xData = val.map(item => item.name)
const yData = val.map(item => item.value)
const yDataCl = JSON.parse(JSON.stringify(yData)).sort((a, b) => (b - a))
const clLength = yDataCl.length
return {
tooltip: {
show: true,
trigger: "axis",
textStyle: {},
confine: true,
triggerOn: 'click'
},
grid: {
bottom: 0,
left: 0,
right: 0,
top: 16
},
xAxis: {
type: "value",
splitLine: {
show: false,
},
axisTick: {
show: false
},
axisLine: {
show: false
},
axisLabel: {
show: false,
}
},
yAxis: [{
type: "category",
data: xData,
axisTick: {
show: false
},
axisPointer: {
type: "shadow",
},
axisLine: {
show: false,
lineStyle: {
color: "#BDD8FB",
fontSize: 12
}
},
axisLabel: {
fontSize: 12,
textStyle: {
color: "#202328",
align: "left",
verticalAlign: 'top',
padding: [-30, 0, 0, 10],
// padding: [rpx2Px(-64), 0, 0, rpx2Px(20)],
fontFamily: 'DingTalk_JinBuTi'
},
// #ifdef APP-NVUE
formatter: `function(value, index) {
const lIndex = ${clLength}-index
let rankDisplay = ''
if(lIndex === 1){
rankDisplay = "{icon1|}"
}else if(lIndex === 2){
rankDisplay = "{icon2|}"
}else if(lIndex === 3){
rankDisplay = "{icon3|}"
}else {
rankDisplay = '{indexs|' + lIndex + '}'
}
let displayValue = value
if(value.length > 20){
displayValue = value.slice(0,20) + '...'
}
return \`\${rankDisplay} \${displayValue}\`;
}`,
// #endif
// #ifndef APP-NVUE
formatter: function(value, index) {
const lIndex = clLength - index
let rankDisplay = ""
if (lIndex === 1) {
rankDisplay = "{icon1|}"
} else if (lIndex === 2) {
rankDisplay = "{icon2|}"
} else if (lIndex === 3) {
rankDisplay = "{icon3|}"
} else {
rankDisplay = `{indexs|${lIndex}}`
}
let displayValue = value
if (value.length > 20) {
displayValue = value.slice(0, 20) + '...'
}
return `${rankDisplay} ${displayValue}`
},
// #endif
rich: {
icon1: {
height: 16,
align: 'left',
backgroundColor: {
image: rank1
}
},
icon2: {
height: 16,
align: 'left',
backgroundColor: {
image: rank2
}
},
icon3: {
height: 16,
align: 'left',
backgroundColor: {
image: rank3
}
},
indexs: {
width: 16,
align: 'center',
fontSize: 12,
}
}
}
}, {
type: 'category',
inverse: true,
axisTick: 'none',
axisLine: 'none',
show: true,
offset: -7,
axisLabel: {
textStyle: {
color: '#202328',
fontSize: 13,
align: 'right'
},
verticalAlign: 'bottom',
padding: [20, 2, 18, 0],
},
data: yDataCl,
}],
series: [{
type: "bar",
stack: "all",
data: yData,
barWidth: 14,
itemStyle: {
color: "#4277F7",
borderRadius: [3, 3, 3, 3],
},
showBackground: true,
backgroundStyle: {
color: '#F7F8FB',
borderRadius: [3, 3, 3, 3],
}
}]
};
};
defineExpose({
initData,
hideFilter
})
</script>
<style lang="scss" scoped>
@import '@/styles/normal.scss';
::v-deep(.uv-safe-area-inset-bottom){
padding-bottom: 0!important;
}
.filter-border{
max-width: 200rpx;
}
.noBg{
background-color: transparent !important;
}
</style>