liu
8 天以前 600fe725775e28af1f86f7f7f1e2521f494252b1
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
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
 
import { onMounted, ref } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
import { Card, Col, Row, Spin, Statistic } from 'ant-design-vue';
 
import { getManagementCockpitTrace } from '#/api/mes/management-cockpit';
 
import { getBarChartOptions, getLineChartOptions, getPieChartOptions } from '../chart-options';
 
defineOptions({ name: 'ManagementCockpitTraceChart' });
 
const loading = ref(false);
const scanTrendRef = ref<EchartsUIType>();
const provinceRef = ref<EchartsUIType>();
const channelRef = ref<EchartsUIType>();
const { renderEcharts: renderScanTrend } = useEcharts(scanTrendRef);
const { renderEcharts: renderProvince } = useEcharts(provinceRef);
const { renderEcharts: renderChannel } = useEcharts(channelRef);
 
// 窜货预警汇总(用于展示卡片)
const crossRegion = ref({
  total: 0,
  pending: 0,
  handled: 0,
  falseAlarm: 0,
  crossProvince: 0,
  crossCity: 0,
});
 
/** 加载追溯统计并渲染 */
async function loadData() {
  loading.value = true;
  try {
    const data = await getManagementCockpitTrace(30);
    const scanTrend = data.scanTrend || [];
    const provinces = data.provinceDistribution || [];
    const channels = data.channelDistribution || [];
    crossRegion.value = data.crossRegionSummary || crossRegion.value;
    await renderScanTrend(
      getLineChartOptions(
        scanTrend.map((d) => d.date.slice(5)),
        scanTrend.map((d) => Number(d.count ?? 0)),
        '扫码次数',
        '#409EFF',
      ),
    );
    await renderProvince(
      getBarChartOptions(
        provinces.map((p) => p.name),
        provinces.map((p) => p.count),
        '扫码次数',
        '#67c23a',
      ),
    );
    await renderChannel(
      getPieChartOptions(channels.map((c) => ({ name: c.name, value: c.count }))),
    );
  } finally {
    loading.value = false;
  }
}
 
onMounted(() => {
  loadData();
});
</script>
 
<template>
  <Card title="追溯维度统计" class="h-full">
    <Spin :spinning="loading">
      <!-- 窜货预警汇总卡片 -->
      <Row :gutter="16" class="mb-2">
        <Col :lg="4" :md="8" :sm="12" :xs="24" class="mb-2">
          <Card size="small">
            <Statistic title="预警总数" :value="crossRegion.total" />
          </Card>
        </Col>
        <Col :lg="4" :md="8" :sm="12" :xs="24" class="mb-2">
          <Card size="small">
            <Statistic title="待处理" :value="crossRegion.pending" :value-style="{ color: '#f5222d' }" />
          </Card>
        </Col>
        <Col :lg="4" :md="8" :sm="12" :xs="24" class="mb-2">
          <Card size="small">
            <Statistic title="已处理" :value="crossRegion.handled" />
          </Card>
        </Col>
        <Col :lg="4" :md="8" :sm="12" :xs="24" class="mb-2">
          <Card size="small">
            <Statistic title="误报" :value="crossRegion.falseAlarm" />
          </Card>
        </Col>
        <Col :lg="4" :md="8" :sm="12" :xs="24" class="mb-2">
          <Card size="small">
            <Statistic title="跨省" :value="crossRegion.crossProvince" />
          </Card>
        </Col>
        <Col :lg="4" :md="8" :sm="12" :xs="24" class="mb-2">
          <Card size="small">
            <Statistic title="跨市" :value="crossRegion.crossCity" />
          </Card>
        </Col>
      </Row>
      <!-- 扫码趋势 + 省份分布 + 渠道分布 -->
      <Row :gutter="16">
        <Col :lg="10" :md="24" :sm="24" :xs="24">
          <div class="mb-1 text-sm text-gray-500">消费者扫码趋势</div>
          <EchartsUI ref="scanTrendRef" class="h-[280px] w-full" />
        </Col>
        <Col :lg="9" :md="24" :sm="24" :xs="24">
          <div class="mb-1 text-sm text-gray-500">扫码省份分布</div>
          <EchartsUI ref="provinceRef" class="h-[280px] w-full" />
        </Col>
        <Col :lg="5" :md="24" :sm="24" :xs="24">
          <div class="mb-1 text-sm text-gray-500">扫码渠道分布</div>
          <EchartsUI ref="channelRef" class="h-[280px] w-full" />
        </Col>
      </Row>
    </Spin>
  </Card>
</template>