gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
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
<script lang="ts" setup>
import type { EchartsUIType } from '../../../../packages/effects/plugins/src/echarts';
 
import type { WmsHomeStatisticsApi } from '#/api/wms/home';
 
import { nextTick, ref } from 'vue';
 
import { EchartsUI, useEcharts } from '../../../../packages/effects/plugins/src/echarts';
 
import { Card, Segmented } from 'ant-design-vue';
 
import { getOrderTrend } from '#/api/wms/home';
 
import { getOrderTrendChartOptions } from './wms-home-order-trend-chart-options';
 
defineOptions({ name: 'WmsHomeOrderTrendChart' });
 
const loading = ref(false);
const warehouseId = ref<number>();
const trendDays = ref(7);
const trendList = ref<WmsHomeStatisticsApi.OrderTrend[]>([]);
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const trendDayOptions = [
  { label: '近7天', value: 7 },
  { label: '近30天', value: 30 },
];
 
/** 使用最新趋势数据渲染单据趋势图 */
async function renderChart() {
  await nextTick();
  await renderEcharts(getOrderTrendChartOptions(trendList.value));
}
 
/** 加载指定仓库的单据趋势数据 */
async function load(selectedWarehouseId?: number) {
  warehouseId.value = selectedWarehouseId;
  loading.value = true;
  try {
    trendList.value = await getOrderTrend(
      trendDays.value,
      selectedWarehouseId ? { warehouseId: selectedWarehouseId } : {},
    );
    await renderChart();
  } finally {
    loading.value = false;
  }
}
 
/** 切换趋势统计时间范围并刷新图表 */
async function handleTrendDaysChange(value: number | string) {
  trendDays.value = Number(value);
  await load(warehouseId.value);
}
 
defineExpose({ load });
</script>
 
<template>
  <Card :body-style="{ padding: '12px 16px 16px' }">
    <div class="mb-3 flex items-center justify-between">
      <div>
        <div class="font-semibold">单据趋势</div>
        <div class="text-sm text-muted-foreground">
          入库、出库、移库、盘库单据数量
        </div>
      </div>
      <Segmented
        :options="trendDayOptions"
        :value="trendDays"
        @change="handleTrendDaysChange"
      />
    </div>
    <div class="relative min-h-[330px]">
      <EchartsUI ref="chartRef" height="330px" />
      <div
        v-if="loading"
        class="absolute inset-0 flex items-center justify-center bg-card/70 text-sm text-muted-foreground"
      >
        加载中
      </div>
    </div>
  </Card>
</template>