liu
9 天以前 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
<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, RadioButton, RadioGroup, Row, Spin } from 'ant-design-vue';
 
import { getManagementCockpitOutbound } from '#/api/mes/management-cockpit';
 
import { getLineChartOptions, getPieChartOptions } from '../chart-options';
 
defineOptions({ name: 'ManagementCockpitOutboundChart' });
 
const trendDays = ref(30);
const loading = ref(false);
const trendRef = ref<EchartsUIType>();
const dealerRef = ref<EchartsUIType>();
const { renderEcharts: renderTrend } = useEcharts(trendRef);
const { renderEcharts: renderDealer } = useEcharts(dealerRef);
 
/** 加载出库统计并渲染 */
async function loadData() {
  loading.value = true;
  try {
    const data = await getManagementCockpitOutbound(trendDays.value);
    const trend = data.trend || [];
    const dealers = data.dealerDistribution || [];
    await renderTrend(
      getLineChartOptions(
        trend.map((d) => d.date.slice(5)),
        trend.map((d) => Number(d.count ?? 0)),
        '出库数量',
      ),
    );
    await renderDealer(
      getPieChartOptions(dealers.map((d) => ({ name: d.name, value: d.count }))),
    );
  } finally {
    loading.value = false;
  }
}
 
/** 切换天数范围 */
function handleDaysChange() {
  loadData();
}
 
onMounted(() => {
  loadData();
});
</script>
 
<template>
  <Card title="出库维度统计" class="h-full">
    <template #extra>
      <RadioGroup v-model:value="trendDays" size="small" @change="handleDaysChange">
        <RadioButton :value="7">近 7 天</RadioButton>
        <RadioButton :value="30">近 30 天</RadioButton>
        <RadioButton :value="90">近 90 天</RadioButton>
      </RadioGroup>
    </template>
    <Spin :spinning="loading">
      <Row :gutter="16">
        <Col :lg="15" :md="24" :sm="24" :xs="24">
          <div class="mb-1 text-sm text-gray-500">出库趋势</div>
          <EchartsUI ref="trendRef" class="h-[280px] w-full" />
        </Col>
        <Col :lg="9" :md="24" :sm="24" :xs="24">
          <div class="mb-1 text-sm text-gray-500">经销商出库占比(TOP 20)</div>
          <EchartsUI ref="dealerRef" class="h-[280px] w-full" />
        </Col>
      </Row>
    </Spin>
  </Card>
</template>