5e0c6e5a
“wangming”
feat: 完善会员画像功能,优化...
|
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
<div class="stat-value">¥{{ formatMoney(statistics.totalTransferAmount) }}</div>
</div>
</div>
<div class="stat-card neon-purple">
<div class="stat-icon-circle">
<i class="el-icon-trophy"></i>
</div>
<div class="stat-content">
<div class="stat-title">退卡金额最大的人</div>
<div class="stat-body">
<div class="highlight text-ellipsis-2">
{{ (statistics.maxAmountPerson && (statistics.maxAmountPerson.MemberName ||
statistics.maxAmountPerson.memberName)) || '无' }}
<span class="value-inline">¥{{ formatMoney((statistics.maxAmountPerson &&
(statistics.maxAmountPerson.TotalRefundAmount || statistics.maxAmountPerson.totalRefundAmount)) || 0)
}}</span>
</div>
</div>
</div>
</div>
<div class="stat-card neon-cyan" style="display: none;">
<div class="stat-icon-circle">
<i class="el-icon-user"></i>
</div>
<div class="stat-content">
<div class="stat-title">退卡次数最多的人</div>
<div class="stat-body">
<div class="highlight text-ellipsis-2">
{{ (statistics.maxCountPerson && (statistics.maxCountPerson.MemberName ||
statistics.maxCountPerson.memberName)) || '无' }}
<span class="value-inline">{{ (statistics.maxCountPerson && (statistics.maxCountPerson.RefundCount ||
statistics.maxCountPerson.refundCount)) || 0 }} 次</span>
</div>
</div>
</div>
</div>
<!-- 退卡金额与实际退款差距清单 -->
<div class="stat-card gap-refund-card" v-if="gapRefundList && gapRefundList.length > 0">
<div class="gap-refund-header">
<div class="stat-icon-circle" style="background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);">
<i class="el-icon-warning"></i>
</div>
<div class="stat-content">
<div class="stat-title">退卡金额与实际退款差距(≥1元)</div>
</div>
</div>
<div class="gap-refund-list-wrapper">
<div class="gap-refund-list">
<div v-for="(item, index) in gapRefundList" :key="index" class="gap-refund-item">
<div class="gap-refund-member">{{ item.MemberName || item.memberName || '—' }}<span
class="gap-amount">差距:¥{{
formatMoney(item.GapAmount || item.gapAmount || 0) }}</span></div>
<div class="gap-refund-details">
<div class="gap-detail-row">
<span class="gap-label">退卡金额:</span>
<span class="gap-value">¥{{ formatMoney(item.RefundAmount || item.refundAmount || 0) }}</span>
</div>
<div class="gap-detail-row">
<span class="gap-label">实际退款:</span>
<span class="gap-value">¥{{ formatMoney(item.ActualRefundAmount || item.actualRefundAmount ||
0) }}</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import request from '@/utils/request'
import dayjs from 'dayjs'
import * as echarts from 'echarts'
import { kpiDrillMixin } from './mixins'
export default {
name: 'RefundAnalysis',
mixins: [kpiDrillMixin],
props: {
filters: {
type: Object,
default: () => ({ startTime: null, endTime: null, storeIds: [], month: null })
},
storeOptions: { type: Array, default: () => [] }
},
data() {
return {
loading: false,
list: [],
displayList: [],
pagination: { pageIndex: 1, pageSize: 10, total: 0 },
statistics: {
totalRefundAmount: 0,
totalActualRefundAmount: 0,
totalTransferAmount: 0,
maxAmountPerson: null,
maxCountPerson: null
},
gapRefundList: [],
selectedStoreName: '', // 当前选中的门店名称
selectedStoreId: '', // 当前选中的门店ID
storeDistribution: [],
columns: [
{ prop: 'tksj', label: '退卡时间', minWidth: 160 },
{ prop: 'mdmc', label: '门店', minWidth: 120 },
{ prop: 'hymc', label: '会员', minWidth: 120 },
{ prop: 'gklx', label: '顾客类型', minWidth: 100 },
{ prop: 'tkje', label: '退款金额', width: 110, type: 'money' },
{ prop: 'actualRefundAmount', label: '实际退款', width: 110, type: 'money' },
{ prop: 'tkyy', label: '退款原因', minWidth: 140 }
],
chart: null
}
},
watch: {
filters: {
deep: true,
handler() {
this.resetAndFetch()
}
}
},
mounted() {
this.fetchData()
this.fetchStatistics()
},
beforeDestroy() {
if (this.chart) this.chart.dispose()
},
methods: {
resetAndFetch() {
this.pagination = { ...this.pagination, pageIndex: 1 }
this.fetchData()
this.fetchStatistics()
},
handleSizeChange(size) {
this.pagination.pageSize = size
this.pagination.pageIndex = 1
this.fetchData()
},
handleCurrentChange(page) {
this.pagination.pageIndex = page
this.fetchData()
},
async fetchStatistics() {
try {
const range = this.buildDateRange()
if (!range) {
console.warn('No date range available for refund statistics')
return
}
const url = '/api/Extend/LqReport/get-refund-drill-statistics'
const data = {
startTime: dayjs(range.start).format('YYYY-MM-DD HH:mm:ss'),
endTime: dayjs(range.end).format('YYYY-MM-DD HH:mm:ss'),
storeIds: this.filters.storeIds || []
}
const res = await request({ url, method: 'POST', data })
console.log('Refund statistics response:', res) // 调试日志
if (res && res.data) {
// 兼容不同的响应格式
let stats = null
if (res.data.Success && res.data.Data) {
stats = res.data.Data
} else if (res.data.data) {
stats = res.data.data
} else if (res.data.Data) {
stats = res.data.Data
} else {
stats = res.data
}
console.log('Parsed stats:', stats) // 调试日志
if (stats) {
// 解析统计数据
this.statistics = {
totalRefundAmount: Number(stats.TotalRefundAmount || stats.totalRefundAmount || 0),
totalActualRefundAmount: Number(stats.TotalActualRefundAmount || stats.totalActualRefundAmount || 0),
totalTransferAmount: Number(stats.TotalTransferAmount || stats.totalTransferAmount || 0),
maxAmountPerson: stats.MaxAmountPerson || stats.maxAmountPerson || null,
maxCountPerson: stats.MaxCountPerson || stats.maxCountPerson || null
}
// 解析差距清单
const rawGapList = stats.GapRefundList || stats.gapRefundList || []
this.gapRefundList = rawGapList.map(item => ({
RefundId: item.RefundId || item.refundId || '',
MemberId: item.MemberId || item.memberId || '',
MemberName: item.MemberName || item.memberName || '—',
RefundAmount: Number(item.RefundAmount || item.refundAmount || 0),
ActualRefundAmount: Number(item.ActualRefundAmount || item.actualRefundAmount || 0),
GapAmount: Number(item.GapAmount || item.gapAmount || 0),
RefundTime: item.RefundTime || item.refundTime || null,
RefundReason: item.RefundReason || item.refundReason || '—'
}))
// 处理门店分布数据,确保门店名称正确
const rawStoreDist = stats.StoreDistribution || stats.storeDistribution || []
console.log('Raw store distribution:', rawStoreDist) // 调试日志
this.storeDistribution = rawStoreDist.map(item => {
const storeId = item.StoreId || item.storeId || item.StoreId
const storeName = this.getStoreName(storeId) || item.StoreName || item.storeName || '未知门店'
const refundAmount = Number(item.RefundAmount || item.refundAmount || 0)
return {
StoreId: storeId,
StoreName: storeName,
RefundAmount: refundAmount,
RefundCount: Number(item.RefundCount || item.refundCount || 0)
}
}).filter(item => item.StoreId) // 过滤掉没有门店ID的数据
console.log('Processed statistics:', this.statistics)
console.log('Processed store distribution:', this.storeDistribution)
// 确保在下一个tick渲染图表
this.$nextTick(() => {
setTimeout(() => {
this.renderStoreDistributionChart()
}, 100)
})
} else {
console.warn('No stats data found in response')
}
} else {
console.warn('No response data')
}
} catch (error) {
console.error('Refund statistics load error:', error)
this.$message.error('加载统计数据失败: ' + (error.message || '未知错误'))
}
},
async fetchData() {
this.loading = true
try {
const range = this.buildDateRange()
const storeId = this.getStoreId()
const url = '/api/Extend/LqHytkHytk'
const data = {
currentPage: this.pagination.pageIndex,
pageSize: this.pagination.pageSize
}
if (range) {
data.tksj = `${range.startTs},${range.endTs}`
}
// 优先使用选中的门店ID,否则使用filters中的门店ID
if (this.selectedStoreId) {
data.md = this.selectedStoreId
} else if (storeId) {
data.md = storeId
}
const res = await request({ url, method: 'GET', data })
await this.handleResponse(res)
} catch (error) {
console.error('Refund analysis load error:', error)
this.$message.error(error.message || '加载数据失败')
this.list = []
this.displayList = []
} finally {
this.loading = false
}
},
async handleResponse(res) {
let list = []
let pagination = this.pagination
if (res && res.data) {
if (res.data.list && res.data.pagination) {
list = res.data.list
pagination = {
pageIndex: res.data.pagination.pageIndex || res.data.pagination.pageNumber || 1,
pageSize: res.data.pagination.pageSize || this.pagination.pageSize,
total: res.data.pagination.total || res.data.pagination.totalCount || 0
}
} else if (Array.isArray(res.data.list)) {
list = res.data.list
} else if (Array.isArray(res.data)) {
list = res.data
}
}
list = list.map(i => {
// 处理门店名称
const storeId = i.md || i.Md || i.storeId || i.StoreId
const storeName = this.getStoreName(storeId) || i.mdmc || i.Mdmc || '—'
// 处理退卡时间
let tksj = ''
if (i.tksj) {
if (typeof i.tksj === 'string') {
tksj = dayjs(i.tksj).format('YYYY-MM-DD HH:mm:ss')
} else if (typeof i.tksj === 'number') {
tksj = dayjs(i.tksj).format('YYYY-MM-DD HH:mm:ss')
} else {
tksj = dayjs(i.tksj).format('YYYY-MM-DD HH:mm:ss')
}
} else if (i.Tksj) {
if (typeof i.Tksj === 'string') {
tksj = dayjs(i.Tksj).format('YYYY-MM-DD HH:mm:ss')
} else if (typeof i.Tksj === 'number') {
tksj = dayjs(i.Tksj).format('YYYY-MM-DD HH:mm:ss')
} else {
tksj = dayjs(i.Tksj).format('YYYY-MM-DD HH:mm:ss')
}
}
return {
tksj: tksj || '—',
mdmc: storeName,
hymc: i.hymc || i.Hymc || '—',
gklx: i.gklx || i.Gklx || '—',
tkje: Number(i.tkje || i.Tkje || 0),
actualRefundAmount: Number(i.actualRefundAmount || i.ActualRefundAmount || i.F_ActualRefundAmount || 0),
tkyy: i.tkyy || i.Tkyy || '—'
}
})
this.list = list
this.displayList = list
this.pagination = pagination
},
renderStoreDistributionChart() {
const chartEl = this.$refs.storeDistributionChart
if (!chartEl) {
console.warn('storeDistributionChart ref not found, retrying...')
this.$nextTick(() => {
setTimeout(() => this.renderStoreDistributionChart(), 200)
})
return
}
if (this.chart) {
this.chart.dispose()
this.chart = null
}
const chart = echarts.init(chartEl)
if (!chart) {
console.error('Failed to initialize chart')
return
}
if (!this.storeDistribution || this.storeDistribution.length === 0) {
chart.setOption({
title: {
text: '暂无数据',
left: 'center',
top: 'middle',
textStyle: { color: '#909399', fontSize: 14 }
},
grid: { left: 0, right: 0, top: 0, bottom: 0 }
})
this.chart = chart
return
}
const stores = this.storeDistribution.map(s => s.StoreName || '未知门店')
const amounts = this.storeDistribution.map(s => Number(s.RefundAmount || 0))
console.log('Chart data - stores:', stores, 'amounts:', amounts) // 调试日志
const option = {
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' },
formatter: (params) => {
const param = Array.isArray(params) ? params[0] : params
return `${param.name}<br/>退卡金额: ¥${this.formatMoney(param.value)}<br/>(不包含转卡)`
}
},
|
5e0c6e5a
“wangming”
feat: 完善会员画像功能,优化...
|
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
xAxis: {
type: 'category',
data: stores,
axisLabel: {
fontSize: 11,
interval: 0,
rotate: stores.length > 10 ? 45 : 0
}
},
yAxis: {
type: 'value',
name: '金额',
axisLabel: {
formatter: (value) => {
if (value >= 10000) return (value / 10000).toFixed(1) + '万'
return value.toFixed(0)
}
}
},
series: [{
name: '退卡金额',
type: 'bar',
data: amounts,
itemStyle: {
color: (params) => {
// 如果当前门店被选中,高亮显示
const storeName = stores[params.dataIndex]
return storeName === this.selectedStoreName ? '#409EFF' : '#F56C6C'
},
borderRadius: [4, 4, 0, 0]
},
label: {
show: true,
position: 'top',
formatter: (params) => {
const value = params.value
if (value >= 10000) return (value / 10000).toFixed(1) + '万'
return value.toFixed(0)
},
fontSize: 10
},
barWidth: stores.length > 20 ? '40%' : '60%',
// 添加点击事件
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(64, 158, 255, 0.5)'
}
}
}]
}
chart.setOption(option)
this.chart = chart
// 添加点击事件监听
chart.off('click') // 先移除之前的监听,避免重复绑定
chart.on('click', (params) => {
if (params.componentType === 'series' && params.seriesType === 'bar') {
const clickedStoreName = stores[params.dataIndex]
this.filterByStore(clickedStoreName)
}
})
// 监听窗口大小变化
const resizeHandler = () => {
if (this.chart) {
this.chart.resize()
}
}
window.removeEventListener('resize', resizeHandler) // 先移除,避免重复绑定
window.addEventListener('resize', resizeHandler)
},
getStoreName(storeId) {
if (!storeId || !this.storeOptions || this.storeOptions.length === 0) return null
const store = this.storeOptions.find(s => s.id === storeId || s.F_Id === storeId)
return store ? (store.fullName || store.dm || store.F_FullName || store.FullName) : null
},
filterByStore(storeName) {
// 如果点击的是已选中的门店,则取消筛选
if (this.selectedStoreName === storeName) {
this.showAllStores()
return
}
// 从storeDistribution中找到对应的门店ID
const storeInfo = this.storeDistribution.find(s => s.StoreName === storeName)
if (!storeInfo || !storeInfo.StoreId) {
this.$message.warning('未找到门店信息')
return
}
this.selectedStoreName = storeName
this.selectedStoreId = storeInfo.StoreId
// 重置分页到第一页
this.pagination.pageIndex = 1
// 重新获取数据(通过接口筛选)
this.fetchData()
// 重新渲染图表,高亮选中的门店
this.$nextTick(() => {
this.renderStoreDistributionChart()
})
},
showAllStores() {
this.selectedStoreName = ''
this.selectedStoreId = ''
// 重置分页到第一页
this.pagination.pageIndex = 1
// 重新获取数据(获取全部数据)
this.fetchData()
// 重新渲染图表,恢复所有门店的颜色
this.$nextTick(() => {
this.renderStoreDistributionChart()
})
}
}
}
</script>
<style lang="scss" scoped>
@import './common-styles.scss';
.refund-wrapper {
width: 100%;
overflow: hidden;
padding: 0;
.refund-layout {
display: flex;
align-items: stretch;
justify-content: space-between;
gap: 16px;
width: 100%;
}
.refund-left {
flex: 0 0 75%;
max-width: 75%;
display: flex;
flex-direction: column;
gap: 12px;
min-width: 0;
}
.refund-right {
flex: 0 0 25%;
max-width: 23.5%;
display: flex;
flex-direction: column;
gap: 12px;
min-width: 0;
}
// 复用公共样式中的 chart-card 和 table-card
.chart-card {
background: #fff;
border: 1px solid #ebeef5;
border-radius: 10px;
padding: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
flex-shrink: 0;
.chart-title {
font-size: 13px;
color: #606266;
margin-bottom: 6px;
display: flex;
align-items: center;
gap: 6px;
i {
color: #409EFF;
}
}
.chart-mini {
height: 220px;
width: 100%;
min-height: 220px;
}
}
.table-card {
background: #fff;
border: 1px solid #ebeef5;
border-radius: 10px;
padding: 10px 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
flex: 1;
|