diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue index 230108ca..bce771b9 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue @@ -6,13 +6,13 @@ import type { CompanyOverviewVO, } from '#/api/ecommerce/company-overview'; -import { onActivated, onMounted, ref, watch } from 'vue'; +import { computed, onActivated, onMounted, ref, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; import { Page } from '@vben/common-ui'; import { EchartsUI, useEcharts } from '@vben/plugins/echarts'; -import { Button, DatePicker, message, Select, Spin } from 'ant-design-vue'; +import { Button, DatePicker, message, Spin } from 'ant-design-vue'; import dayjs from 'dayjs'; import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview'; @@ -31,10 +31,18 @@ const exportLoading = ref(false); const overviewData = ref(null); const shopCount = ref(0); -// 店铺多选 -interface ShopOption { label: string; value: number; } -const shopList = ref([]); -const selectedShopIds = ref([]); +// 指定店铺导出模式 +const shopExportMode = ref(false); +const selectedExportShopIds = ref([]); + +// 全选状态计算 +const allShopsSelected = computed(() => { + const total = overviewData.value?.shopComparisons?.length || 0; + return total > 0 && selectedExportShopIds.value.length === total; +}); +const someShopsSelected = computed(() => { + return selectedExportShopIds.value.length > 0; +}); // 日期范围 const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([ @@ -236,19 +244,6 @@ const loadShopCount = async () => { filters: {}, }); shopCount.value = response.total || 0; - - // 加载店铺列表供导出选择 - if (response.total > 0) { - const shopRes = await getShopPageApi({ - page: 1, - pageSize: response.total, - filters: {}, - }); - shopList.value = (shopRes.records || []).map((s: { id: number; name: string }) => ({ - label: s.name, - value: s.id, - })); - } } catch (error) { console.error('获取店铺数量失败:', error); } @@ -472,6 +467,25 @@ const handleExportCompanyOverview = async () => { try { exportLoading.value = true; const [startDate, endDate] = dateRange.value; + + // 优先使用已加载的 shopComparisons 数据(保持和页面一致的列顺序) + let dataToExport: CompanyOverviewVO.ShopComparison[] = []; + if (overviewData.value?.shopComparisons) { + if (selectedExportShopIds.value.length > 0) { + dataToExport = overviewData.value.shopComparisons.filter((s) => + selectedExportShopIds.value.includes(s.shopId), + ); + } else { + dataToExport = overviewData.value.shopComparisons; + } + } + + // 若无缓存数据,走原有接口按 shopIds 过滤 + let shopIds: number[] | undefined; + if (dataToExport.length === 0) { + shopIds = selectedExportShopIds.value.length > 0 ? selectedExportShopIds.value : undefined; + } + const filename = `公司概览_${startDate.format('YYYYMMDD')}_${endDate.format('YYYYMMDD')}.xlsx`; await exportByPost( '/ec/company-overview/export', @@ -480,14 +494,34 @@ const handleExportCompanyOverview = async () => { startDate.format('YYYY-MM-DD'), endDate.format('YYYY-MM-DD'), ], - shopIds: selectedShopIds.value.length > 0 ? selectedShopIds.value : undefined, + shopIds, }, filename, ); + + // 关闭行选择模式 + shopExportMode.value = false; } finally { exportLoading.value = false; } }; + +// 切换行选择模式 +const toggleShopExportMode = (enabled: boolean) => { + shopExportMode.value = enabled; + if (!enabled) { + selectedExportShopIds.value = []; + } +}; + +// 导出当前选中店铺(不关闭模式) +const handleExportSelectedShops = async () => { + if (selectedExportShopIds.value.length === 0) { + message.warning('请先选择要导出的店铺'); + return; + } + await handleExportCompanyOverview(); +};