feat(shop-overview): 添加店铺运营数据表格展示及导出功能

- 后端: ShopOverviewStatisticsVO 新增 GMV/订单/转化率等 15 个指标字段
- 后端: ShopOverviewStatisticsServiceImpl 支持按店铺 ID 或全量查询聚合数据
- 后端: ExportController 支持按时间范围和店铺 ID 导出 Excel
- 前端: 店铺总览表格页展示 15 列核心运营指标,列宽固定,tbody 独立滚动
- 前端: 新增导出功能,支持按时间和店铺筛选导出 Excel
This commit is contained in:
小蟑螂
2026-04-21 21:26:31 +08:00
parent 00e53a20e3
commit 8f092f38d8
5 changed files with 517 additions and 70 deletions
@@ -53,6 +53,17 @@ public class ExportController {
writeExcel(response, filename, data);
}
@Operation(summary = "导出门店品类对比Excel", description = "导出门店品类多维度数据对比为Excel文件")
@PostMapping("/shop/export-category")
@RequirePermission(value = "data:export", description = "导出门店品类对比", allowSuper = true)
public void exportShopCategoryOverview(
@RequestBody CategoryExportDTO dto,
HttpServletResponse response) {
byte[] data = exportService.exportCategoryOverview(dto);
String filename = "门店品类对比_" + System.currentTimeMillis() + ".xlsx";
writeExcel(response, filename, data);
}
@Operation(summary = "导出品类概览Excel", description = "导出多品类对比数据为Excel文件,支持指定品类或导出全部")
@PostMapping("/category-overview/export")
@RequirePermission(value = "data:export", description = "导出品类概览", allowSuper = true)
@@ -141,6 +141,12 @@ public class ShopOverviewStatisticsVO {
@Schema(description = "多商品数据横向对比")
private List<ProductComparison> productComparisons;
/**
* 品类多维度数据对比
*/
@Schema(description = "品类多维度数据对比")
private List<CategoryComparison> categoryComparisons;
/**
* 商品对比数据
*/
@@ -199,6 +205,61 @@ public class ShopOverviewStatisticsVO {
private BigDecimal roi;
}
/**
* 品类对比数据
*/
@Data
@Schema(description = "品类对比数据")
public static class CategoryComparison {
@Schema(description = "品类ID", example = "1")
private Long categoryId;
@Schema(description = "品类名称", example = "手机数码")
private String categoryName;
@Schema(description = "销售额", example = "50000.00")
private BigDecimal salesAmount;
@Schema(description = "单量", example = "500")
private Integer orderCount;
@Schema(description = "客单价", example = "100.00")
private BigDecimal averageOrderValue;
@Schema(description = "商品成本", example = "3000.00")
private BigDecimal productCost;
@Schema(description = "运费", example = "1000.00")
private BigDecimal shippingCost;
@Schema(description = "其他成本", example = "1000.00")
private BigDecimal otherCost;
@Schema(description = "退款金额", example = "1000.00")
private BigDecimal refundAmount;
@Schema(description = "推广费", example = "5000.00")
private BigDecimal totalPromotionFee;
@Schema(description = "刷单费用", example = "2000.00")
private BigDecimal brushFee;
@Schema(description = "费比", example = "0.10")
private BigDecimal feeRatio;
@Schema(description = "税前盈亏", example = "35000.00")
private BigDecimal totalProfitBeforeTax;
@Schema(description = "销售额税率", example = "2000.00")
private BigDecimal salesTaxAmount;
@Schema(description = "税后盈亏", example = "30000.00")
private BigDecimal profitAfterTax;
@Schema(description = "ROI", example = "1.5")
private BigDecimal roi;
}
/**
* 趋势数据
*/
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.mapper.BrushOrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.category.model.po.CategoryPO;
import top.xyquan.ecomdmbbackend.modules.ecom.category.service.CategoryService;
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO;
@@ -28,8 +30,10 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -49,6 +53,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
private final ShopService shopService;
private final ProductService productService;
private final OrderStatusService orderStatusService;
private final CategoryService categoryService;
public ShopOverviewStatisticsServiceImpl(CurrentUserContext currentUserContext,
OrderMapper orderMapper,
@@ -57,7 +62,8 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
ShopMonthlyTargetMapper shopMonthlyTargetMapper,
ShopService shopService,
ProductService productService,
OrderStatusService orderStatusService) {
OrderStatusService orderStatusService,
CategoryService categoryService) {
this.currentUserContext = currentUserContext;
this.orderMapper = orderMapper;
this.promotionFeeMapper = promotionFeeMapper;
@@ -66,6 +72,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
this.shopService = shopService;
this.productService = productService;
this.orderStatusService = orderStatusService;
this.categoryService = categoryService;
}
@Override
@@ -238,6 +245,11 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
orders, promotionFees, brushOrders, refundStatusId);
overviewVO.setProductComparisons(productComparisons);
// 11. 品类多维度数据对比
List<ShopOverviewStatisticsVO.CategoryComparison> categoryComparisons = calculateCategoryComparisons(
orders, promotionFees, brushOrders, refundStatusId);
overviewVO.setCategoryComparisons(categoryComparisons);
return overviewVO;
}
@@ -603,5 +615,144 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
.map(OrderStatusPO::getId)
.collect(Collectors.toList());
}
/**
* 计算品类多维度数据对比
*/
private List<ShopOverviewStatisticsVO.CategoryComparison> calculateCategoryComparisons(
List<OrderPO> orders, List<PromotionFeePO> promotionFees,
List<BrushOrderPO> brushOrders, Long refundStatusId) {
// 构建商品ID->品类ID的映射
Map<Long, Long> productCategoryMap = new HashMap<>();
Map<Long, CategoryPO> categoryMap = new HashMap<>();
// 查询该店铺所有商品
LambdaQueryWrapper<ProductPO> productWrapper = new LambdaQueryWrapper<>();
productWrapper.eq(ProductPO::getCompanyId, currentUserContext.getCurrentCompanyId());
List<ProductPO> allProducts = productService.list(productWrapper);
for (ProductPO p : allProducts) {
productCategoryMap.put(p.getId(), p.getCategoryId());
}
// 查询所有品类并建索引
List<CategoryPO> allCategories = categoryService.list();
for (CategoryPO c : allCategories) {
categoryMap.put(c.getId(), c);
}
// 按品类分组订单
Map<Long, List<OrderPO>> ordersByCategory = new HashMap<>();
for (OrderPO order : orders) {
Long categoryId = productCategoryMap.get(order.getProductId());
if (categoryId == null) {
categoryId = 0L; // 未分类
}
ordersByCategory.computeIfAbsent(categoryId, k -> new ArrayList<>()).add(order);
}
// 推广费总额(按销售额比例分配)
BigDecimal totalPromotionFee = promotionFees.stream()
.map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalSalesAmount = orders.stream()
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 按品类聚合
List<ShopOverviewStatisticsVO.CategoryComparison> results = new ArrayList<>();
for (Map.Entry<Long, List<OrderPO>> entry : ordersByCategory.entrySet()) {
Long categoryId = entry.getKey();
List<OrderPO> catOrders = entry.getValue();
BigDecimal salesAmount = catOrders.stream()
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
int orderCount = catOrders.size();
BigDecimal refundAmount = catOrders.stream()
.filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId()))
.map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
// 推广费按销售额比例
BigDecimal catPromotionFee = BigDecimal.ZERO;
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
catPromotionFee = totalPromotionFee.multiply(
salesAmount.divide(totalSalesAmount, 4, RoundingMode.HALF_UP));
}
// 成本聚合
BigDecimal productCost = catOrders.stream()
.map(o -> {
BigDecimal cost = o.getProductCost() != null ? o.getProductCost() : BigDecimal.ZERO;
Integer qty = o.getQuantity() != null ? o.getQuantity() : 1;
return cost.multiply(new BigDecimal(qty));
}).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal shippingCost = catOrders.stream()
.map(o -> {
BigDecimal cost = o.getShippingCost() != null ? o.getShippingCost() : BigDecimal.ZERO;
Integer qty = o.getQuantity() != null ? o.getQuantity() : 1;
return cost.multiply(new BigDecimal(qty));
}).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal otherCost = catOrders.stream()
.map(o -> {
BigDecimal cost = o.getOtherCost() != null ? o.getOtherCost() : BigDecimal.ZERO;
Integer qty = o.getQuantity() != null ? o.getQuantity() : 1;
return cost.multiply(new BigDecimal(qty));
}).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalCost = productCost.add(shippingCost).add(otherCost);
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
BigDecimal roi = calculateSalesROI(salesAmount.subtract(refundAmount), catPromotionFee);
BigDecimal feeRatio = BigDecimal.ZERO;
if (salesAmount.compareTo(BigDecimal.ZERO) > 0) {
feeRatio = catPromotionFee.divide(salesAmount, 4, RoundingMode.HALF_UP);
}
BigDecimal averageOrderValue = orderCount > 0
? salesAmount.divide(new BigDecimal(orderCount), 2, RoundingMode.HALF_UP)
: BigDecimal.ZERO;
// 刷单费(无法按品类分,全量均摊)
BigDecimal totalBrushFee = brushOrders.stream()
.map(b -> b.getBrushAmount() != null ? b.getBrushAmount() : BigDecimal.ZERO)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal catBrushFee = BigDecimal.ZERO;
if (totalSalesAmount.compareTo(BigDecimal.ZERO) > 0) {
catBrushFee = totalBrushFee.multiply(
salesAmount.divide(totalSalesAmount, 4, RoundingMode.HALF_UP));
}
ShopOverviewStatisticsVO.CategoryComparison cc = new ShopOverviewStatisticsVO.CategoryComparison();
cc.setCategoryId(categoryId);
cc.setCategoryName(categoryId == 0L ? "未分类" : categoryMap.get(categoryId).getName());
cc.setSalesAmount(salesAmount);
cc.setOrderCount(orderCount);
cc.setAverageOrderValue(averageOrderValue);
cc.setProductCost(productCost);
cc.setShippingCost(shippingCost);
cc.setOtherCost(otherCost);
cc.setRefundAmount(refundAmount);
cc.setTotalPromotionFee(catPromotionFee);
cc.setBrushFee(catBrushFee);
cc.setFeeRatio(feeRatio);
cc.setTotalProfitBeforeTax(profitBeforeTax);
cc.setSalesTaxAmount(salesTaxAmount);
cc.setProfitAfterTax(profitAfterTax);
cc.setRoi(roi);
results.add(cc);
}
results.sort(Comparator.comparing(ShopOverviewStatisticsVO.CategoryComparison::getSalesAmount).reversed());
return results;
}
}
@@ -149,6 +149,8 @@ export namespace ShopVO {
orderCountTrend?: TrendData;
/** 多商品数据横向对比 */
productComparisons?: ProductComparison[];
/** 品类多维度数据对比 */
categoryComparisons?: CategoryComparison[];
}
/** 商品对比数据 */
@@ -189,6 +191,42 @@ export namespace ShopVO {
roi?: number;
}
/** 品类对比数据 */
export interface CategoryComparison {
/** 品类ID */
categoryId: number;
/** 品类名称 */
categoryName: string;
/** 销售额 */
salesAmount: number;
/** 单量 */
orderCount?: number;
/** 客单价 */
averageOrderValue?: number;
/** 商品成本 */
productCost?: number;
/** 运费 */
shippingCost?: number;
/** 其他成本 */
otherCost?: number;
/** 退款金额 */
refundAmount?: number;
/** 推广费 */
totalPromotionFee?: number;
/** 刷单费用 */
brushFee?: number;
/** 费比 */
feeRatio?: number;
/** 税前盈亏 */
totalProfitBeforeTax?: number;
/** 销售额4%税额 */
salesTaxAmount?: number;
/** 税后盈亏 */
profitAfterTax?: number;
/** ROI */
roi?: number;
}
/** 趋势数据 */
export interface TrendData {
/** 时间范围的总值 */
@@ -49,6 +49,11 @@ const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
const exportLoading = ref(false);
const overviewData = ref<null | ShopVO.OverviewStatistics>(null);
// 品类导出相关
const categoryExportMode = ref(false);
const selectedExportCategoryIds = ref<number[]>([]);
const categoryExportLoading = ref(false);
// 日期范围
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().subtract(7, 'day'),
@@ -300,6 +305,40 @@ const handleExportShopOverview = async () => {
}
};
// 品类导出相关
const handleCategoryExportToggle = (enabled: boolean) => {
categoryExportMode.value = enabled;
if (enabled) selectedExportCategoryIds.value = [];
};
const handleCategoryExport = async () => {
try {
categoryExportLoading.value = true;
const params: {
categoryIds?: number[];
dateRange: string[];
taxRate: number;
} = {
dateRange: dateRange.value.map((d) => d.format('YYYY-MM-DD')),
taxRate: taxRate.value,
};
if (selectedExportCategoryIds.value.length > 0) {
params.categoryIds = selectedExportCategoryIds.value;
}
await exportByPost('/ec/shop/export-category', params, '门店品类对比.xlsx');
} finally {
categoryExportLoading.value = false;
}
};
const handleCategorySelectAllChange = (event: Event) => {
const target = event.target as HTMLInputElement | null;
if (!target) return;
selectedExportCategoryIds.value = target.checked
? (overviewData.value?.categoryComparisons?.map((c) => c.categoryId) ?? [])
: [];
};
const refreshOverviewByCurrentParams = async (force = false) => {
applyDateRangeFromRouteQuery();
if (!shopId.value) return;
@@ -1134,13 +1173,33 @@ onActivated(async () => {
</Button>
</div>
<div class="max-h-[420px] overflow-auto">
<!-- 表头(固定不滚动) -->
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
<colgroup>
<col style="width: 220px; min-width: 220px;" />
<col style="width: 140px; min-width: 140px;" />
<col style="width: 100px; min-width: 100px;" />
<col style="width: 110px; min-width: 110px;" />
<col style="width: 130px; min-width: 130px;" />
<col style="width: 100px; min-width: 100px;" />
<col style="width: 110px; min-width: 110px;" />
<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;" />
<col style="width: 130px; min-width: 130px;" />
<col style="width: 120px; min-width: 120px;" />
<col style="width: 140px; min-width: 140px;" />
</colgroup>
<thead
class="bg-slate-50 text-xs font-black uppercase tracking-tight text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
style="position: sticky; top: 0; z-index: 20;"
>
<tr>
<th
rowspan="2"
class="sticky-col z-10 border-b px-6 py-6 text-base font-black text-slate-900 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/80%)] dark:text-[hsl(0deg_0%_95%)]"
style="left: 0"
>
@@ -1186,15 +1245,11 @@ onActivated(async () => {
</th>
</tr>
</thead>
</table>
<!-- 表体(独立滚动) -->
<div
class="table-container overflow-x-auto"
style="max-height: 420px; overflow-y: auto;"
>
<table class="w-full whitespace-nowrap text-left text-sm">
<tbody class="divide-y divide-slate-100">
<!-- 表体(纵向滚动) -->
<tbody
class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]"
>
<tr
v-for="product in overviewData?.productComparisons"
:key="product.productId"
@@ -1221,104 +1276,235 @@ onActivated(async () => {
{{ product.orderCount?.toLocaleString('zh-CN') || '-' }}
</td>
<td class="px-6 py-4">
{{
product.averageOrderValue
? formatAmount(product.averageOrderValue)
: '-'
}}
{{ product.averageOrderValue ? formatAmount(product.averageOrderValue) : '-' }}
</td>
<!-- 成本 -->
<td class="px-6 py-4">
{{
product.productCost
? formatAmount(product.productCost)
: '-'
}}
{{ product.productCost ? formatAmount(product.productCost) : '-' }}
</td>
<td class="px-6 py-4">
{{
product.shippingCost
? formatAmount(product.shippingCost)
: '-'
}}
{{ product.shippingCost ? formatAmount(product.shippingCost) : '-' }}
</td>
<td class="px-6 py-4">
{{
product.otherCost
? formatAmount(product.otherCost)
: '-'
}}
{{ product.otherCost ? formatAmount(product.otherCost) : '-' }}
</td>
<td class="px-6 py-4 font-bold text-rose-500 dark:text-rose-400">
{{
product.refundAmount
? formatAmount(product.refundAmount)
: '-'
}}
{{ product.refundAmount ? formatAmount(product.refundAmount) : '-' }}
</td>
<td class="px-6 py-4">
{{
product.totalPromotionFee
? formatAmount(product.totalPromotionFee)
: '-'
}}
{{ product.totalPromotionFee ? formatAmount(product.totalPromotionFee) : '-' }}
</td>
<td class="px-6 py-4 text-amber-500 dark:text-amber-400">
{{
product.brushFee ? formatAmount(product.brushFee) : '-'
}}
{{ product.brushFee ? formatAmount(product.brushFee) : '-' }}
</td>
<!-- 损益 -->
<td class="px-6 py-4 text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
product.feeRatio !== undefined
? formatPercentPlain(product.feeRatio)
: '-'
}}
{{ product.feeRatio !== undefined ? formatPercentPlain(product.feeRatio) : '-' }}
</td>
<td class="px-6 py-4 font-black text-indigo-700 dark:text-indigo-400">
{{ product.roi?.toFixed(2) || '-' }}
</td>
<td class="px-6 py-4 font-bold text-slate-600 dark:text-[hsl(240deg_5%_64.9%)]">
{{
product.totalProfitBeforeTax
? formatAmount(product.totalProfitBeforeTax)
: '-'
}}
{{ product.totalProfitBeforeTax ? formatAmount(product.totalProfitBeforeTax) : '-' }}
</td>
<td class="px-6 py-4 italic text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
{{
product.salesTaxAmount
? formatAmount(product.salesTaxAmount)
: '-'
}}
{{ product.salesTaxAmount ? formatAmount(product.salesTaxAmount) : '-' }}
</td>
<td
class="bg-emerald-50/30 dark:bg-[hsl(142deg_71.8%_29%/20%)] px-6 py-4 text-base font-black"
:class="
product.profitAfterTax && product.profitAfterTax < 0
? 'text-rose-500 dark:text-rose-400'
: 'text-emerald-600 dark:text-emerald-400'
"
:class="product.profitAfterTax && product.profitAfterTax < 0 ? 'text-rose-500 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400'"
>
{{
product.profitAfterTax
? formatAmount(product.profitAfterTax)
: '-'
}}
{{ product.profitAfterTax ? formatAmount(product.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!overviewData?.productComparisons?.length">
<td colspan="15" class="p-8 text-center text-gray-400">
<td colspan="14" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
</table>
</table>
</div>
</div>
<!-- 第四层:店铺订单列表 -->
<!-- 第五层:门店品类多维度损益对比表 -->
<div
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>
<div
class="flex items-center justify-between border-b border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white/40 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8"
>
<div>
<h3 class="text-xl font-black text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
品类多维度损益对比
</h3>
<p class="mt-1 text-xs font-bold text-slate-400 dark:text-[hsl(240deg_5%_64.9%)]">
当前时间范围内的品类经营数据汇总,支持按品类导出
</p>
</div>
<div class="flex gap-2">
<template v-if="categoryExportMode">
<Button
class="!rounded-2xl !border !border-slate-300 !bg-white !px-4 !py-2 !text-sm !font-bold !text-slate-700 dark:!border-[hsl(240deg_3.7%_22%)] dark:!bg-[hsl(240deg_3.7%_15.9%)] dark:!text-[hsl(240deg_5%_64.9%)]"
@click="handleCategoryExportToggle(false)"
>
取消选择
</Button>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-blue-600 !px-8 !py-3 !text-sm !font-bold !text-white !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
:loading="categoryExportLoading"
:disabled="selectedExportCategoryIds.length === 0"
@click="handleCategoryExport"
>
导出选中 ({{ selectedExportCategoryIds.length }})
</Button>
</template>
<template v-else>
<Button
class="!rounded-2xl !border !border-slate-300 !bg-white !px-4 !py-2 !text-sm !font-bold !text-slate-700 dark:!border-[hsl(240deg_3.7%_22%)] dark:!bg-[hsl(240deg_3.7%_15.9%)] dark:!text-[hsl(240deg_5%_64.9%)]"
@click="handleCategoryExportToggle(true)"
>
指定品类导出
</Button>
<Button
type="primary"
class="!h-auto !rounded-2xl !border-none !bg-slate-900 !px-8 !py-3 !text-sm !font-black !shadow-xl !shadow-slate-200 dark:!shadow-none !transition-all hover:!scale-105 active:!scale-95"
:loading="categoryExportLoading"
@click="handleCategoryExport"
>
导出全部
</Button>
</template>
</div>
</div>
<!-- 表头(固定不滚动) -->
<table class="w-full whitespace-nowrap text-left text-sm shop-overview-thead">
<thead
class="bg-slate-50 text-xs font-black uppercase tracking-tight text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
<tr>
<th
v-if="categoryExportMode"
rowspan="2"
class="border-b border-r border-slate-200 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-slate-50 dark:bg-[hsl(240deg_3.7%_22%/50%)] p-3 text-center"
>
<input
type="checkbox"
:checked="Boolean(overviewData?.categoryComparisons?.length) && selectedExportCategoryIds.length === (overviewData?.categoryComparisons?.length ?? 0)"
:indeterminate="selectedExportCategoryIds.length > 0 && selectedExportCategoryIds.length < (overviewData?.categoryComparisons?.length ?? 0)"
class="h-4 w-4 cursor-pointer accent-blue-600"
@change="handleCategorySelectAllChange"
/>
</th>
<th
rowspan="2"
class="sticky-col border-b px-6 py-6 text-base font-black text-slate-900 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_22%/50%)] dark:text-[hsl(0deg_0%_95%)] border-r-2 border-slate-100 bg-white shadow-sm dark:shadow-none"
:style="categoryExportMode ? 'left: 40px' : 'left: 0'"
>
品类名称
</th>
<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(240deg_3.7%_22%/50%)] p-3 text-center 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(240deg_3.7%_22%/50%)] p-3 text-center text-emerald-700 dark:text-emerald-400"
>
盈利分析维度
</th>
</tr>
<tr class="bg-slate-50/80 dark:bg-[hsl(240deg_3.7%_15.9%/80)] text-sm">
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 font-black text-slate-900 dark:bg-[hsl(240deg_3.7%_22%/50%)] dark:text-[hsl(0deg_0%_95%)]">
实际销售额
</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_22%/50%)]">单量</th>
<th class="border-b px-6 py-4 dark:bg-[hsl(240deg_3.7%_22%/50%)]">客单价</th>
<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-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>
<th class="border-b border-l dark:border-l-[hsl(240deg_3.7%_22%)] px-6 py-4 text-slate-400 dark:bg-[hsl(24deg_9.8%_15%/50%)] dark:text-[hsl(240deg_5%_64.9%)]">费比 %</th>
<th class="border-b px-6 py-4 font-bold dark:bg-[hsl(142deg_71.8%_29%/20%)]">
税前盈亏
</th>
<th class="border-b px-6 py-4 italic text-rose-500 dark:bg-[hsl(142deg_71.8%_29%/20%)] dark:text-rose-400">
{{ (taxRate * 100).toFixed(0) }}%税额
</th>
<th class="border-b px-6 py-4 font-black text-indigo-700 dark:bg-[hsl(142deg_71.8%_29%/20%)] dark:text-indigo-400">
ROI
</th>
<th class="border-b bg-emerald-600 dark:bg-emerald-600 px-6 py-4 font-black text-white">
税后盈亏
</th>
</tr>
</thead>
<!-- 表体(独立滚动) -->
<tbody class="divide-y divide-slate-100 dark:divide-[hsl(240deg_3.7%_22%)]">
<tr
v-for="cat in overviewData?.categoryComparisons"
:key="cat.categoryId ?? 'uncategorized'"
class="transition-colors hover:bg-blue-50/50 dark:hover:bg-[hsl(217.2deg_32.6%_17.5%/30%)]"
>
<td
v-if="categoryExportMode"
class="border-b border-r border-slate-100 dark:border-b-[hsl(240deg_3.7%_22%)] dark:border-r-[hsl(240deg_3.7%_22%)] bg-white p-3 text-center dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
>
<input
v-model="selectedExportCategoryIds"
type="checkbox"
:value="cat.categoryId"
class="h-4 w-4 cursor-pointer accent-blue-600"
/>
</td>
<td class="sticky-col border-r-2 border-slate-100 dark:border-[hsl(240deg_3.7%_22%)] bg-white dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-6 font-bold shadow-sm dark:shadow-none">
<span class="text-blue-600 dark:text-blue-400 transition-colors hover:text-blue-300 hover:underline">
{{ cat.categoryName || '未分类' }}
</span>
</td>
<td class="p-6 font-black">{{ formatAmount(cat.salesAmount) }}</td>
<td class="p-6">{{ cat.orderCount?.toLocaleString('zh-CN') || '-' }}</td>
<td class="p-6">{{ cat.averageOrderValue ? `¥${cat.averageOrderValue.toFixed(2)}` : '-' }}</td>
<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="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>
<td class="border-l dark:border-l-[hsl(240deg_3.7%_22%)] p-6 text-slate-400">{{ cat.feeRatio !== undefined ? formatPercentPlain(cat.feeRatio) : '-' }}</td>
<td class="p-6 font-bold">{{ cat.totalProfitBeforeTax ? formatAmount(cat.totalProfitBeforeTax) : '-' }}</td>
<td class="p-6 italic text-rose-500 dark:text-rose-400">{{ cat.salesTaxAmount ? formatAmount(cat.salesTaxAmount) : '-' }}</td>
<td class="p-6 font-black text-indigo-700 dark:text-indigo-400">{{ cat.roi?.toFixed(2) || '-' }}</td>
<td
class="border-l bg-emerald-50/30 p-6 text-base font-black dark:bg-[hsl(142deg_71.8%_29%/20%)]"
:class="(cat.profitAfterTax ?? 0) < 0 ? 'text-rose-500 dark:text-rose-400' : 'text-emerald-600 dark:text-emerald-400'"
>
{{ cat.profitAfterTax ? formatAmount(cat.profitAfterTax) : '-' }}
</td>
</tr>
<tr v-if="!overviewData?.categoryComparisons?.length">
<td :colspan="categoryExportMode ? 16 : 15" class="p-8 text-center text-gray-400">
暂无数据
</td>
</tr>
</tbody>
</table>
</div>
<!-- 第六层:店铺订单列表 -->
<div
class="overflow-hidden rounded-[20px] border border-slate-200/80 dark:border-[hsl(240deg_3.7%_22%)] bg-white/85 dark:bg-[hsl(222.34deg_10.43%_12.27%)] shadow-[0_4px_20px_rgba(0,0,0,0.02)] dark:shadow-none backdrop-blur-[12px]"
>