mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
598 lines
19 KiB
Vue
598 lines
19 KiB
Vue
<script lang="ts" setup>
|
|
import type { EchartsUIType } from '@vben/plugins/echarts';
|
|
|
|
import type {
|
|
CompanyOverviewDTO,
|
|
CompanyOverviewVO,
|
|
} from '#/api/ecommerce/company-overview';
|
|
|
|
import { onMounted, ref, watch } from 'vue';
|
|
|
|
import { Page } from '@vben/common-ui';
|
|
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
|
|
|
import { Button, DatePicker, message, Spin } from 'ant-design-vue';
|
|
import dayjs from 'dayjs';
|
|
|
|
import { getCompanyOverviewApi } from '#/api/ecommerce/company-overview';
|
|
import { getShopPageApi } from '#/api/ecommerce/shop';
|
|
|
|
defineOptions({ name: 'CompanyOverview' });
|
|
|
|
// 响应式数据
|
|
const loading = ref(false);
|
|
const overviewData = ref<CompanyOverviewVO.Info | null>(null);
|
|
const shopCount = ref(0);
|
|
|
|
// 日期范围
|
|
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
|
|
dayjs().subtract(30, 'day'),
|
|
dayjs(),
|
|
]);
|
|
|
|
// 当前选中的时间范围类型
|
|
const activeTimeRange = ref<
|
|
'7days' | '30days' | 'custom' | 'today' | 'yesterday'
|
|
>('30days');
|
|
|
|
// 自定义日期范围
|
|
const customDateRange = ref<[dayjs.Dayjs, dayjs.Dayjs] | undefined>(undefined);
|
|
|
|
// 切换时间范围
|
|
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];
|
|
};
|
|
|
|
// 自定义日期范围变化
|
|
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 barChartRef = ref<EchartsUIType>();
|
|
const scatterChartRef = ref<EchartsUIType>();
|
|
const { renderEcharts: renderBarChart } = useEcharts(barChartRef);
|
|
const { renderEcharts: renderScatterChart } = useEcharts(scatterChartRef);
|
|
|
|
// 格式化金额
|
|
const formatAmount = (amount: number) => {
|
|
return `¥${(amount / 10_000).toFixed(2)}万`;
|
|
};
|
|
|
|
// 格式化金额(完整)
|
|
const formatAmountFull = (amount: number) => {
|
|
return `¥${amount.toLocaleString('zh-CN')}`;
|
|
};
|
|
|
|
// 格式化百分比
|
|
const formatPercent = (value: number | undefined) => {
|
|
if (value === undefined) return '-';
|
|
return `${value > 0 ? '+' : ''}${value.toFixed(1)}%`;
|
|
};
|
|
|
|
// 加载店铺数量
|
|
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'),
|
|
],
|
|
};
|
|
const data = await getCompanyOverviewApi(params);
|
|
overviewData.value = data;
|
|
} catch (error) {
|
|
console.error('获取全店概览数据失败:', error);
|
|
message.error('获取全店概览数据失败');
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
// 渲染店铺销售占比排行图表
|
|
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 / 1000).reverse(); // 转换为千元
|
|
|
|
renderBarChart({
|
|
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/>销售额: ${formatAmountFull(shop.salesAmount)}<br/>占比: ${shop.ratio.toFixed(2)}%`;
|
|
},
|
|
},
|
|
xAxis: {
|
|
type: 'value',
|
|
show: false,
|
|
},
|
|
yAxis: {
|
|
type: 'category',
|
|
data: shopNames,
|
|
axisLine: { show: false },
|
|
},
|
|
series: [
|
|
{
|
|
type: 'bar',
|
|
data: salesAmounts,
|
|
itemStyle: {
|
|
color: {
|
|
type: 'linear',
|
|
x: 1,
|
|
y: 0,
|
|
x2: 0,
|
|
y2: 0,
|
|
colorStops: [
|
|
{ offset: 0, color: '#6366f1' },
|
|
{ offset: 1, color: '#a5b4fc' },
|
|
],
|
|
},
|
|
borderRadius: [0, 10, 10, 0],
|
|
},
|
|
barWidth: 25,
|
|
},
|
|
],
|
|
});
|
|
};
|
|
|
|
// 渲染店铺效率象限图
|
|
const renderShopScatterChart = () => {
|
|
if (!scatterChartRef.value || !overviewData.value?.shopEfficiencyQuadrants)
|
|
return;
|
|
|
|
const quadrants = overviewData.value.shopEfficiencyQuadrants;
|
|
const data = quadrants.map((q) => [q.roi, q.netProfit / 1000]); // 净利转换为千元
|
|
|
|
renderScatterChart({
|
|
grid: {
|
|
top: '10%',
|
|
bottom: '10%',
|
|
left: '10%',
|
|
right: '10%',
|
|
},
|
|
tooltip: {
|
|
trigger: 'item',
|
|
formatter: (params: any) => {
|
|
const index = params.dataIndex;
|
|
const shop = quadrants[index];
|
|
if (!shop) return '';
|
|
return `${shop.shopName}<br/>ROI: ${shop.roi.toFixed(2)}<br/>净利: ${formatAmountFull(shop.netProfit)}`;
|
|
},
|
|
},
|
|
xAxis: {
|
|
name: 'ROI',
|
|
nameLocation: 'middle',
|
|
nameGap: 30,
|
|
splitLine: {
|
|
lineStyle: {
|
|
type: 'dashed',
|
|
},
|
|
},
|
|
},
|
|
yAxis: {
|
|
name: '净利(千元)',
|
|
nameLocation: 'middle',
|
|
nameGap: 50,
|
|
splitLine: {
|
|
lineStyle: {
|
|
type: 'dashed',
|
|
},
|
|
},
|
|
},
|
|
series: [
|
|
{
|
|
type: 'scatter',
|
|
symbolSize: 40,
|
|
data,
|
|
itemStyle: {
|
|
color: '#6366f1',
|
|
opacity: 0.6,
|
|
},
|
|
},
|
|
],
|
|
});
|
|
};
|
|
|
|
// 监听数据变化,重新渲染图表
|
|
watch(
|
|
() => overviewData.value,
|
|
() => {
|
|
if (overviewData.value) {
|
|
// 使用 setTimeout 确保 DOM 已更新
|
|
setTimeout(() => {
|
|
renderShopBarChart();
|
|
renderShopScatterChart();
|
|
}, 100);
|
|
}
|
|
},
|
|
{ deep: true },
|
|
);
|
|
|
|
// 监听日期范围变化
|
|
watch(
|
|
() => dateRange.value,
|
|
() => {
|
|
loadOverviewData();
|
|
},
|
|
);
|
|
|
|
// 初始化
|
|
onMounted(async () => {
|
|
await loadShopCount();
|
|
await loadOverviewData();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<Page
|
|
title="全店铺经营大盘"
|
|
auto-content-height
|
|
class="bg-gradient-to-br from-rose-50 via-indigo-50 to-green-50"
|
|
>
|
|
<template #description>
|
|
<div class="font-bold text-indigo-600">
|
|
Company Dashboard · 共 {{ shopCount }} 家在营店铺
|
|
</div>
|
|
</template>
|
|
|
|
<template #extra>
|
|
<div class="flex items-center gap-4">
|
|
<!-- 汇总 ROI 和总税后盈亏 -->
|
|
<div
|
|
class="flex items-center gap-6 rounded-[2rem] border border-white/60 bg-white/50 px-6 py-3 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<div class="text-center">
|
|
<div class="text-[10px] font-bold uppercase text-slate-400">
|
|
汇总 ROI
|
|
</div>
|
|
<div class="text-lg font-black">
|
|
{{ overviewData?.totalROI?.toFixed(2) || '-' }}
|
|
</div>
|
|
</div>
|
|
<div class="h-8 w-px bg-slate-200"></div>
|
|
<div class="text-center">
|
|
<div class="text-[10px] font-bold uppercase text-slate-400">
|
|
总税后盈亏
|
|
</div>
|
|
<div class="text-lg font-black text-emerald-600">
|
|
{{
|
|
overviewData?.totalProfitAfterTax
|
|
? formatAmount(overviewData.totalProfitAfterTax)
|
|
: '-'
|
|
}}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 时间选择器组件 -->
|
|
<div
|
|
class="flex flex-wrap items-center gap-2 rounded-2xl border border-white/60 bg-white/40 p-1.5 shadow-[0_8px_32px_0_rgba(31,38,135,0.05)] backdrop-blur-[16px]"
|
|
>
|
|
<!-- 快速选择按钮 -->
|
|
<div class="flex rounded-xl bg-white/30 p-1">
|
|
<Button
|
|
:type="activeTimeRange === 'today' ? 'primary' : 'text'"
|
|
size="small"
|
|
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
|
|
:class="
|
|
activeTimeRange === 'today'
|
|
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
|
|
: ''
|
|
"
|
|
@click="switchTimeRange('today')"
|
|
>
|
|
今日
|
|
</Button>
|
|
<Button
|
|
:type="activeTimeRange === 'yesterday' ? 'primary' : 'text'"
|
|
size="small"
|
|
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
|
|
:class="
|
|
activeTimeRange === 'yesterday'
|
|
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
|
|
: ''
|
|
"
|
|
@click="switchTimeRange('yesterday')"
|
|
>
|
|
昨日
|
|
</Button>
|
|
<Button
|
|
:type="activeTimeRange === '7days' ? 'primary' : 'text'"
|
|
size="small"
|
|
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
|
|
:class="
|
|
activeTimeRange === '7days'
|
|
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
|
|
: ''
|
|
"
|
|
@click="switchTimeRange('7days')"
|
|
>
|
|
近7日
|
|
</Button>
|
|
<Button
|
|
:type="activeTimeRange === '30days' ? 'primary' : 'text'"
|
|
size="small"
|
|
class="!h-auto border-none !px-4 !py-1.5 !text-sm !font-bold"
|
|
:class="
|
|
activeTimeRange === '30days'
|
|
? '!bg-indigo-600 !text-white !shadow-[0_4px_12px_rgba(99,102,241,0.3)]'
|
|
: ''
|
|
"
|
|
@click="switchTimeRange('30days')"
|
|
>
|
|
近30日
|
|
</Button>
|
|
</div>
|
|
<!-- 分隔线 -->
|
|
<div class="mx-1 h-6 w-px bg-slate-300"></div>
|
|
<!-- 自定义时间 -->
|
|
<div
|
|
class="flex items-center gap-2 rounded-xl bg-white/30 px-3 py-1.5"
|
|
>
|
|
<span class="text-[10px] font-bold uppercase text-slate-400">
|
|
自定义
|
|
</span>
|
|
<DatePicker.RangePicker
|
|
v-model:value="customDateRange"
|
|
size="small"
|
|
format="YYYY-MM-DD"
|
|
:allow-clear="false"
|
|
class="!border-none !bg-transparent"
|
|
:class="
|
|
activeTimeRange === 'custom'
|
|
? '[&_.ant-picker-input>input]:!font-bold [&_.ant-picker-input>input]:!text-indigo-600'
|
|
: ''
|
|
"
|
|
@change="handleCustomDateRangeChange"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<Spin :spinning="loading">
|
|
<div class="mx-auto max-w-[1600px] space-y-8 p-6">
|
|
<!-- 汇总卡片 -->
|
|
<div class="grid grid-cols-1 gap-6 md:grid-cols-4">
|
|
<!-- 全店总销售额 -->
|
|
<div
|
|
class="rounded-[2rem] border border-white/60 bg-white/50 bg-gradient-to-br from-indigo-500/10 to-transparent p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<div class="text-sm font-bold text-slate-500">全店总销售额</div>
|
|
<div class="mt-1 text-3xl font-black">
|
|
{{
|
|
overviewData?.totalSalesAmount
|
|
? formatAmount(overviewData.totalSalesAmount)
|
|
: '-'
|
|
}}
|
|
</div>
|
|
<div
|
|
v-if="overviewData?.monthOverMonthGrowth !== undefined"
|
|
class="mt-4 w-fit rounded-lg bg-emerald-50 px-2 py-1 text-xs font-bold text-emerald-500"
|
|
>
|
|
{{ formatPercent(overviewData.monthOverMonthGrowth) }} 较上月同期
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 全店总单量 -->
|
|
<div
|
|
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<div class="text-sm font-bold text-slate-500">全店总单量</div>
|
|
<div class="mt-1 text-3xl font-black">
|
|
{{
|
|
overviewData?.totalOrderCount?.toLocaleString('zh-CN') || '-'
|
|
}}
|
|
</div>
|
|
<div class="mt-4 text-xs font-bold italic text-slate-400">
|
|
目标达成率 92%
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 总推广费支出 -->
|
|
<div
|
|
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<div class="text-sm font-bold text-slate-500">总推广费支出</div>
|
|
<div class="mt-1 text-3xl font-black">
|
|
{{
|
|
overviewData?.totalPromotionFee
|
|
? formatAmount(overviewData.totalPromotionFee)
|
|
: '-'
|
|
}}
|
|
</div>
|
|
<div class="mt-4 text-xs font-bold text-indigo-400">
|
|
平均费比:
|
|
{{
|
|
overviewData?.averageFeeRatio
|
|
? `${overviewData.averageFeeRatio.toFixed(1)}%`
|
|
: '-'
|
|
}}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 全店总净利 -->
|
|
<div
|
|
class="rounded-[2rem] border border-white/60 bg-white/50 bg-gradient-to-br from-emerald-500/10 to-transparent p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<div class="text-sm font-bold text-slate-500">
|
|
全店总净利 (税后)
|
|
</div>
|
|
<div class="mt-1 text-3xl font-black text-emerald-600">
|
|
{{
|
|
overviewData?.totalNetProfitAfterTax
|
|
? formatAmount(overviewData.totalNetProfitAfterTax)
|
|
: '-'
|
|
}}
|
|
</div>
|
|
<div class="mt-4 text-xs font-bold text-slate-400">
|
|
扣除总税额:
|
|
{{
|
|
overviewData?.totalTaxAmount
|
|
? formatAmount(overviewData.totalTaxAmount)
|
|
: '-'
|
|
}}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 各店对比分析 -->
|
|
<div class="grid grid-cols-1 gap-8 lg:grid-cols-2">
|
|
<!-- 店铺销售占比排行 -->
|
|
<div
|
|
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<h3 class="mb-6 text-xl font-bold">各店铺销售占比排行</h3>
|
|
<div class="h-[400px]">
|
|
<EchartsUI ref="barChartRef" />
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 店铺效率象限 -->
|
|
<div
|
|
class="rounded-[2rem] border border-white/60 bg-white/50 p-8 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<h3 class="mb-6 text-xl font-bold">店铺效率象限 (ROI vs 净利)</h3>
|
|
<div class="h-[400px]">
|
|
<EchartsUI ref="scatterChartRef" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 店铺多维度对比表 -->
|
|
<div
|
|
class="overflow-hidden rounded-[2rem] border border-white/60 bg-white/50 shadow-[0_10px_30px_rgba(0,0,0,0.02)] backdrop-blur-[20px]"
|
|
>
|
|
<div class="flex items-center justify-between p-8">
|
|
<h3 class="text-xl font-bold">多店铺数据横向对比</h3>
|
|
</div>
|
|
<div class="overflow-x-auto px-4 pb-6">
|
|
<table class="w-full border-collapse whitespace-nowrap text-left">
|
|
<thead
|
|
class="border-b border-white/40 text-[11px] uppercase text-slate-400"
|
|
>
|
|
<tr>
|
|
<th class="p-4 font-black">店铺名称</th>
|
|
<th class="p-4 font-black">销售额</th>
|
|
<th class="p-4 font-black text-indigo-600">ROI</th>
|
|
<th class="p-4 font-black text-red-400">退款/刷单费</th>
|
|
<th class="p-4 font-black">推广费总和</th>
|
|
<th class="p-4 font-black text-emerald-600">税后盈亏</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="text-sm">
|
|
<tr
|
|
v-for="shop in overviewData?.shopComparisons"
|
|
:key="shop.shopId"
|
|
class="border-t border-white/20 transition hover:bg-white/40"
|
|
>
|
|
<td class="p-4 font-bold">{{ shop.shopName }}</td>
|
|
<td class="p-4">
|
|
{{ formatAmountFull(shop.salesAmount) }}
|
|
</td>
|
|
<td class="p-4 font-black text-indigo-600">
|
|
{{ shop.roi?.toFixed(2) || '-' }}
|
|
</td>
|
|
<td class="p-4 text-red-400">
|
|
{{ formatAmountFull(shop.refundAmount || 0) }} /
|
|
{{ formatAmountFull(shop.brushFee || 0) }}
|
|
</td>
|
|
<td class="p-4">
|
|
{{
|
|
shop.totalPromotionFee
|
|
? formatAmountFull(shop.totalPromotionFee)
|
|
: '-'
|
|
}}
|
|
</td>
|
|
<td class="p-4 font-black text-emerald-600">
|
|
{{
|
|
shop.profitAfterTax
|
|
? formatAmountFull(shop.profitAfterTax)
|
|
: '-'
|
|
}}
|
|
</td>
|
|
</tr>
|
|
<tr v-if="!overviewData?.shopComparisons?.length">
|
|
<td colspan="6" class="p-8 text-center text-gray-400">
|
|
暂无数据
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Spin>
|
|
</Page>
|
|
</template>
|
|
|
|
<style scoped>
|
|
/* 自定义样式 */
|
|
</style>
|