mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 03:09:19 +08:00
feat: 忘了干啥了
This commit is contained in:
@@ -1,806 +0,0 @@
|
||||
<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.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 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).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?.shopEfficiencyQuadrants)
|
||||
return;
|
||||
|
||||
const quadrants = overviewData.value.shopEfficiencyQuadrants;
|
||||
const data = quadrants.map((q) => [
|
||||
q.roi,
|
||||
q.netProfit / 10_000, // 转换为万元
|
||||
q.shopName,
|
||||
]);
|
||||
|
||||
renderScatterChart({
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
formatter: (params: any) => {
|
||||
const shop = quadrants[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: {
|
||||
name: '投资回报率 (ROI)',
|
||||
nameLocation: 'middle',
|
||||
nameGap: 35,
|
||||
axisLabel: { fontWeight: 'bold' },
|
||||
splitLine: {
|
||||
lineStyle: { type: 'dashed' },
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
name: '税后净利润 (单位: 万元)',
|
||||
nameLocation: 'middle',
|
||||
nameGap: 50,
|
||||
axisLabel: { fontWeight: 'bold' },
|
||||
splitLine: {
|
||||
lineStyle: { type: 'dashed' },
|
||||
},
|
||||
},
|
||||
series: [
|
||||
{
|
||||
type: 'scatter',
|
||||
symbolSize: 45,
|
||||
data,
|
||||
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,
|
||||
() => {
|
||||
loadOverviewData();
|
||||
},
|
||||
);
|
||||
|
||||
// 初始化
|
||||
onMounted(async () => {
|
||||
await loadShopCount();
|
||||
await loadOverviewData();
|
||||
});
|
||||
</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 items-center gap-2 rounded-2xl border border-slate-200 bg-slate-200/50 p-1.5"
|
||||
>
|
||||
<!-- 快速选择按钮组 -->
|
||||
<div class="flex items-center gap-1 rounded-xl bg-white/30 p-1">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
class="!h-auto !min-w-0 !rounded-xl !border-none !px-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
|
||||
: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-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
|
||||
: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-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
|
||||
: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-5 !py-2 !text-sm !font-bold !shadow-none !transition-colors"
|
||||
: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="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-xs font-bold text-slate-400">自定义日期</span>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="customDateRange"
|
||||
size="small"
|
||||
format="YYYY-MM-DD"
|
||||
:allow-clear="false"
|
||||
:placeholder="['开始日期', '结束日期']"
|
||||
class="!border-none !bg-transparent !text-sm !font-bold"
|
||||
@change="handleCustomDateRangeChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Spin :spinning="loading">
|
||||
<div class="mx-auto w-full space-y-6 p-4 md:p-8">
|
||||
<!-- 第一层:核心汇总指标 -->
|
||||
<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>已扣除预扣税额 (4%)</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>
|
||||
<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"
|
||||
>
|
||||
导出财务分析报表
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="table-container overflow-x-auto">
|
||||
<table class="w-full whitespace-nowrap text-left text-sm">
|
||||
<!-- 表头分组 -->
|
||||
<thead
|
||||
class="bg-slate-50 text-[11px] font-black uppercase text-slate-500"
|
||||
>
|
||||
<tr>
|
||||
<th
|
||||
rowspan="2"
|
||||
class="sticky-col border-b p-6 text-sm font-black text-slate-900 shadow-sm"
|
||||
>
|
||||
店铺名称
|
||||
</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">
|
||||
<!-- 目标 -->
|
||||
<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 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">
|
||||
4%税额
|
||||
</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
|
||||
class="sticky-col border-r-2 border-slate-100 bg-white p-6 font-bold text-slate-900 shadow-sm"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</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.shippingCost ? formatAmount(shop.shippingCost) : '-'
|
||||
}}
|
||||
</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;
|
||||
}
|
||||
</style>
|
||||
@@ -235,9 +235,7 @@ onUnmounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="h-full overflow-hidden bg-gradient-to-br from-indigo-100 via-pink-100 to-slate-100 p-8"
|
||||
>
|
||||
<div class="h-full overflow-hidden bg-slate-100 p-8">
|
||||
<div class="mx-auto flex h-full w-[60%] flex-col overflow-hidden">
|
||||
<!-- 头部标题 -->
|
||||
<div class="mb-12 shrink-0 text-center">
|
||||
@@ -254,10 +252,8 @@ onUnmounted(() => {
|
||||
v-if="csvData.length === 0"
|
||||
class="flex min-h-0 flex-1 flex-col overflow-hidden"
|
||||
>
|
||||
<div
|
||||
class="mb-8 grid shrink-0 grid-cols-1 gap-6 lg:grid-cols-[2fr_1fr]"
|
||||
>
|
||||
<!-- 左侧:导入区域 -->
|
||||
<div class="mb-8 shrink-0">
|
||||
<!-- 导入区域 -->
|
||||
<div
|
||||
class="relative flex min-h-[400px] flex-col items-center justify-center overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-8 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] backdrop-blur-2xl"
|
||||
>
|
||||
@@ -273,68 +269,6 @@ onUnmounted(() => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧:指引与历史 -->
|
||||
<div class="flex flex-col gap-6">
|
||||
<!-- 操作指南卡片 -->
|
||||
<div
|
||||
class="relative flex flex-col gap-4 overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-6 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] backdrop-blur-2xl"
|
||||
>
|
||||
<h3 class="m-0 text-base font-bold text-slate-800">操作指南</h3>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex items-start gap-3">
|
||||
<div
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-indigo-600 text-xs font-bold text-white"
|
||||
>
|
||||
1
|
||||
</div>
|
||||
<p
|
||||
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
|
||||
>
|
||||
从电商后台导出【订单详情】CSV文件
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-start gap-3">
|
||||
<div
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-indigo-100 bg-white text-xs font-bold text-indigo-600"
|
||||
>
|
||||
2
|
||||
</div>
|
||||
<p
|
||||
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
|
||||
>
|
||||
检查文件是否包含【订单号】与【金额】列
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-start gap-3">
|
||||
<div
|
||||
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-indigo-100 bg-white text-xs font-bold text-indigo-600"
|
||||
>
|
||||
3
|
||||
</div>
|
||||
<p
|
||||
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
|
||||
>
|
||||
上传成功后,系统将自动解析并显示数据
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部全局按钮 -->
|
||||
<div class="flex justify-center gap-4 pt-4">
|
||||
<Button :disabled="csvData.length === 0" @click="handleClearData">
|
||||
清空当前选择
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="csvHeaders.length === 0"
|
||||
@click="handleCreateImportTask"
|
||||
>
|
||||
创建导入任务
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -342,7 +276,7 @@ onUnmounted(() => {
|
||||
<div v-else class="flex min-h-0 w-full flex-1 flex-col overflow-hidden">
|
||||
<div
|
||||
class="mb-6 flex shrink-0 flex-wrap items-start justify-between gap-4"
|
||||
>
|
||||
>
|
||||
<div class="flex-1">
|
||||
<h2 class="mb-1 text-2xl font-bold text-slate-800">数据预览</h2>
|
||||
<p class="m-0 text-sm text-slate-500">
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ const handleDelete = (product: ProductVO.Info) => {
|
||||
</span>
|
||||
</div>
|
||||
<span class="ml-4 font-semibold text-red-500 dark:text-red-400">
|
||||
¥{{ spec.costPrice.toFixed(2) }}
|
||||
¥{{ spec.productCost.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+112
-69
@@ -17,7 +17,7 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { createProductApi, updateProductApi } from '#/api/ecommerce/product';
|
||||
import { uploadImageApi } from '#/api/media/image';
|
||||
import { uploadFileToOss } from '#/utils/oss-upload';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
@@ -30,9 +30,9 @@ const emit = defineEmits<Emits>();
|
||||
// 创建Vben Modal实例
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '添加商品',
|
||||
class: 'w-[800px]',
|
||||
class: 'w-[1000px]',
|
||||
draggable: true, // 开启拖拽
|
||||
contentClass: 'px-6 py-4',
|
||||
contentClass: 'px-5 py-4',
|
||||
onConfirm: handleSubmit,
|
||||
onCancel: close,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
@@ -67,10 +67,7 @@ const imageLoadError = ref(false); // 图片加载错误状态
|
||||
const formData = ref({
|
||||
name: '',
|
||||
productCode: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined as number | undefined,
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 规格数据 - 支持创建和更新
|
||||
@@ -88,30 +85,17 @@ const currentImageUrl = computed(() => {
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentProductData.value) {
|
||||
// 编辑模式
|
||||
// 注意:ProductVO.Info 中可能没有 specCode、skuCode、costPrice 字段
|
||||
// 这些字段可能需要在编辑时从其他地方获取或设置为空
|
||||
const productData = currentProductData.value as any;
|
||||
formData.value = {
|
||||
name: currentProductData.value.name || '',
|
||||
productCode: currentProductData.value.productCode || '',
|
||||
specCode: productData.specCode || '',
|
||||
skuCode: productData.skuCode || '',
|
||||
mainImageId: undefined,
|
||||
costPrice: productData.costPrice ?? 0,
|
||||
};
|
||||
|
||||
// 设置原始图片 URL
|
||||
originalImageUrl.value = currentProductData.value.mainImage || '';
|
||||
} else {
|
||||
// 创建模式 - 如果有传入的productData,则使用它来初始化表单
|
||||
formData.value = {
|
||||
name: currentProductData.value?.name || '',
|
||||
productCode: currentProductData.value?.productCode || '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined,
|
||||
costPrice: 0,
|
||||
};
|
||||
originalImageUrl.value = currentProductData.value?.mainImage || '';
|
||||
}
|
||||
@@ -130,25 +114,25 @@ function initFormData() {
|
||||
'specs' in currentProductData.value &&
|
||||
currentProductData.value.specs
|
||||
) {
|
||||
if (isEdit.value) {
|
||||
// 编辑模式:使用 UpdateSpec 格式,包含 id
|
||||
specs.value = currentProductData.value.specs.map(
|
||||
(spec) =>
|
||||
({
|
||||
id: (spec as ProductVO.SpecInfo).id,
|
||||
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0,
|
||||
}) as ProductDTO.UpdateSpec,
|
||||
);
|
||||
} else {
|
||||
// 创建模式:使用 Spec 格式
|
||||
specs.value = currentProductData.value.specs.map((spec) => ({
|
||||
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0,
|
||||
}));
|
||||
}
|
||||
const mapSpec = (spec: ProductVO.SpecInfo) => ({
|
||||
name: spec.name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
productCost: spec.productCost ?? 0,
|
||||
shippingCost: spec.shippingCost ?? 0,
|
||||
otherCost: spec.otherCost ?? 0,
|
||||
remark: spec.remark || '',
|
||||
});
|
||||
specs.value = isEdit.value
|
||||
? currentProductData.value.specs.map(
|
||||
(spec) =>
|
||||
({
|
||||
id: (spec as ProductVO.SpecInfo).id,
|
||||
...mapSpec(spec as ProductVO.SpecInfo),
|
||||
}) as ProductDTO.UpdateSpec,
|
||||
)
|
||||
: currentProductData.value.specs.map((spec) =>
|
||||
mapSpec(spec as ProductVO.SpecInfo),
|
||||
);
|
||||
showSpecs.value = specs.value.length > 0;
|
||||
}
|
||||
}
|
||||
@@ -305,22 +289,21 @@ function removeNewImage() {
|
||||
message.success('已重置图片');
|
||||
}
|
||||
|
||||
const defaultSpec = (): ProductDTO.Spec => ({
|
||||
name: '',
|
||||
specCode: '',
|
||||
productCost: 0,
|
||||
shippingCost: 0,
|
||||
otherCost: 0,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 添加规格
|
||||
function addSpec() {
|
||||
if (isEdit.value) {
|
||||
// 编辑模式:新增的规格暂时不包含id,服务器端会识别并创建新规格
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
} as ProductDTO.Spec);
|
||||
specs.value.push(defaultSpec() as ProductDTO.Spec);
|
||||
} else {
|
||||
// 创建模式
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
specs.value.push(defaultSpec());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +318,7 @@ const specColumns = [
|
||||
title: '规格名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: '30%',
|
||||
width: 300,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
@@ -354,7 +337,7 @@ const specColumns = [
|
||||
title: '规格编码',
|
||||
dataIndex: 'specCode',
|
||||
key: 'specCode',
|
||||
width: '30%',
|
||||
width: 140,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
@@ -370,23 +353,86 @@ const specColumns = [
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '成本价',
|
||||
dataIndex: 'costPrice',
|
||||
key: 'costPrice',
|
||||
width: '25%',
|
||||
title: '商品成本',
|
||||
dataIndex: 'productCost',
|
||||
key: 'productCost',
|
||||
width: 100,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.costPrice,
|
||||
placeholder: '请输入成本价',
|
||||
value: record.productCost,
|
||||
placeholder: '商品成本',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.costPrice = value ?? 0;
|
||||
record.productCost = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '运费成本',
|
||||
dataIndex: 'shippingCost',
|
||||
key: 'shippingCost',
|
||||
width: 90,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.shippingCost ?? 0,
|
||||
placeholder: '运费',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.shippingCost = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '其他成本',
|
||||
dataIndex: 'otherCost',
|
||||
key: 'otherCost',
|
||||
width: 90,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.otherCost ?? 0,
|
||||
placeholder: '其他',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.otherCost = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 100,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: ProductDTO.Spec | ProductDTO.UpdateSpec;
|
||||
}) => {
|
||||
return h(Input, {
|
||||
value: record.remark ?? '',
|
||||
placeholder: '备注',
|
||||
'onUpdate:value': (value: string) => {
|
||||
record.remark = value ?? '';
|
||||
},
|
||||
});
|
||||
},
|
||||
@@ -394,7 +440,7 @@ const specColumns = [
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: '15%',
|
||||
width: 80,
|
||||
align: 'center' as const,
|
||||
customRender: ({ index }: { index: number }) => {
|
||||
return h(
|
||||
@@ -421,11 +467,13 @@ async function uploadImageAndGetId(): Promise<number | undefined> {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadImageApi(newImageFile.value);
|
||||
return response.id;
|
||||
const fileInfo = await uploadFileToOss(newImageFile.value, {
|
||||
category: 'product-main-image',
|
||||
errorMessage: '主图上传失败',
|
||||
});
|
||||
return fileInfo.id;
|
||||
} catch (error) {
|
||||
console.error('图片上传失败:', error);
|
||||
message.error('图片上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -448,12 +496,7 @@ onUnmounted(() => {
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form ref="formRef" :model="formData">
|
||||
<Form.Item label="商品主图" name="mainImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px">
|
||||
<!-- 主图预览区域 -->
|
||||
|
||||
+1
-1
@@ -335,7 +335,7 @@ defineExpose({
|
||||
white-space: nowrap;
|
||||
"
|
||||
>
|
||||
¥{{ spec.costPrice.toFixed(2) }}
|
||||
¥{{ spec.productCost.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+13
-15
@@ -8,11 +8,8 @@ import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createShopApi,
|
||||
updateShopApi,
|
||||
uploadShopLogoApi,
|
||||
} from '#/api/ecommerce/shop';
|
||||
import { createShopApi, updateShopApi } from '#/api/ecommerce/shop';
|
||||
import { uploadFileToOss } from '#/utils/oss-upload';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
@@ -230,11 +227,13 @@ async function uploadLogoAndGetId(): Promise<number | undefined> {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadShopLogoApi(newLogoFile.value);
|
||||
return response.id;
|
||||
const fileInfo = await uploadFileToOss(newLogoFile.value, {
|
||||
category: 'shop-logo',
|
||||
errorMessage: 'Logo上传失败',
|
||||
});
|
||||
return fileInfo.id;
|
||||
} catch (error) {
|
||||
console.error('Logo上传失败:', error);
|
||||
message.error('Logo上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -256,13 +255,12 @@ onUnmounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Modal
|
||||
:title="modalTitle"
|
||||
:confirm-loading="loading"
|
||||
content-class="px-5 py-4"
|
||||
>
|
||||
<Form ref="formRef" :model="formData">
|
||||
<Form.Item label="店铺Logo" name="logoImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px">
|
||||
<!-- Logo预览区域 -->
|
||||
|
||||
@@ -227,7 +227,7 @@ function handleModalSuccess() {
|
||||
|
||||
// 处理查看详情
|
||||
function handleViewDetails(record: ShopVO.Info) {
|
||||
router.push(`/ecom/shop/details/${record.id}`);
|
||||
router.push(`/ecom/shop/overview/${record.id}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -267,6 +267,48 @@ watch(
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
// 检查查询参数,如果有则设置时间范围
|
||||
const query = route.query;
|
||||
if (query.startDate && query.endDate) {
|
||||
const startDate = dayjs(query.startDate as string);
|
||||
const endDate = dayjs(query.endDate as string);
|
||||
const today = dayjs();
|
||||
|
||||
if (startDate.isValid() && endDate.isValid()) {
|
||||
dateRange.value = [startDate, endDate];
|
||||
// 判断时间范围类型
|
||||
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';
|
||||
} else if (
|
||||
daysDiff === 0 &&
|
||||
startDate.isSame(dayjs().subtract(1, 'day'), 'day')
|
||||
) {
|
||||
activeTimeRange.value = 'yesterday';
|
||||
} else if (isEndDateToday && isStartDate7DaysAgo) {
|
||||
// 近7天:从7天前到今天
|
||||
activeTimeRange.value = '7days';
|
||||
} else if (isEndDateToday && isStartDate30DaysAgo) {
|
||||
// 近30天:从30天前到今天
|
||||
activeTimeRange.value = '30days';
|
||||
} else {
|
||||
activeTimeRange.value = 'custom';
|
||||
customDateRange.value = [startDate, endDate];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置完时间范围后再加载数据
|
||||
if (shopId.value) {
|
||||
loadOverviewData();
|
||||
}
|
||||
@@ -274,7 +316,11 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="店铺经营概览" auto-content-height class="bg-[#f8fafc]">
|
||||
<Page
|
||||
:title="overviewData?.shopName || '店铺经营概览'"
|
||||
auto-content-height
|
||||
class="bg-[#f8fafc]"
|
||||
>
|
||||
<template #description>
|
||||
<div class="mt-1 text-sm font-bold italic text-slate-500">
|
||||
数据更新于:{{ dayjs().format('今日 HH:mm:ss') }}
|
||||
|
||||
Reference in New Issue
Block a user