gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
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
<script lang="ts" setup>
import type { Dayjs } from 'dayjs';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
import { ref } from 'vue';
 
import { buildSortingField } from '..\..\..\..\..\packages\effects\request\src';
import { formatDateTime } from '..\..\..\..\..\packages\utils\src';
 
import { Card } from 'ant-design-vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getProductStatisticsRankPage } from '#/api/mall/statistics/product';
import ShortcutDateRangePicker from '#/components/shortcut-date-range-picker/shortcut-date-range-picker.vue';
 
/** 商品排行 */
defineOptions({ name: 'ProductRankCard' });
 
const searchTimes = ref<string[]>([]);
 
/** 处理日期范围变化 */
const handleDateRangeChange = (times?: [Dayjs, Dayjs]) => {
  if (times?.length !== 2) {
    return;
  }
  searchTimes.value = [
    formatDateTime(times[0]) as string,
    formatDateTime(times[1]) as string,
  ];
  gridApi.query();
};
 
const columns: VxeTableGridOptions['columns'] = [
  { field: 'spuId', title: '商品 ID', minWidth: 100 },
  {
    field: 'picUrl',
    title: '商品图片',
    minWidth: 100,
    cellRender: { name: 'CellImage' },
  },
  {
    field: 'name',
    title: '商品名称',
    minWidth: 200,
  },
  {
    field: 'browseCount',
    title: '浏览量',
    minWidth: 100,
    sortable: true,
  },
  {
    field: 'browseUserCount',
    title: '访客数',
    minWidth: 100,
    sortable: true,
  },
  {
    field: 'cartCount',
    title: '加购件数',
    minWidth: 110,
    sortable: true,
  },
  {
    field: 'orderCount',
    title: '下单件数',
    minWidth: 110,
    sortable: true,
  },
  {
    field: 'orderPayCount',
    title: '支付件数',
    minWidth: 110,
    sortable: true,
  },
  {
    field: 'orderPayPrice',
    title: '支付金额(元)',
    minWidth: 120,
    formatter: 'formatFenToYuanAmount',
    sortable: true,
  },
  {
    field: 'favoriteCount',
    title: '收藏数',
    minWidth: 100,
    sortable: true,
  },
  {
    field: 'browseConvertPercent',
    title: '访客-支付转化率(%)',
    minWidth: 160,
    sortable: true,
    formatter: ({ cellValue }) => `${cellValue || 0}%`,
  },
];
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    columns,
    height: 400,
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page, sorts }) => {
          return await getProductStatisticsRankPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            times: searchTimes.value.length > 0 ? searchTimes.value : undefined,
            ...buildSortingField(sorts),
          });
        },
      },
      sort: true,
    },
    sortConfig: {
      remote: true,
      multiple: false,
    },
    toolbarConfig: {
      enabled: false,
    },
  } as VxeTableGridOptions,
});
</script>
 
<template>
  <Card :bordered="false" title="商品排行">
    <template #extra>
      <ShortcutDateRangePicker @change="handleDateRangeChange" />
    </template>
    <Grid />
  </Card>
</template>