refactor(ecom-dmb): 店铺/品类/平台概览统一改为对象结构(含后端计算的合计行)

This commit is contained in:
小蟑螂
2026-04-23 21:12:59 +08:00
parent 60e3efab81
commit c1f718ed7e
6 changed files with 278 additions and 37 deletions
@@ -23,10 +23,10 @@ export namespace CompanyOverviewVO {
shopSalesRatios?: ShopSalesRatio[];
/** 店铺效率象限(ROI vs 净利) */
shopEfficiencyQuadrants?: ShopEfficiencyQuadrant[];
/** 多店铺数据横向对比(16维度) */
shopComparisons?: ShopComparison[];
/** 多店铺数据横向对比 */
shopComparisons?: ShopOverview;
/** 多品类数据横向对比 */
categoryComparisons?: CategoryComparison[];
categoryComparisons?: CategoryOverview;
/** 平台维度概览(包含合计行和平台列表) */
platformSummary?: PlatformOverview;
/** 汇总ROI */
@@ -202,4 +202,20 @@ export namespace CompanyOverviewVO {
/** 各平台汇总列表 */
platforms: PlatformSummary[];
}
/** 多店铺概览 */
export interface ShopOverview {
/** 合计行 */
total: ShopComparison;
/** 各店铺对比列表 */
shops: ShopComparison[];
}
/** 多品类概览 */
export interface CategoryOverview {
/** 合计行 */
total: CategoryComparison;
/** 各品类对比列表 */
categories: CategoryComparison[];
}
}
@@ -6,7 +6,7 @@ import { computed } from 'vue';
defineOptions({ name: 'CategoryComparisonTable' });
interface Props {
categoryComparisons?: CompanyOverviewVO.CategoryComparison[];
categoryComparisons?: CompanyOverviewVO.CategoryOverview;
taxRate: number;
categoryExportMode?: boolean;
selectedExportCategoryIds?: number[];
@@ -26,7 +26,7 @@ const props = withDefaults(defineProps<Props>(), {
const emit = defineEmits<Emits>();
const allCategoriesSelected = computed(() => {
const total = props.categoryComparisons?.length || 0;
const total = props.categoryComparisons?.categories?.length || 0;
return total > 0 && props.selectedExportCategoryIds.length === total;
});
@@ -113,7 +113,7 @@ const formatPercentPlain = (value: number | undefined) => {
'update:selectedExportCategoryIds',
allCategoriesSelected
? []
: (categoryComparisons ?? []).map((c) => c.categoryId!)
: (categoryComparisons?.categories ?? []).map((c) => c.categoryId!)
)
"
/>
@@ -174,7 +174,7 @@ const formatPercentPlain = (value: number | undefined) => {
</thead>
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="cat in categoryComparisons"
v-for="cat in (categoryComparisons?.categories || [])"
:key="cat.categoryId ?? 'uncategorized'"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
>
@@ -237,12 +237,35 @@ const formatPercentPlain = (value: number | undefined) => {
{{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!categoryComparisons?.length">
<tr v-if="!categoryComparisons?.categories?.length">
<td :colspan="categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="categoryComparisons?.total" 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="p-6 text-base">合计</td>
<!-- 规模 -->
<td class="p-6">{{ categoryComparisons?.total?.salesAmount ? formatAmount(categoryComparisons?.total?.salesAmount) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.orderCount ? categoryComparisons?.total?.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<!-- 成本 -->
<td class="p-6">{{ categoryComparisons?.total?.productCost ? formatAmount(categoryComparisons?.total?.productCost) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.shippingCost ? formatAmount(categoryComparisons?.total?.shippingCost) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.otherCost ? formatAmount(categoryComparisons?.total?.otherCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ categoryComparisons?.total?.refundAmount ? formatAmount(categoryComparisons?.total?.refundAmount) : '-' }}</td>
<td class="p-6">{{ categoryComparisons?.total?.totalPromotionFee ? formatAmount(categoryComparisons?.total?.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ categoryComparisons?.total?.brushFee ? formatAmount(categoryComparisons?.total?.brushFee) : '-' }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categoryComparisons?.total?.feeRatio !== undefined ? formatPercentPlain(categoryComparisons?.total?.feeRatio) : '-' }}</td>
<!-- 盈利 -->
<td class="p-6">{{ categoryComparisons?.total?.totalProfitBeforeTax ? formatAmount(categoryComparisons?.total?.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ categoryComparisons?.total?.salesTaxAmount ? formatAmount(categoryComparisons?.total?.salesTaxAmount) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ categoryComparisons?.total?.roi?.toFixed(2) || '-' }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base text-emerald-600">{{ categoryComparisons?.total?.profitAfterTax ? formatAmount(categoryComparisons?.total?.profitAfterTax) : '-' }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
@@ -293,36 +293,36 @@ const sortIcon = (field: string) => {
<!-- 目标 -->
<td class="p-6">{{ totalData.targetOrderCount?.toLocaleString() }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<td class="p-6">{{ formatAmount(totalData.targetAmount) }}</td>
<td class="p-6">{{ totalData.targetAmount ? formatAmount(totalData.targetAmount) : '-' }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<!-- 规模 -->
<td class="p-6">{{ formatAmount(totalData.salesAmount) }}</td>
<td class="p-6">{{ totalData.orderCount?.toLocaleString() }}</td>
<td class="p-6">{{ totalData.salesAmount ? formatAmount(totalData.salesAmount) : '-' }}</td>
<td class="p-6">{{ totalData.orderCount ? totalData.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<!-- 成本 -->
<td class="p-6">{{ formatAmount(totalData.productCost) }}</td>
<td class="p-6">{{ formatAmount(totalData.shippingCost) }}</td>
<td class="p-6">{{ formatAmount(totalData.otherCost) }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ formatAmount(totalData.refundAmount) }}</td>
<td class="p-6">{{ formatAmount(totalData.totalPromotionFee) }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ formatAmount(totalData.brushFee) }}</td>
<td class="p-6">{{ totalData.productCost ? formatAmount(totalData.productCost) : '-' }}</td>
<td class="p-6">{{ totalData.shippingCost ? formatAmount(totalData.shippingCost) : '-' }}</td>
<td class="p-6">{{ totalData.otherCost ? formatAmount(totalData.otherCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ totalData.refundAmount ? formatAmount(totalData.refundAmount) : '-' }}</td>
<td class="p-6">{{ totalData.totalPromotionFee ? formatAmount(totalData.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ totalData.brushFee ? formatAmount(totalData.brushFee) : '-' }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ formatPercentPlain(totalData.feeRatio) }}
{{ totalData.feeRatio !== undefined ? formatPercentPlain(totalData.feeRatio) : '-' }}
</td>
<!-- 盈利 -->
<td class="p-6">
{{ formatAmount(totalData.totalProfitBeforeTax) }}
{{ totalData.totalProfitBeforeTax ? formatAmount(totalData.totalProfitBeforeTax) : '-' }}
</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
{{ formatAmount(totalData.salesTaxAmount) }}
{{ totalData.salesTaxAmount ? formatAmount(totalData.salesTaxAmount) : '-' }}
</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">
{{ totalData.roi?.toFixed(2) }}
{{ totalData.roi !== undefined ? totalData.roi.toFixed(2) : '-' }}
</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base"
:class="totalData.profitAfterTax >= 0 ? 'text-emerald-600' : 'text-rose-600'"
>
{{ formatAmount(totalData.profitAfterTax) }}
{{ totalData.profitAfterTax ? formatAmount(totalData.profitAfterTax) : '-' }}
</td>
</tr>
</tfoot>
@@ -109,7 +109,7 @@ const formatPercentPlain = (value: number | undefined) => {
if ((e.target as HTMLInputElement).checked) {
emit(
'update:selectedExportShopIds',
shopComparisons?.map((s) => s.shopId) || [],
shopComparisons?.shops?.map((s) => s.shopId) || [],
);
} else {
emit('update:selectedExportShopIds', []);
@@ -193,7 +193,7 @@ const formatPercentPlain = (value: number | undefined) => {
</thead>
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="shop in shopComparisons"
v-for="shop in (shopComparisons?.shops || [])"
:key="shop.shopId"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)] dark:bg-[hsl(217.2deg_32.6%_17.5%/50%)]"
>
@@ -328,12 +328,40 @@ const formatPercentPlain = (value: number | undefined) => {
}}
</td>
</tr>
<tr v-if="!shopComparisons?.length">
<tr v-if="!shopComparisons?.shops?.length">
<td colspan="17" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<!-- 合计行 -->
<tfoot v-if="shopComparisons?.total" 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="p-6 text-base" :class="shopExportMode ? 'border-l-0' : ''">合计</td>
<!-- 目标 -->
<td class="p-6">{{ shopComparisons?.total?.targetOrderCount?.toLocaleString() }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<td class="p-6">{{ shopComparisons?.total?.targetAmount ? formatAmount(shopComparisons?.total?.targetAmount) : '-' }}</td>
<td class="p-6 text-blue-600 dark:text-blue-400">-</td>
<!-- 规模 -->
<td class="p-6">{{ shopComparisons?.total?.salesAmount ? formatAmount(shopComparisons?.total?.salesAmount) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.orderCount ? shopComparisons?.total?.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<!-- 成本 -->
<td class="p-6">{{ shopComparisons?.total?.productCost ? formatAmount(shopComparisons?.total?.productCost) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.shippingCost ? formatAmount(shopComparisons?.total?.shippingCost) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.otherCost ? formatAmount(shopComparisons?.total?.otherCost) : '-' }}</td>
<td class="p-6 text-rose-600 dark:text-rose-400">{{ shopComparisons?.total?.refundAmount ? formatAmount(shopComparisons?.total?.refundAmount) : '-' }}</td>
<td class="p-6">{{ shopComparisons?.total?.totalPromotionFee ? formatAmount(shopComparisons?.total?.totalPromotionFee) : '-' }}</td>
<td class="p-6 text-orange-600 dark:text-orange-400">{{ shopComparisons?.total?.brushFee ? formatAmount(shopComparisons?.total?.brushFee) : '-' }}</td>
<td class="p-6 text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopComparisons?.total?.feeRatio !== undefined ? formatPercentPlain(shopComparisons?.total?.feeRatio) : '-' }}</td>
<!-- 盈利 -->
<td class="p-6">{{ shopComparisons?.total?.totalProfitBeforeTax ? formatAmount(shopComparisons?.total?.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">{{ shopComparisons?.total?.salesTaxAmount ? formatAmount(shopComparisons?.total?.salesTaxAmount) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ shopComparisons?.total?.roi !== undefined ? shopComparisons?.total?.roi.toFixed(2) : '-' }}</td>
<td class="bg-emerald-100 dark:bg-emerald-900/30 p-6 text-base text-emerald-600">{{ shopComparisons?.total?.profitAfterTax ? formatAmount(shopComparisons?.total?.profitAfterTax) : '-' }}</td>
</tr>
</tfoot>
</table>
</div>
</div>