feat(ecom): 产品概况同步增加总成本字段

- ProductOverviewVO.SpecSummaryItem 和 SpecSummaryTotal 新增 totalCost 字段
- ShopOverviewStatisticsVO 也新增 totalCost
- ProductOverviewServiceImpl / ShopOverviewStatisticsServiceImpl 计算并赋值总成本
- 前端 types.vo.ts 及各表格组件同步展示
This commit is contained in:
小蟑螂
2026-05-05 12:14:42 +08:00
parent 44662a4790
commit 31dc0cb2a1
11 changed files with 108 additions and 36 deletions
@@ -37,6 +37,8 @@ export namespace ProductOverviewVO {
shippingCost: number;
/** 其他成本 */
otherCost: number;
/** 总成本(商品成本+运费+其他成本) */
totalCost?: number;
/** 退款金额 */
refundAmount: number;
/** 推广费 */
@@ -67,6 +69,8 @@ export namespace ProductOverviewVO {
shippingCost: number;
/** 其他成本 */
otherCost: number;
/** 总成本(商品成本+运费+其他成本) */
totalCost?: number;
/** 退款金额 */
refundAmount: number;
/** 推广费 */
@@ -123,6 +123,8 @@ export namespace ShopVO {
shippingCost?: number;
/** 其他成本 */
otherCost?: number;
/** 总成本(商品成本+运费+其他成本) */
totalCost?: number;
/** 退款金额 */
refundAmount?: number;
/** 推广费 */
@@ -159,6 +161,8 @@ export namespace ShopVO {
shippingCost?: number;
/** 其他成本 */
otherCost?: number;
/** 总成本(商品成本+运费+其他成本) */
totalCost?: number;
/** 退款金额 */
refundAmount?: number;
/** 推广费 */
@@ -1,4 +1,8 @@
<script lang="ts" setup>
import type { ProductOverviewVO } from '#/api/ecommerce/product-overview';
import { computed } from 'vue';
interface SpecData {
specId: number;
specName: string;
@@ -10,6 +14,7 @@ interface SpecData {
productCost: number;
shippingCost: number;
otherCost: number;
totalCost?: number;
refundAmount: number;
promotionFee: number;
feeRatio: number;
@@ -21,11 +26,14 @@ interface SpecData {
interface Props {
data: SpecData[];
/** 后端合计行(含 totalCost),优先展示 */
footerTotal?: ProductOverviewVO.SpecSummaryTotal | null;
taxRate?: number;
}
const props = withDefaults(defineProps<Props>(), {
taxRate: 4,
footerTotal: null,
});
const formatAmount = (amount: number | undefined) => {
@@ -43,8 +51,8 @@ const formatCount = (value: number | undefined) => {
return value.toLocaleString('zh-CN');
};
// 计算合计
const totalData = () => {
/** 无后端合计时由行数据汇总(兼容旧数据) */
const computedFooter = computed(() => {
if (!props.data || props.data.length === 0) return null;
const total: SpecData = {
specId: 0,
@@ -56,6 +64,7 @@ const totalData = () => {
productCost: 0,
shippingCost: 0,
otherCost: 0,
totalCost: 0,
refundAmount: 0,
promotionFee: 0,
feeRatio: 0,
@@ -71,6 +80,10 @@ const totalData = () => {
total.productCost += item.productCost || 0;
total.shippingCost += item.shippingCost || 0;
total.otherCost += item.otherCost || 0;
const lineTotalCost =
item.totalCost ??
(item.productCost || 0) + (item.shippingCost || 0) + (item.otherCost || 0);
total.totalCost = (total.totalCost || 0) + lineTotalCost;
total.refundAmount += item.refundAmount || 0;
total.promotionFee += item.promotionFee || 0;
total.profitBeforeTax += item.profitBeforeTax || 0;
@@ -80,10 +93,16 @@ const totalData = () => {
if (total.salesAmount > 0) {
total.averageOrderValue = total.salesAmount / total.orderCount;
total.feeRatio = (total.promotionFee / total.salesAmount) * 100;
total.roi = total.profitAfterTax / (total.productCost + total.shippingCost + total.otherCost + total.promotionFee) * 100;
const costBase = total.totalCost ?? total.productCost + total.shippingCost + total.otherCost;
total.roi =
costBase + total.promotionFee > 0
? (total.profitAfterTax / (costBase + total.promotionFee)) * 100
: 0;
}
return total;
};
});
const footerRow = computed(() => props.footerTotal ?? computedFooter.value);
</script>
<template>
@@ -120,7 +139,7 @@ const totalData = () => {
经营规模
</th>
<th
colspan="6"
colspan="7"
class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50%)] p-3 text-center text-orange-700 dark:text-orange-400"
>
成本费用
@@ -141,6 +160,7 @@ const totalData = () => {
<th class="border-b border-l px-5 py-3">商品成本</th>
<th class="border-b px-5 py-3">运费</th>
<th class="border-b px-5 py-3">其他成本</th>
<th class="border-b px-5 py-3 font-bold text-orange-800 dark:text-orange-300">总成本</th>
<th class="border-b px-5 py-3 font-bold text-rose-600 dark:text-rose-400">退款金额</th>
<th class="border-b px-5 py-3">推广费</th>
<th class="border-b px-5 py-3 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">费比 %</th>
@@ -174,6 +194,9 @@ const totalData = () => {
<td class="p-5">{{ item.productCost ? formatAmount(item.productCost) : '-' }}</td>
<td class="p-5">{{ item.shippingCost ? formatAmount(item.shippingCost) : '-' }}</td>
<td class="p-5">{{ item.otherCost ? formatAmount(item.otherCost) : '-' }}</td>
<td class="p-5 font-bold text-orange-800 dark:text-orange-300">
{{ item.totalCost != null ? formatAmount(item.totalCost) : '-' }}
</td>
<td class="p-5 font-bold text-rose-600 dark:text-rose-400">
{{ item.refundAmount ? formatAmount(item.refundAmount) : '-' }}
</td>
@@ -190,29 +213,32 @@ const totalData = () => {
</td>
</tr>
<tr v-if="!data || data.length === 0">
<td colspan="15" class="p-8 text-center text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">暂无规格数据</td>
<td colspan="16" class="p-8 text-center text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">暂无规格数据</td>
</tr>
</tbody>
<tfoot v-if="totalData()" class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tfoot v-if="footerRow" class="bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td class="border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] p-5 text-base">合计</td>
<td class="p-5">{{ formatAmount(totalData()!.salesAmount) }}</td>
<td class="p-5">{{ formatAmount(footerRow.salesAmount) }}</td>
<td class="p-5">
<span>{{ formatCount(totalData()!.orderCount) }}</span>
<span>{{ formatCount(footerRow.orderCount) }}</span>
<span class="ml-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">单</span>
<span class="ml-2 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">({{ formatCount(totalData()!.quantity) }}件)</span>
<span class="ml-2 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">({{ formatCount(footerRow.quantity) }}件)</span>
</td>
<td class="p-5">-</td>
<td class="p-5">{{ formatAmount(totalData()!.productCost) }}</td>
<td class="p-5">{{ formatAmount(totalData()!.shippingCost) }}</td>
<td class="p-5">{{ formatAmount(totalData()!.otherCost) }}</td>
<td class="p-5 text-rose-600 dark:text-rose-400">{{ formatAmount(totalData()!.refundAmount) }}</td>
<td class="p-5">{{ formatAmount(totalData()!.promotionFee) }}</td>
<td class="p-5 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatPercent(totalData()!.feeRatio) }}</td>
<td class="p-5">{{ formatAmount(totalData()!.profitBeforeTax) }}</td>
<td class="p-5 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatAmount(totalData()!.salesTaxAmount) }}</td>
<td class="p-5 text-indigo-700 dark:text-indigo-400">{{ totalData()!.roi ? totalData()!.roi.toFixed(2) : '-' }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-5 text-base text-emerald-600 dark:text-emerald-400">{{ formatAmount(totalData()!.profitAfterTax) }}</td>
<td class="p-5">{{ formatAmount(footerRow.productCost) }}</td>
<td class="p-5">{{ formatAmount(footerRow.shippingCost) }}</td>
<td class="p-5">{{ formatAmount(footerRow.otherCost) }}</td>
<td class="p-5 font-bold text-orange-800 dark:text-orange-300">
{{ footerRow.totalCost != null ? formatAmount(footerRow.totalCost) : formatAmount((footerRow.productCost || 0) + (footerRow.shippingCost || 0) + (footerRow.otherCost || 0)) }}
</td>
<td class="p-5 text-rose-600 dark:text-rose-400">{{ formatAmount(footerRow.refundAmount) }}</td>
<td class="p-5">{{ formatAmount(footerRow.promotionFee) }}</td>
<td class="p-5 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatPercent(footerRow.feeRatio) }}</td>
<td class="p-5">{{ formatAmount(footerRow.profitBeforeTax) }}</td>
<td class="p-5 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ formatAmount(footerRow.salesTaxAmount) }}</td>
<td class="p-5 text-indigo-700 dark:text-indigo-400">{{ footerRow.roi ? footerRow.roi.toFixed(2) : '-' }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-5 text-base text-emerald-600 dark:text-emerald-400">{{ formatAmount(footerRow.profitAfterTax) }}</td>
</tr>
</tfoot>
</table>
@@ -238,4 +264,4 @@ const totalData = () => {
background: #e2e8f0;
border-radius: 10px;
}
</style>
</style>
@@ -164,7 +164,8 @@ const pageTitle = computed(() => overviewData.value?.productName || '商品概
<!-- 第三层:规格销售汇总 -->
<SpecSummaryTable
:data="overviewData?.specSummaries?.list"
:data="overviewData?.specSummaries?.list ?? []"
:footer-total="overviewData?.specSummaries?.total"
:tax-rate="taxRate"
/>
</div>
@@ -127,7 +127,7 @@ const formatPercentPlain = (value: number | undefined) => {
<th colspan="3" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-slate-100/50 dark:bg-[hsl(240deg_3.7%_22%/50)] p-3 text-center">
经营规模维度
</th>
<th colspan="7" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50)] p-3 text-center italic text-orange-700 dark:text-orange-400">
<th colspan="8" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50)] p-3 text-center italic text-orange-700 dark:text-orange-400">
成本费用维度
</th>
<th colspan="5" class="border-b border-l border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-l-[hsl(240deg_3.7%_22%)] bg-emerald-50/50 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-3 text-center italic text-emerald-700 dark:text-emerald-400">
@@ -141,6 +141,7 @@ const formatPercentPlain = (value: number | undefined) => {
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">商品成本</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">运费</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">其他成本</th>
<th class="border-b px-6 py-4 font-bold text-orange-800 dark:text-orange-300 dark:bg-[hsl(24deg_9.8%_15%/50%)]">总成本</th>
<th class="border-b px-6 py-4 font-bold text-rose-600 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-rose-400">退款金额</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(24deg_9.8%_15%/50%)]">推广费</th>
<th class="border-b px-6 py-4 text-orange-600 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-orange-400">刷单费用</th>
@@ -180,6 +181,7 @@ const formatPercentPlain = (value: number | undefined) => {
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.productCost ? formatAmount(cat.productCost) : '-' }}</td>
<td class="p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.shippingCost ? formatAmount(cat.shippingCost) : '-' }}</td>
<td class="p-6 text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">{{ cat.otherCost ? formatAmount(cat.otherCost) : '-' }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ cat.totalCost != null ? formatAmount(cat.totalCost) : '-' }}</td>
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 font-bold text-rose-600 dark:text-rose-400">{{ cat.refundAmount ? formatAmount(cat.refundAmount) : '-' }}</td>
<td class="p-6 text-amber-600 dark:text-amber-400">{{ cat.totalPromotionFee ? formatAmount(cat.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ cat.brushFee ? formatAmount(cat.brushFee) : '-' }}</td>
@@ -195,7 +197,7 @@ const formatPercentPlain = (value: number | undefined) => {
</td>
</tr>
<tr v-if="!props.data?.categoryOverview?.categories?.length">
<td :colspan="props.categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
<td :colspan="props.categoryExportMode ? 17 : 16" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
@@ -210,6 +212,7 @@ const formatPercentPlain = (value: number | undefined) => {
<td class="p-6">{{ props.data.categoryOverview.total.productCost ? formatAmount(props.data.categoryOverview.total.productCost) : '-' }}</td>
<td class="p-6">{{ props.data.categoryOverview.total.shippingCost ? formatAmount(props.data.categoryOverview.total.shippingCost) : '-' }}</td>
<td class="p-6">{{ props.data.categoryOverview.total.otherCost ? formatAmount(props.data.categoryOverview.total.otherCost) : '-' }}</td>
<td class="p-6 font-bold text-orange-800 dark:text-orange-300">{{ props.data.categoryOverview.total.totalCost != null ? formatAmount(props.data.categoryOverview.total.totalCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ props.data.categoryOverview.total.refundAmount ? formatAmount(props.data.categoryOverview.total.refundAmount) : '-' }}</td>
<td class="p-6">{{ props.data.categoryOverview.total.totalPromotionFee ? formatAmount(props.data.categoryOverview.total.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ props.data.categoryOverview.total.brushFee ? formatAmount(props.data.categoryOverview.total.brushFee) : '-' }}</td>
@@ -63,6 +63,7 @@ const formatPercentPlain = (value: number | undefined) => {
<col style="width: 110px; min-width: 110px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 110px; min-width: 110px;" />
<col style="width: 100px; min-width: 100px;" />
<col style="width: 110px; min-width: 110px;" />
@@ -89,7 +90,7 @@ const formatPercentPlain = (value: number | undefined) => {
商品规模 (Scale)
</th>
<th
colspan="6"
colspan="7"
class="border-b border-l border-slate-200 dark:border-b dark:border-l dark:border-[hsl(240deg_3.7%_22%)] bg-orange-50/50 dark:bg-[hsl(24deg_9.8%_15%/50)] px-3 py-3 text-center italic text-orange-700 dark:text-orange-400"
>
费用成本 (Costs)
@@ -108,6 +109,7 @@ const formatPercentPlain = (value: number | undefined) => {
<th class="border-b border-l dark:border-l dark:border-[hsl(240deg_3.7%_22%)] 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-orange-800 dark:text-orange-300">总成本</th>
<th class="border-b px-6 py-4 text-rose-600">退款金额</th>
<th class="border-b px-6 py-4">推广费</th>
<th class="border-b px-6 py-4">刷单费用</th>
@@ -148,6 +150,9 @@ const formatPercentPlain = (value: number | undefined) => {
<td class="px-6 py-4">{{ product.productCost ? formatAmount(product.productCost) : '-' }}</td>
<td class="px-6 py-4">{{ product.shippingCost ? formatAmount(product.shippingCost) : '-' }}</td>
<td class="px-6 py-4">{{ product.otherCost ? formatAmount(product.otherCost) : '-' }}</td>
<td class="px-6 py-4 font-bold text-orange-800 dark:text-orange-300">
{{ product.totalCost != null ? formatAmount(product.totalCost) : '-' }}
</td>
<td class="px-6 py-4 font-bold text-rose-500 dark:text-rose-400">
{{ product.refundAmount ? formatAmount(product.refundAmount) : '-' }}
</td>
@@ -175,7 +180,7 @@ const formatPercentPlain = (value: number | undefined) => {
</td>
</tr>
<tr v-if="!data?.productOverview?.products?.length">
<td colspan="15" class="p-8 text-center text-gray-400">
<td colspan="16" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
@@ -189,6 +194,7 @@ const formatPercentPlain = (value: number | undefined) => {
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.productCost ? formatAmount(data.productOverview.total.productCost) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.shippingCost ? formatAmount(data.productOverview.total.shippingCost) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.otherCost ? formatAmount(data.productOverview.total.otherCost) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 font-bold text-orange-800 dark:text-orange-300 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.totalCost != null ? formatAmount(data.productOverview.total.totalCost) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 text-rose-500 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-rose-400 px-6 py-4">{{ data.productOverview.total.refundAmount ? formatAmount(data.productOverview.total.refundAmount) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.totalPromotionFee ? formatAmount(data.productOverview.total.totalPromotionFee) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 text-amber-500 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-amber-400 px-6 py-4">{{ data.productOverview.total.brushFee ? formatAmount(data.productOverview.total.brushFee) : '-' }}</td>