Files
ecom-dmb/ecom-dmb-frontend/apps/web-antd/src/views/dashboard/company-overview/index.vue
T
小蟑螂 03cf396aea feat: 公司/店铺概览对比表增加商品成本和其他成本字段
CompanyOverviewVO.ShopComparison: 加 productCost、otherCost 字段
ShopOverviewStatisticsVO.ProductComparison: 加 productCost、otherCost 字段
CompanyOverviewServiceImpl / ShopOverviewStatisticsServiceImpl: 分别计算并赋值
前端 API 类型同步更新
公司概览 + 店铺概览页面表格:成本运费列拆为商品成本/运费/其他成本三列
2026-04-15 22:40:37 +08:00

1202 lines
40 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import type {
CompanyOverviewDTO,
CompanyOverviewVO,
} from '#/api/ecommerce/company-overview';
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, InputNumber, message, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview';
import { getShopPageApi } from '#/api/ecommerce/shop';
import { exportByPost } from '#/utils/export';
defineOptions({ name: 'CompanyOverview' });
// 路由
const router = useRouter();
const route = useRoute();
// 响应式数据
const loading = ref(false);
const exportLoading = ref(false);
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
const shopCount = ref(0);
// 指定店铺导出模式
const shopExportMode = ref(false);
const selectedExportShopIds = ref<number[]>([]);
// 全选状态计算
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]>([
dayjs().subtract(30, 'day'),
dayjs(),
]);
// 税率(公司/店铺概览共用持久化)
const TAX_RATE_KEY = 'overview-tax-rate';
const taxRate = ref<number>(0.04);
taxRate.value = Number(localStorage.getItem(TAX_RATE_KEY)) || 0.04;
watch(taxRate, (val) => {
localStorage.setItem(TAX_RATE_KEY, String(val));
loadOverviewData();
});
const formatTaxRate = (value: null | number | string | undefined) => {
if (value === null || value === undefined || value === '') return '';
const num = Number(value);
if (!Number.isFinite(num)) return '';
return `${num * 100}%`;
};
const parseTaxRate = (value: string | undefined) => {
if (!value) return 0;
const num = Number(value.replace('%', '').trim());
return Number.isFinite(num) ? num / 100 : 0;
};
// 当前选中的时间范围类型
const activeTimeRange = ref<
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
>('30days');
// 自定义日期范围
const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>([
dateRange.value[0],
dateRange.value[1],
]);
const lastRequestKey = ref('');
const isSyncingRouteQuery = ref(false);
// 切换时间范围
const switchTimeRange = (
type: '7days' | '30days' | 'custom' | 'today' | 'yesterday',
) => {
activeTimeRange.value = type;
let startDate: dayjs.Dayjs;
let endDate: dayjs.Dayjs = dayjs();
switch (type) {
case '7days': {
startDate = dayjs().subtract(7, 'day');
break;
}
case '30days': {
startDate = dayjs().subtract(30, 'day');
break;
}
case 'custom': {
if (customDateRange.value) {
dateRange.value = customDateRange.value;
}
return;
}
case 'today': {
startDate = dayjs();
endDate = dayjs();
break;
}
case 'yesterday': {
startDate = dayjs().subtract(1, 'day');
endDate = dayjs().subtract(1, 'day');
break;
}
}
dateRange.value = [startDate, endDate];
customDateRange.value = [startDate, endDate];
};
// 自定义日期范围变化
const handleCustomDateRangeChange = (
value: [dayjs.Dayjs, dayjs.Dayjs] | [string, string] | null,
_dateString?: [string, string],
) => {
if (value && Array.isArray(value) && value.length === 2) {
// 确保是 dayjs 对象
const dates = [
dayjs.isDayjs(value[0]) ? value[0] : dayjs(value[0]),
dayjs.isDayjs(value[1]) ? value[1] : dayjs(value[1]),
] as [dayjs.Dayjs, dayjs.Dayjs];
customDateRange.value = dates;
activeTimeRange.value = 'custom';
dateRange.value = dates;
}
};
const setTimeRangeTypeByDates = (
startDate: dayjs.Dayjs,
endDate: dayjs.Dayjs,
) => {
const today = dayjs();
const daysDiff = endDate.diff(startDate, 'day');
const isEndDateToday = endDate.isSame(today, 'day');
const isStartDate7DaysAgo = startDate.isSame(
dayjs().subtract(7, 'day'),
'day',
);
const isStartDate30DaysAgo = startDate.isSame(
dayjs().subtract(30, 'day'),
'day',
);
if (daysDiff === 0 && startDate.isSame(today, 'day')) {
activeTimeRange.value = 'today';
customDateRange.value = [startDate, endDate];
return;
}
if (daysDiff === 0 && startDate.isSame(dayjs().subtract(1, 'day'), 'day')) {
activeTimeRange.value = 'yesterday';
customDateRange.value = [startDate, endDate];
return;
}
if (isEndDateToday && isStartDate7DaysAgo) {
activeTimeRange.value = '7days';
customDateRange.value = [startDate, endDate];
return;
}
if (isEndDateToday && isStartDate30DaysAgo) {
activeTimeRange.value = '30days';
customDateRange.value = [startDate, endDate];
return;
}
activeTimeRange.value = 'custom';
customDateRange.value = [startDate, endDate];
};
const applyDateRangeFromRouteQuery = () => {
const { endDate, startDate } = route.query;
if (!startDate || !endDate) return false;
const parsedStartDate = dayjs(startDate as string);
const parsedEndDate = dayjs(endDate as string);
if (!parsedStartDate.isValid() || !parsedEndDate.isValid()) return false;
const isSameRange =
dateRange.value[0].isSame(parsedStartDate, 'day') &&
dateRange.value[1].isSame(parsedEndDate, 'day');
if (!isSameRange) {
dateRange.value = [parsedStartDate, parsedEndDate];
}
setTimeRangeTypeByDates(parsedStartDate, parsedEndDate);
return true;
};
const syncDateRangeToRouteQuery = async () => {
const startDate = dateRange.value[0].format('YYYY-MM-DD');
const endDate = dateRange.value[1].format('YYYY-MM-DD');
if (route.query.startDate === startDate && route.query.endDate === endDate) {
return;
}
isSyncingRouteQuery.value = true;
try {
await router.replace({
path: route.path,
query: {
...route.query,
endDate,
startDate,
},
});
} finally {
isSyncingRouteQuery.value = false;
}
};
// 图表引用
const barChartRef = ref<EchartsUIType>();
const scatterChartRef = ref<EchartsUIType>();
const { renderEcharts: renderBarChart } = useEcharts(barChartRef);
const { renderEcharts: renderScatterChart } = useEcharts(scatterChartRef);
// 格式化金额
const formatAmount = (amount: number) => {
return `¥${amount.toLocaleString('zh-CN')}`;
};
// 格式化百分比
const formatPercent = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
};
// 格式化百分比(不带符号)
const formatPercentPlain = (value: number | undefined) => {
if (value === undefined) return '-';
return `${value.toFixed(1)}%`;
};
// 跳转到店铺详情页
const navigateToShopOverview = (shopId: number) => {
router.push({
path: `/ecom/shop/overview/${shopId}`,
query: {
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
},
});
};
// 加载店铺数量
const loadShopCount = async () => {
try {
const response = await getShopPageApi({
page: 1,
pageSize: 1,
filters: {},
});
shopCount.value = response.total || 0;
} catch (error) {
console.error('获取店铺数量失败:', error);
}
};
// 加载概览数据
const loadOverviewData = async () => {
try {
loading.value = true;
const params: CompanyOverviewDTO.Query = {
dateRange: [
dateRange.value[0].format('YYYY-MM-DD'),
dateRange.value[1].format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
};
const data = await getCompanyOverviewApi(params);
overviewData.value = data;
} catch (error) {
console.error('获取全店概览数据失败:', error);
} finally {
loading.value = false;
}
};
const refreshOverviewByCurrentParams = async (force = false) => {
applyDateRangeFromRouteQuery();
const requestKey = `${dateRange.value[0].format('YYYY-MM-DD')}_${dateRange.value[1].format('YYYY-MM-DD')}`;
if (!force && lastRequestKey.value === requestKey) {
return;
}
lastRequestKey.value = requestKey;
await loadOverviewData();
};
// 渲染店铺销售占比排行图表
const renderShopBarChart = () => {
if (!barChartRef.value || !overviewData.value?.shopSalesRatios) return;
const ratios = overviewData.value.shopSalesRatios;
const shopNames = ratios.map((r) => r.shopName).reverse();
const salesAmounts = ratios.map((r) => r.salesAmount).reverse();
renderBarChart({
grid: {
left: '3%',
right: '12%',
bottom: '3%',
top: '3%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
formatter: (params: any) => {
const param = Array.isArray(params) ? params[0] : params;
const index = param.dataIndex;
const shop = ratios[ratios.length - 1 - index];
if (!shop) return '';
return `${shop.shopName}<br/>销售额: ${formatAmount(shop.salesAmount)}<br/>占比: ${shop.ratio.toFixed(2)}%`;
},
},
xAxis: {
type: 'value',
axisLabel: { show: false },
splitLine: { show: false },
},
yAxis: {
type: 'category',
data: shopNames,
axisLine: { show: false },
axisTick: { show: false },
axisLabel: {
fontWeight: 'bold',
color: '#1e293b',
fontSize: 13,
},
},
series: [
{
type: 'bar',
data: salesAmounts,
barWidth: 20,
itemStyle: {
borderRadius: [0, 10, 10, 0],
color: {
type: 'linear',
x: 1,
y: 0,
x2: 0,
y2: 0,
colorStops: [
{ offset: 0, color: '#6366f1' },
{ offset: 1, color: '#a5b4fc' },
],
},
},
label: {
show: true,
position: 'right',
formatter: (params: any) =>
`¥${params.value.toLocaleString('zh-CN')}`,
fontWeight: 900,
color: '#0f172a',
},
},
],
});
};
// 渲染店铺效率象限图
const renderShopScatterChart = () => {
if (!scatterChartRef.value || !overviewData.value) return;
const quadrants = overviewData.value.shopEfficiencyQuadrants ?? [];
const scatterSource =
quadrants.length > 0
? quadrants.map((q) => ({
shopId: q.shopId,
shopName: q.shopName,
roi: Number(q.roi),
netProfit: Number(q.netProfit),
}))
: (overviewData.value.shopComparisons ?? []).map((shop) => ({
shopId: shop.shopId,
shopName: shop.shopName,
roi: Number(shop.roi),
netProfit: Number(shop.profitAfterTax),
}));
const data: Array<[number, number, string]> = scatterSource.map((q) => {
const roi = Number.isFinite(q.roi) ? q.roi : 0;
const netProfit = Number.isFinite(q.netProfit) ? q.netProfit : 0;
return [roi, netProfit / 10_000, q.shopName];
});
const roiValues = data.map((item) => item[0]);
const profitValues = data.map((item) => item[1]);
const minRoi = roiValues.length ? Math.min(...roiValues) : 0;
const maxRoi = roiValues.length ? Math.max(...roiValues) : 1;
const minProfit = profitValues.length ? Math.min(...profitValues) : 0;
const maxProfit = profitValues.length ? Math.max(...profitValues) : 1;
const roiPadding = minRoi === maxRoi ? 1 : (maxRoi - minRoi) * 0.2;
const profitPadding =
minProfit === maxProfit ? 1 : (maxProfit - minProfit) * 0.2;
renderScatterChart({
grid: {
left: '6%',
right: '4%',
top: '8%',
bottom: '16%',
containLabel: true,
},
tooltip: {
trigger: 'item',
formatter: (params: any) => {
const shop = scatterSource[params.dataIndex];
if (!shop) return '';
return `<div style="padding:4px; font-weight:bold">${shop.shopName}</div><hr/>投资回报率 (ROI): ${shop.roi.toFixed(2)}<br/>净利润: ¥${(shop.netProfit / 10_000).toFixed(2)}万`;
},
},
xAxis: {
type: 'value',
min: minRoi - roiPadding,
max: Math.max(maxRoi + roiPadding, 3.5),
name: '投资回报率 (ROI)',
nameLocation: 'middle',
nameGap: 35,
axisLabel: { fontWeight: 'bold' },
splitLine: {
lineStyle: { type: 'dashed' },
},
},
yAxis: {
type: 'value',
min: Math.min(minProfit - profitPadding, 0),
max: Math.max(maxProfit + profitPadding, 10),
name: '税后净利润 (单位: 万元)',
nameLocation: 'middle',
nameGap: 50,
axisLabel: { fontWeight: 'bold' },
splitLine: {
lineStyle: { type: 'dashed' },
},
},
series: [
{
type: 'scatter',
symbolSize: 45,
data,
label: {
show: true,
position: 'top',
color: '#334155',
fontWeight: 700,
formatter: (params: any) => params.data?.[2] ?? '',
},
itemStyle: {
color: (params: any) => {
const roi = params.data?.[0];
const profit = params.data?.[1];
if (roi >= 3.5 && profit >= 10) return '#10b981'; // 高产区
if (roi < 3 || profit < 0) return '#f43f5e'; // 风险区
return '#6366f1'; // 潜力区
},
shadowBlur: 15,
shadowColor: 'rgba(0,0,0,0.1)',
},
markLine: {
silent: true,
lineStyle: { type: 'dashed', color: '#94a3b8' },
data: [{ xAxis: 3.5 }, { yAxis: 10 }],
},
},
],
});
};
// 监听数据变化,重新渲染图表
watch(
() => overviewData.value,
() => {
if (overviewData.value) {
// 使用 setTimeout 确保 DOM 已更新
setTimeout(() => {
renderShopBarChart();
renderShopScatterChart();
}, 100);
}
},
{ deep: true },
);
// 监听日期范围变化
watch(
() => dateRange.value,
async () => {
await syncDateRangeToRouteQuery();
await refreshOverviewByCurrentParams();
},
);
watch(
() => [route.query.startDate, route.query.endDate],
async () => {
if (isSyncingRouteQuery.value) return;
await refreshOverviewByCurrentParams();
},
);
// 初始化
onMounted(async () => {
await loadShopCount();
await refreshOverviewByCurrentParams(true);
});
onActivated(async () => {
await refreshOverviewByCurrentParams(true);
});
// 导出公司概览
const handleExportCompanyOverview = async () => {
try {
exportLoading.value = true;
const [startDate, endDate] = dateRange.value;
// 优先使用已加载的 shopComparisons 数据(保持和页面一致的列顺序)
let dataToExport: CompanyOverviewVO.ShopComparison[] = [];
if (overviewData.value?.shopComparisons) {
dataToExport =
selectedExportShopIds.value.length > 0
? overviewData.value.shopComparisons.filter((s) =>
selectedExportShopIds.value.includes(s.shopId),
)
: 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',
{
dateRange: [
startDate.format('YYYY-MM-DD'),
endDate.format('YYYY-MM-DD'),
],
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();
};
</script>
<template>
<Page title="全店铺经营概览大盘" auto-content-height class="bg-[#f8fafc]">
<template #description>
<div class="mt-1 text-sm font-bold text-slate-500">
数据范围:公司旗下所有店铺汇总统计 · 共 {{ shopCount }} 家在营店铺
</div>
</template>
<template #extra>
<!-- 税率 + 时间选择器 -->
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-2">
<!-- 税率输入 -->
<div
class="flex h-[42px] items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 px-3"
>
<span class="text-xs font-bold text-slate-400">税率</span>
<InputNumber
v-model:value="taxRate"
:min="0"
:max="1"
:step="0.01"
:precision="2"
size="small"
class="tax-rate-input !h-8 !w-20 !rounded-lg !border-none !bg-white/30 !text-sm !font-bold"
:formatter="formatTaxRate"
:parser="parseTaxRate"
/>
</div>
<!-- 时间选择器容器 -->
<div
class="flex flex-col gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 p-1.5 sm:flex-row sm:items-center sm:gap-2"
>
<!-- 快速选择按钮组 -->
<div
class="flex items-center gap-1 overflow-x-auto rounded-xl bg-white/30 p-1"
>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === 'today'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('today')"
>
今日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === 'yesterday'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('yesterday')"
>
昨日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === '7days'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('7days')"
>
近7日
</Button>
<Button
type="text"
size="small"
class="!h-auto !min-w-0 !rounded-xl !border-none !px-3 !py-2 !text-sm !font-bold !shadow-none !transition-colors sm:!px-5"
:class="
activeTimeRange === '30days'
? '!bg-white !text-blue-600 !shadow-sm'
: '!bg-transparent !text-slate-600 hover:!bg-white/50'
"
@click="switchTimeRange('30days')"
>
近30日
</Button>
</div>
<!-- 日期选择器 -->
<div class="flex items-center gap-2">
<span class="hidden text-xs font-bold text-slate-400 sm:inline">
自定义日期
</span>
<DatePicker.RangePicker
v-model:value="customDateRange"
size="small"
format="YYYY-MM-DD"
:allow-clear="false"
:placeholder="['开始', '结束']"
class="!h-8 !border-none !bg-transparent !text-sm !font-bold"
@change="handleCustomDateRangeChange"
/>
</div>
</div>
</div>
</template>
<Spin :spinning="loading">
<div class="mx-auto w-full space-y-6">
<!-- 第一层:核心汇总指标 -->
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4">
<!-- 销售额 -->
<div
class="rounded-2xl border border-slate-200 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="mb-4 flex items-start justify-between">
<span class="text-xs font-black text-slate-500">
全店总销售额
</span>
<span
v-if="overviewData?.monthOverMonthGrowth !== undefined"
class="rounded bg-emerald-50 px-2 py-1 text-xs font-bold text-emerald-600"
>
{{ formatPercent(overviewData.monthOverMonthGrowth) }} 较上月
</span>
</div>
<div class="text-4xl font-black leading-none text-slate-900">
{{
overviewData?.totalSalesAmount
? formatAmount(overviewData.totalSalesAmount)
: '-'
}}
</div>
<div
v-if="overviewData?.salesAmountAchievementRate !== undefined"
class="mt-6 flex items-center justify-between border-t border-slate-100 pt-4"
>
<span class="text-xs font-bold text-slate-400">
销售额目标达成率
</span>
>
<span class="text-sm font-black text-blue-600">
{{
formatPercentPlain(overviewData.salesAmountAchievementRate)
}}
</span>
</div>
</div>
<!-- ROI效率 -->
<div
class="rounded-2xl border border-slate-200 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="mb-4 text-xs font-black text-slate-500">
投资回报率 (ROI)
</div>
<div class="text-4xl font-black leading-none text-indigo-600">
{{ overviewData?.totalROI?.toFixed(2) || '-' }}
</div>
<div
v-if="overviewData?.averageFeeRatio !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 pt-4 text-xs font-bold text-slate-400"
>
<span>全店平均费比</span>
<span class="text-slate-900">
{{ formatPercentPlain(overviewData.averageFeeRatio) }}
</span>
</div>
</div>
<!-- 订单达成 -->
<div
class="rounded-2xl border border-slate-200 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="mb-4 text-xs font-black text-slate-500">
销量目标达成率 (订单数)
</div>
<div class="text-4xl font-black leading-none text-slate-900">
{{
overviewData?.orderCountAchievementRate !== undefined
? formatPercentPlain(overviewData.orderCountAchievementRate)
: '-'
}}
</div>
<div
v-if="overviewData?.orderCountAchievementRate !== undefined"
class="mt-6 h-2 w-full overflow-hidden rounded-full bg-slate-100"
>
<div
class="h-full bg-indigo-500"
:style="{
width: `${Math.min(overviewData.orderCountAchievementRate, 100)}%`,
}"
></div>
</div>
</div>
<!-- 税后利润 -->
<div
class="rounded-2xl border-l-4 border-slate-200 border-l-emerald-500 bg-white/90 p-6 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div class="mb-4 text-xs font-black text-emerald-600">
全店总净利润 (税后)
</div>
<div class="text-4xl font-black leading-none text-emerald-600">
{{
overviewData?.totalNetProfitAfterTax
? formatAmount(overviewData.totalNetProfitAfterTax)
: '-'
}}
</div>
<div
v-if="overviewData?.totalTaxAmount !== undefined"
class="mt-6 flex justify-between border-t border-slate-100 pt-4 text-[11px] font-bold text-slate-400"
>
<span>已扣除预扣税额 ({{ (taxRate * 100).toFixed(0) }}%)</span>
<span>{{ formatAmount(overviewData.totalTaxAmount) }}</span>
</div>
</div>
</div>
<!-- 第二层:深度分析图表 -->
<div class="grid grid-cols-1 gap-6 xl:grid-cols-2">
<!-- 销售占比排行 -->
<div
class="rounded-2xl border border-slate-200 bg-white/90 p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<h3 class="mb-6 text-lg font-black text-slate-800">
各店铺销售贡献排行
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="barChartRef" />
</div>
</div>
<!-- 效率象限图 -->
<div
class="rounded-2xl border border-slate-200 bg-white/90 p-8 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<h3 class="mb-6 text-lg font-black text-slate-800">
店铺经营效率象限 (ROI vs 净利)
</h3>
<div class="h-[380px] w-full">
<EchartsUI ref="scatterChartRef" />
</div>
<!-- 象限图说明 -->
<div class="mt-4 flex justify-center gap-6">
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600"
>
<span class="h-3 w-3 rounded-full bg-emerald-500"></span>
高产区
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600"
>
<span class="h-3 w-3 rounded-full bg-blue-500"></span>
潜力区
</div>
<div
class="flex items-center gap-2 text-xs font-bold text-slate-600"
>
<span class="h-3 w-3 rounded-full bg-rose-500"></span>
风险区
</div>
</div>
</div>
</div>
<!-- 第三层:横向对比大表 (16维度) -->
<div
class="overflow-hidden rounded-2xl border border-slate-200 bg-white/90 shadow-[0_4px_12px_rgba(0,0,0,0.03)] backdrop-blur-[10px]"
>
<div
class="flex flex-col items-start justify-between gap-4 border-b border-slate-100 p-8 md:flex-row md:items-center"
>
<div>
<h3 class="text-xl font-black text-slate-800">
各店铺多维度经营明细对比
</h3>
<p class="mt-1 text-xs font-bold text-slate-400">
包含:目标达成、规模、成本及最终损益所有维度
</p>
</div>
<div class="flex items-center gap-3">
<template v-if="shopExportMode">
<Button
type="default"
class="!rounded-2xl"
@click="toggleShopExportMode(false)"
>
取消选择
</Button>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-blue-600 !px-8 !py-3 !text-sm !font-bold !shadow-xl !shadow-slate-200 !transition-all hover:!scale-105 active:!scale-95"
:loading="exportLoading"
:disabled="selectedExportShopIds.length === 0"
@click="handleExportSelectedShops"
>
导出已选店铺 ({{ selectedExportShopIds.length }})
</Button>
</template>
<template v-else>
<Button
class="!rounded-2xl"
@click="toggleShopExportMode(true)"
>
指定店铺导出
</Button>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-bold !shadow-xl !shadow-slate-200 !transition-all hover:!scale-105 active:!scale-95"
:loading="exportLoading"
@click="handleExportCompanyOverview"
>
导出全部
</Button>
</template>
</div>
</div>
<div class="table-container overflow-x-auto">
<table class="w-full whitespace-nowrap text-left text-sm">
<!-- 表头分组 -->
<thead
class="bg-slate-50 text-xs font-black uppercase text-slate-500"
>
<tr>
<th
v-if="shopExportMode"
rowspan="2"
class="sticky-col border-b border-r-2 border-slate-200 bg-slate-100 p-3 text-center"
>
<input
type="checkbox"
class="h-4 w-4 cursor-pointer accent-blue-600"
:checked="allShopsSelected"
:indeterminate="someShopsSelected && !allShopsSelected"
@change="
(e) => {
if ((e.target as HTMLInputElement).checked) {
selectedExportShopIds =
overviewData?.shopComparisons?.map(
(s: CompanyOverviewVO.ShopComparison) =>
s.shopId,
) || [];
} else {
selectedExportShopIds = [];
}
}
"
/>
</th>
<th
rowspan="2"
class="sticky-col border-b p-6 text-base font-black text-slate-900 shadow-sm"
:class="
shopExportMode
? 'border-l-0 bg-white'
: 'border-r-2 border-slate-100 bg-white'
"
>
店铺名称
</th>
<th
colspan="4"
class="border-b border-l border-slate-200 bg-blue-50/50 p-3 text-center text-blue-700"
>
目标达成维度
</th>
<th
colspan="3"
class="border-b border-l border-slate-200 bg-slate-100/50 p-3 text-center"
>
经营规模维度
</th>
<th
colspan="5"
class="border-b border-l border-slate-200 bg-orange-50/50 p-3 text-center text-orange-700"
>
成本费用维度
</th>
<th
colspan="4"
class="border-b border-l border-slate-200 bg-emerald-50/50 p-3 text-center text-emerald-700"
>
盈利分析维度
</th>
</tr>
<tr class="bg-slate-50/80 text-sm">
<!-- 目标 -->
<th class="border-b border-l px-6 py-4">目标单量</th>
<th class="border-b px-6 py-4 text-blue-600">单量达成率</th>
<th class="border-b px-6 py-4">目标额</th>
<th class="border-b px-6 py-4 text-blue-600">销售达成率</th>
<!-- 规模 -->
<th
class="border-b border-l px-6 py-4 font-black text-slate-900"
>
实际销售额
</th>
<th class="border-b px-6 py-4">单量</th>
<th class="border-b px-6 py-4">客单价</th>
<!-- 成本 -->
<th class="border-b border-l px-6 py-4">商品成本</th>
<th class="border-b px-6 py-4">运费</th>
<th class="border-b px-6 py-4">其他成本</th>
<th class="border-b px-6 py-4 font-bold text-rose-600">
退款金额
</th>
<th class="border-b px-6 py-4">推广费</th>
<th class="border-b px-6 py-4 text-orange-600">刷单费用</th>
<th class="border-b px-6 py-4 text-slate-400">费比 %</th>
<!-- 盈利 -->
<th class="border-b border-l px-6 py-4 font-bold">
税前盈亏
</th>
<th class="border-b px-6 py-4 italic text-rose-500">
{{ (taxRate * 100).toFixed(0) }}%税额
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700">
ROI
</th>
<th
class="border-b bg-emerald-600 px-6 py-4 font-black text-white"
>
税后盈亏
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
<tr
v-for="shop in overviewData?.shopComparisons"
:key="shop.shopId"
class="transition-colors hover:bg-blue-50/50"
>
<td
v-if="shopExportMode"
class="sticky-col border-r bg-slate-50/50 p-3 text-center"
>
<input
v-model="selectedExportShopIds"
type="checkbox"
:value="shop.shopId"
class="h-4 w-4 cursor-pointer accent-blue-600"
/>
</td>
<td
class="sticky-col border-r-2 border-slate-100 bg-white p-6 font-bold shadow-sm"
:class="shopExportMode ? 'border-l-0' : ''"
>
<span
class="cursor-pointer text-blue-600 transition-colors hover:text-blue-800 hover:underline"
@click="navigateToShopOverview(shop.shopId)"
>
{{ shop.shopName }}
</span>
</td>
<!-- 目标 -->
<td class="p-6 font-medium">
{{ shop.targetOrderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="p-6 font-black text-blue-600">
{{
shop.orderCountAchievementRate !== undefined
? formatPercentPlain(shop.orderCountAchievementRate)
: '-'
}}
</td>
<td class="p-6 font-medium">
{{
shop.targetAmount ? formatAmount(shop.targetAmount) : '-'
}}
</td>
<td class="p-6 font-black text-blue-600">
{{
shop.salesAmountAchievementRate !== undefined
? formatPercentPlain(shop.salesAmountAchievementRate)
: '-'
}}
</td>
<!-- 规模 -->
<td class="p-6 font-black">
{{ formatAmount(shop.salesAmount) }}
</td>
<td class="p-6 font-medium">
{{ shop.orderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="p-6 font-medium">
{{
shop.averageOrderValue
? formatAmount(shop.averageOrderValue)
: '-'
}}
</td>
<!-- 成本 -->
<td class="p-6">
{{
shop.productCost ? formatAmount(shop.productCost) : '-'
}}
</td>
<td class="p-6">
{{
shop.shippingCost ? formatAmount(shop.shippingCost) : '-'
}}
</td>
<td class="p-6">
{{
shop.otherCost ? formatAmount(shop.otherCost) : '-'
}}
</td>
<td class="p-6 font-bold text-rose-600">
{{
shop.refundAmount ? formatAmount(shop.refundAmount) : '-'
}}
</td>
<td class="p-6">
{{
shop.totalPromotionFee
? formatAmount(shop.totalPromotionFee)
: '-'
}}
</td>
<td class="p-6 text-orange-600">
{{ shop.brushFee ? formatAmount(shop.brushFee) : '-' }}
</td>
<td class="p-6 text-slate-400">
{{
shop.feeRatio !== undefined
? formatPercentPlain(shop.feeRatio)
: '-'
}}
</td>
<!-- 盈利 -->
<td class="p-6 font-bold">
{{
shop.totalProfitBeforeTax
? formatAmount(shop.totalProfitBeforeTax)
: '-'
}}
</td>
<td class="p-6 italic text-slate-400">
{{
shop.salesTaxAmount
? formatAmount(shop.salesTaxAmount)
: '-'
}}
</td>
<td class="p-6 font-black text-indigo-700">
{{ shop.roi?.toFixed(2) || '-' }}
</td>
<td
class="bg-emerald-50 p-6 text-base font-black text-emerald-600"
>
{{
shop.profitAfterTax
? formatAmount(shop.profitAfterTax)
: '-'
}}
</td>
</tr>
<tr v-if="!overviewData?.shopComparisons?.length">
<td colspan="17" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</Spin>
</Page>
</template>
<style scoped>
/* 表格滚动条 */
.table-container::-webkit-scrollbar {
height: 8px;
}
.table-container::-webkit-scrollbar-thumb {
background: #cbd5e1;
border-radius: 10px;
}
.table-container::-webkit-scrollbar-track {
background: #f1f5f9;
}
/* 固定首列 */
.sticky-col {
position: sticky;
left: 0;
z-index: 10;
}
:deep(.tax-rate-input .ant-input-number-input) {
height: 32px;
line-height: 32px;
padding-top: 0;
padding-bottom: 0;
}
</style>