refactor(ecom-dmb): 店铺概览商品/品类对比表改为对象结构含合计行

This commit is contained in:
小蟑螂
2026-04-23 21:30:48 +08:00
parent c1f718ed7e
commit 85cce1ff7a
6 changed files with 237 additions and 26 deletions
@@ -149,10 +149,10 @@ export namespace ShopVO {
salesAmountTrend?: TrendData;
/** 单量趋势分析 */
orderCountTrend?: TrendData;
/** 多商品数据横向对比 */
productComparisons?: ProductComparison[];
/** 品类多维度数据对比 */
categoryComparisons?: CategoryComparison[];
/** 多商品数据横向对比(含合计行) */
productOverview?: ProductOverview;
/** 品类多维度数据对比(含合计行) */
categoryOverview?: CategoryOverview;
}
/** 商品对比数据 */
@@ -244,4 +244,20 @@ export namespace ShopVO {
/** 对应的值 */
value: number;
}
/** 商品概览(含合计行和商品列表) */
export interface ProductOverview {
/** 合计行 */
total: ProductComparison;
/** 各商品对比列表 */
products: ProductComparison[];
}
/** 品类概览(含合计行和品类列表) */
export interface CategoryOverview {
/** 合计行 */
total: CategoryComparison;
/** 各品类对比列表 */
categories: CategoryComparison[];
}
}
@@ -80,7 +80,7 @@ const formatPercentPlain = (value: number | undefined) => {
</div>
</div>
<div class="max-h-[420px] overflow-auto">
<div class="max-h-[580px] overflow-auto">
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
<colgroup>
<col style="width: 60px; min-width: 60px;" />
@@ -111,8 +111,8 @@ const formatPercentPlain = (value: number | undefined) => {
>
<input
type="checkbox"
:checked="Boolean(props.data?.categoryComparisons?.length) && props.selectedExportCategoryIds.length === (props.data?.categoryComparisons?.length ?? 0)"
:indeterminate="props.selectedExportCategoryIds.length > 0 && props.selectedExportCategoryIds.length < (props.data?.categoryComparisons?.length ?? 0)"
:checked="Boolean(props.data?.categoryOverview?.categories?.length) && props.selectedExportCategoryIds.length === (props.data?.categoryOverview?.categories?.length ?? 0)"
:indeterminate="props.selectedExportCategoryIds.length > 0 && props.selectedExportCategoryIds.length < (props.data?.categoryOverview?.categories?.length ?? 0)"
class="h-4 w-4 cursor-pointer accent-blue-600"
@change="emit('category-select-all', $event)"
/>
@@ -154,7 +154,7 @@ const formatPercentPlain = (value: number | undefined) => {
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="cat in props.data?.categoryComparisons"
v-for="cat in (props.data?.categoryOverview?.categories || [])"
:key="cat.categoryId ?? 'uncategorized'"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)]"
>
@@ -194,12 +194,32 @@ const formatPercentPlain = (value: number | undefined) => {
{{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!props.data?.categoryComparisons?.length">
<tr v-if="!props.data?.categoryOverview?.categories?.length">
<td :colspan="props.categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<tfoot v-if="props.data?.categoryOverview?.total" class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)]">
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td v-if="props.categoryExportMode" class="sticky-col border-r border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] p-6 text-center" style="left: 40px; position: sticky; z-index: 10;"></td>
<td class="sticky-col border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4 text-base font-black" style="left: 0; position: sticky; z-index: 10;">合计</td>
<td class="p-6">{{ props.data.categoryOverview.total.salesAmount ? formatAmount(props.data.categoryOverview.total.salesAmount) : '-' }}</td>
<td class="p-6">{{ props.data.categoryOverview.total.orderCount ? props.data.categoryOverview.total.orderCount.toLocaleString() : '-' }}</td>
<td class="p-6">-</td>
<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 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>
<td class="p-6 text-slate-400">{{ props.data.categoryOverview.total.feeRatio !== undefined ? formatPercentPlain(props.data.categoryOverview.total.feeRatio) : '-' }}</td>
<td class="p-6">{{ props.data.categoryOverview.total.totalProfitBeforeTax ? formatAmount(props.data.categoryOverview.total.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-slate-400">{{ props.data.categoryOverview.total.salesTaxAmount ? formatAmount(props.data.categoryOverview.total.salesTaxAmount) : '-' }}</td>
<td class="p-6 text-indigo-700 dark:text-indigo-400">{{ props.data.categoryOverview.total.roi !== undefined ? props.data.categoryOverview.total.roi.toFixed(2) : '-' }}</td>
<td class="bg-emerald-50/30 dark:bg-[hsl(142deg_71.8%_29%/20%)] p-6 text-base">{{ props.data.categoryOverview.total.profitAfterTax ? formatAmount(props.data.categoryOverview.total.profitAfterTax) : '-' }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
@@ -51,7 +51,7 @@ const formatPercentPlain = (value: number | undefined) => {
</Button>
</div>
<div class="max-h-[420px] overflow-auto">
<div class="max-h-[580px] overflow-auto">
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
<colgroup>
<col style="width: 220px; min-width: 220px;" />
@@ -125,7 +125,7 @@ const formatPercentPlain = (value: number | undefined) => {
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="product in data?.productComparisons"
v-for="product in (data?.productOverview?.products || [])"
:key="product.productId"
class="transition-colors hover:bg-blue-50/30"
>
@@ -174,12 +174,31 @@ const formatPercentPlain = (value: number | undefined) => {
{{ product.profitAfterTax ? formatAmount(product.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!data?.productComparisons?.length">
<tr v-if="!data?.productOverview?.products?.length">
<td colspan="15" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
<tfoot v-if="data?.productOverview?.total">
<tr class="font-black text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
<td class="sticky-col sticky bottom-0 border-r-2 border-slate-200 dark:border-[hsl(240deg_3.7%_22%)] bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4 text-base font-black" style="left: 0; z-index: 30;">合计</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.salesAmount ? formatAmount(data.productOverview.total.salesAmount) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.orderCount ? data.productOverview.total.orderCount.toLocaleString() : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">-</td>
<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 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>
<td class="sticky bottom-0 bg-slate-100 text-slate-400 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-[hsl(240deg_5%_64.9%)] px-6 py-4">{{ data.productOverview.total.feeRatio !== undefined ? formatPercentPlain(data.productOverview.total.feeRatio) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 text-indigo-700 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-indigo-400 px-6 py-4">{{ data.productOverview.total.roi !== undefined ? data.productOverview.total.roi.toFixed(2) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 dark:bg-[hsl(240deg_3.7%_22%)] px-6 py-4">{{ data.productOverview.total.totalProfitBeforeTax ? formatAmount(data.productOverview.total.totalProfitBeforeTax) : '-' }}</td>
<td class="sticky bottom-0 bg-slate-100 italic text-slate-400 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-[hsl(240deg_5%_64.9%)] px-6 py-4">{{ data.productOverview.total.salesTaxAmount ? formatAmount(data.productOverview.total.salesTaxAmount) : '-' }}</td>
<td class="sticky bottom-0 bg-emerald-50/30 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-6 py-4 text-base">{{ data.productOverview.total.profitAfterTax ? formatAmount(data.productOverview.total.profitAfterTax) : '-' }}</td>
</tr>
</tfoot>
</table>
</div>
</div>