This commit is contained in:
ah--desktop
2025-12-13 08:11:29 +08:00
parent 5129657f7f
commit ca15b80d86
14 changed files with 503 additions and 339 deletions
+2 -2
View File
@@ -11,8 +11,8 @@
<groupId>top.xyquan</groupId>
<artifactId>ecom-dmb-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ah-gf-backend</name>
<description>ah-gf-backend</description>
<name>ecom-dmb-backend</name>
<description>ecom-dmb-backend</description>
<properties>
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
@@ -12,10 +12,12 @@ import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
@@ -103,7 +105,7 @@ public class ShopController {
return ApiResponse.success(statistics);
}
@Operation(summary = "分页获取店铺商品详细信息", description = "分页获取店铺商品的详细信息,包含商品基础信息和统计数据(销售额、订单数、客单价),支持按商品名称、商品编码筛选,日期参数不传默认为当日")
@Operation(summary = "分页获取店铺商品详细信息", description = "分页获取店铺商品的详细信息,包含商品基础信息和统计数据(销售额、订单数、客单价),支持按商品名称、商品编码筛选,日期范围参数不传默认为当月1号到今天")
@PostMapping("/products/page")
@RequireRole(description = "查询店铺商品列表", allowUser = true)
public ApiResponse<PageResultVO<ShopProductDetailVO>> getShopProductPage(
@@ -111,4 +113,13 @@ public class ShopController {
PageResultVO<ShopProductDetailVO> result = shopService.getShopProductPage(pageQueryDTO);
return ApiResponse.success(result);
}
@Operation(summary = "获取店铺详情", description = "获取店铺详情,包含统计信息(销售额、订单数、客单价、成本、退款金额、推广费、费比)和所有商品列表,支持按时间范围查询,日期范围参数不传默认为当月1号到今天")
@PostMapping("/detail")
@RequireRole(description = "查询店铺详情", allowUser = true)
public ApiResponse<ShopDetailVO> getShopDetail(
@Valid @RequestBody ShopDetailQueryDTO queryDTO) {
ShopDetailVO shopDetail = shopService.getShopDetail(queryDTO);
return ApiResponse.success(shopDetail);
}
}
@@ -0,0 +1,35 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDate;
/**
* 店铺详情查询DTO
*/
@Data
@Schema(description = "店铺详情查询DTO")
public class ShopDetailQueryDTO {
/**
* 店铺ID
*/
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "店铺ID不能为空")
private Long shopId;
/**
* 开始日期(不传默认为当月1号)
*/
@Schema(description = "开始日期(不传默认为当月1号)", example = "2024-01-01")
private LocalDate startDate;
/**
* 结束日期(不传默认为今天)
*/
@Schema(description = "结束日期(不传默认为今天)", example = "2024-01-31")
private LocalDate endDate;
}
@@ -31,9 +31,15 @@ public class ShopProductFilterDTO {
private String productCode;
/**
* 统计日期(不传默认为当日)
* 开始日期(不传默认为当月1号)
*/
@Schema(description = "统计日期(不传默认为当日)", example = "2024-01-01")
private LocalDate statDate;
@Schema(description = "开始日期(不传默认为当月1号)", example = "2024-01-01")
private LocalDate startDate;
/**
* 结束日期(不传默认为今天)
*/
@Schema(description = "结束日期(不传默认为今天)", example = "2024-01-31")
private LocalDate endDate;
}
@@ -0,0 +1,27 @@
package top.xyquan.ecomdmbbackend.modules.ecom.model.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* 店铺详情VO
*/
@Data
@Schema(description = "店铺详情VO")
public class ShopDetailVO {
/**
* 店铺统计信息
*/
@Schema(description = "店铺统计信息")
private ShopStatisticsVO statistics;
/**
* 商品列表
*/
@Schema(description = "商品列表")
private List<ShopProductDetailVO> products;
}
@@ -5,11 +5,13 @@ import org.springframework.web.multipart.MultipartFile;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.UpdateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
@@ -83,4 +85,12 @@ public interface ShopService extends IService<ShopPO> {
* @return 分页结果
*/
PageResultVO<ShopProductDetailVO> getShopProductPage(PageQueryDTO<ShopProductFilterDTO> pageQueryDTO);
/**
* 获取店铺详情(包含统计信息和商品分页列表)
*
* @param queryDTO 店铺详情查询DTO
* @return 店铺详情VO
*/
ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO);
}
@@ -17,6 +17,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.mapper.PromotionFeeMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ShopProductRelationMapper;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.CreateShopDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopDetailQueryDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopProductFilterDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.shop.ShopStatisticsQueryDTO;
@@ -27,6 +28,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.PromotionFeePO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ShopProductRelationPO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopProductDetailVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopStatisticsVO;
import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ShopVO;
@@ -413,10 +415,17 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
throw new BusinessException("店铺不存在");
}
// 确定统计日期(不传默认为当日)
LocalDate statDate = filter.getStatDate() != null ? filter.getStatDate() : LocalDate.now();
LocalDateTime startDateTime = statDate.atStartOfDay();
LocalDateTime endDateTime = statDate.atTime(23, 59, 59);
// 确定统计日期范围(不传默认为当月1号到今天)
LocalDate startDate = filter.getStartDate() != null ? filter.getStartDate() : LocalDate.now().withDayOfMonth(1);
LocalDate endDate = filter.getEndDate() != null ? filter.getEndDate() : LocalDate.now();
// 验证日期范围
if (startDate.isAfter(endDate)) {
throw new BusinessException("开始日期不能晚于结束日期");
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
// 创建分页对象
Page<ShopProductRelationPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
@@ -537,4 +546,91 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopPO> implements
BeanUtils.copyProperties(shop, shopVO);
return shopVO;
}
/**
* 获取店铺详情(包含统计信息和商品列表)
*/
@Override
public ShopDetailVO getShopDetail(ShopDetailQueryDTO queryDTO) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId();
// 验证店铺是否存在
ShopPO shop = this.getById(queryDTO.getShopId());
if (shop == null || !shop.getCompanyId().equals(companyId)) {
throw new BusinessException("店铺不存在");
}
// 确定统计日期范围(不传默认为当月1号到今天)
LocalDate startDate = queryDTO.getStartDate() != null ? queryDTO.getStartDate() : LocalDate.now().withDayOfMonth(1);
LocalDate endDate = queryDTO.getEndDate() != null ? queryDTO.getEndDate() : LocalDate.now();
// 验证日期范围
if (startDate.isAfter(endDate)) {
throw new BusinessException("开始日期不能晚于结束日期");
}
LocalDateTime startDateTime = startDate.atStartOfDay();
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
// 获取店铺统计信息
ShopStatisticsQueryDTO statisticsQueryDTO = new ShopStatisticsQueryDTO();
statisticsQueryDTO.setShopId(queryDTO.getShopId());
statisticsQueryDTO.setStartDate(startDate);
statisticsQueryDTO.setEndDate(endDate);
ShopStatisticsVO statistics = calculateStatistics(statisticsQueryDTO, companyId);
// 获取所有商品列表
List<ShopProductDetailVO> products = getAllShopProducts(queryDTO.getShopId(), companyId, startDateTime, endDateTime);
// 组装返回结果
ShopDetailVO shopDetailVO = new ShopDetailVO();
shopDetailVO.setStatistics(statistics);
shopDetailVO.setProducts(products);
return shopDetailVO;
}
/**
* 获取店铺所有商品详细信息
*/
private List<ShopProductDetailVO> getAllShopProducts(Long shopId, Long companyId,
LocalDateTime startDateTime, LocalDateTime endDateTime) {
// 构建查询条件(店铺商品关联表)
LambdaQueryWrapper<ShopProductRelationPO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShopProductRelationPO::getCompanyId, companyId)
.eq(ShopProductRelationPO::getShopId, shopId);
// 排序
wrapper.orderByAsc(ShopProductRelationPO::getSortOrder)
.orderByDesc(ShopProductRelationPO::getCreateTime);
// 查询所有商品关联记录
List<ShopProductRelationPO> relations = shopProductRelationMapper.selectList(wrapper);
// 转换为VO并填充统计数据
return relations.stream()
.map(relation -> {
ShopProductDetailVO vo = new ShopProductDetailVO();
vo.setRelationId(relation.getId());
vo.setSortOrder(relation.getSortOrder());
vo.setCreateTime(relation.getCreateTime());
vo.setUpdateTime(relation.getUpdateTime());
// 查询商品信息
ProductPO product = productMapper.selectById(relation.getProductId());
if (product != null) {
vo.setProductId(product.getId());
vo.setProductName(product.getName());
vo.setProductCode(product.getProductCode());
vo.setMainImage(product.getMainImage());
}
// 统计订单数据(按日期范围)
calculateProductStatistics(vo, shopId, relation.getProductId(), companyId, startDateTime, endDateTime);
return vo;
})
.collect(Collectors.toList());
}
}
@@ -76,3 +76,10 @@ export async function getShopProductPageApi(
params,
);
}
/**
* 获取店铺详情
*/
export async function getShopDetailApi(params: ShopDTO.DetailQuery) {
return requestClient.post<ShopVO.Detail>('/ec/shop/detail', params);
}
@@ -52,4 +52,14 @@ export namespace ShopDTO {
/** 统计日期(不传默认为当日) */
statDate?: string;
}
/** 店铺详情查询参数 */
export interface DetailQuery {
/** 店铺ID */
shopId: number;
/** 开始日期(不传默认为当月1号) */
startDate?: string;
/** 结束日期(不传默认为今天) */
endDate?: string;
}
}
@@ -70,4 +70,12 @@ export namespace ShopVO {
/** 客单价(销售额/订单数) */
averageOrderValue: number;
}
/** 店铺详情 */
export interface Detail {
/** 店铺统计信息 */
statistics: Statistics;
/** 商品列表 */
products: ProductDetail[];
}
}
@@ -289,13 +289,7 @@ onMounted(async () => {
</script>
<template>
<Page title="订单管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理电商订单信息,包括订单创建、编辑、删除和状态管理
</div>
</template>
<Page auto-content-height>
<!-- VbenVxeGrid 表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
@@ -0,0 +1,150 @@
<script lang="ts" setup>
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import { onMounted, ref, watch } from 'vue';
import { Card, Col, DatePicker, message, Row, Space, Statistic } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getShopDetailApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'ShopStatistics' });
interface Props {
shopId: number;
}
const props = defineProps<Props>();
const emit = defineEmits<{
productListUpdate: [products: ShopVO.ProductDetail[]];
}>();
// 响应式数据
const loading = ref(false);
const customStats = ref<null | ShopVO.Statistics>(null);
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().startOf('month'),
dayjs(),
]);
// 格式化金额
function formatCurrency(value: number): string {
return `¥${value.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
}
// 格式化百分比
function formatPercent(value: number): string {
return `${(value * 100).toFixed(2)}%`;
}
// 获取店铺详情(包含统计信息和商品列表)
async function fetchShopDetail() {
if (!props.shopId || !dateRange.value) return;
try {
loading.value = true;
const params: ShopDTO.DetailQuery = {
shopId: props.shopId,
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
};
const data = await getShopDetailApi(params);
customStats.value = data.statistics;
// 通知父组件更新商品列表
emit('productListUpdate', data.products || []);
} catch (error) {
console.error('获取店铺详情失败:', error);
message.error('获取店铺详情失败');
} finally {
loading.value = false;
}
}
// 处理日期范围变化
function handleDateRangeChange() {
fetchShopDetail();
}
// 监听 shopId 变化
watch(
() => props.shopId,
(newShopId) => {
if (newShopId) {
fetchShopDetail();
}
},
);
// 初始化数据
onMounted(() => {
if (props.shopId) {
fetchShopDetail();
}
});
</script>
<template>
<Card title="店铺统计信息" :loading="loading" class="mb-4 flex-shrink-0">
<div class="mb-4">
<Space>
<span>选择日期范围:</span>
<DatePicker.RangePicker
v-model:value="dateRange"
format="YYYY-MM-DD"
@change="handleDateRangeChange"
/>
</Space>
</div>
<Row :gutter="16" v-if="customStats">
<Col :span="6">
<Statistic
title="销售额"
:value="customStats.salesAmount"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6">
<Statistic title="订单数" :value="customStats.orderCount" />
</Col>
<Col :span="6">
<Statistic
title="客单价"
:value="customStats.averageOrderValue"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6">
<Statistic
title="成本"
:value="customStats.costAmount"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6" class="mt-4">
<Statistic
title="退款金额"
:value="customStats.refundAmount"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6" class="mt-4">
<Statistic
title="推广费"
:value="customStats.promotionFee"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6" class="mt-4">
<Statistic
title="费比"
:value="customStats.feeRatio"
:formatter="({ value }) => formatPercent(value as number)"
/>
</Col>
</Row>
</Card>
</template>
@@ -1,30 +1,16 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import type { ColumnsType } from 'ant-design-vue/es/table';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
import {
Card,
Col,
DatePicker,
Image,
message,
Row,
Space,
Statistic,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import { Card, Image, message, Table } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
getShopProductPageApi,
getShopStatisticsApi,
} from '#/api/ecommerce/shop';
import ShopStatistics from './components/ShopStatistics.vue';
defineOptions({ name: 'ShopDetails' });
@@ -38,12 +24,7 @@ const shopId = computed(() => {
// 响应式数据
const loading = ref(false);
const tableLoading = ref(false);
const customStats = ref<null | ShopVO.Statistics>(null);
const dateRange = ref<[dayjs.Dayjs, dayjs.Dayjs]>([
dayjs().startOf('month'),
dayjs(),
]);
const productList = ref<ShopVO.ProductDetail[]>([]);
// 格式化金额
function formatCurrency(value: number): string {
@@ -53,217 +34,76 @@ function formatCurrency(value: number): string {
})}`;
}
// 格式化百分比
function formatPercent(value: number): string {
return `${(value * 100).toFixed(2)}%`;
// 处理商品列表更新(由 ShopStatistics 组件触发)
function handleProductListUpdate(products: ShopVO.ProductDetail[]) {
productList.value = products || [];
}
// 获取自定义日期范围统计信息
async function fetchCustomStatistics() {
if (!shopId.value || !dateRange.value) return;
try {
loading.value = true;
const params: ShopDTO.StatisticsQuery = {
shopId: shopId.value,
startDate: dateRange.value[0].format('YYYY-MM-DD'),
endDate: dateRange.value[1].format('YYYY-MM-DD'),
};
const data = await getShopStatisticsApi(params);
customStats.value = data;
} catch (error) {
console.error('获取统计信息失败:', error);
message.error('获取统计信息失败');
} finally {
loading.value = false;
}
}
// 处理日期范围变化
function handleDateRangeChange() {
fetchCustomStatistics();
}
// 店铺ID的稳定引用,避免响应式循环
const stableShopId = computed(() => {
const id = route.params.id;
return id ? Number(id) : 0;
});
// VbenVxeGrid 表格配置 - 商品列表
const gridOptions: VxeGridProps<ShopVO.ProductDetail> = {
columns: [
{
type: 'seq' as const,
width: 80,
title: '序号',
},
{
title: '商品主图',
width: 100,
align: 'center' as const,
slots: { default: 'mainImage' },
},
{
field: 'productName',
title: '商品名称',
minWidth: 200,
showOverflow: 'tooltip' as const,
},
{
field: 'productCode',
title: '商品编码',
minWidth: 150,
showOverflow: 'tooltip' as const,
},
{
field: 'salesAmount',
title: '销售额',
width: 150,
align: 'right' as const,
formatter: ({ cellValue }) => formatCurrency(cellValue || 0),
},
{
field: 'orderCount',
title: '订单数',
width: 120,
align: 'right' as const,
},
{
field: 'averageOrderValue',
title: '客单价',
width: 150,
align: 'right' as const,
formatter: ({ cellValue }) => formatCurrency(cellValue || 0),
},
{
field: 'createTime',
title: '创建时间',
width: 180,
},
],
height: 'auto',
border: true,
stripe: true,
rowConfig: {
isHover: true,
// 表格列配置
const columns: ColumnsType<ShopVO.ProductDetail> = [
{
title: '序号',
width: 80,
align: 'center',
customRender: ({ index }) => index + 1,
},
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
{
title: '商品主图',
width: 100,
align: 'center',
dataIndex: 'mainImage',
key: 'mainImage',
},
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: [
'PrevJump',
'PrevPage',
'Number',
'NextPage',
'NextJump',
'Sizes',
'FullJump',
'Total',
] as (
| 'FullJump'
| 'NextJump'
| 'NextPage'
| 'Number'
| 'PrevJump'
| 'PrevPage'
| 'Sizes'
| 'Total'
)[],
{
title: '商品名称',
dataIndex: 'productName',
key: 'productName',
ellipsis: true,
minWidth: 200,
},
// 配置远程加载
proxyConfig: {
autoLoad: false, // 禁用自动加载,手动控制
ajax: {
query: async ({ page }, formValues) => {
// 确保 shopId 有值才查询,使用稳定的 shopId 引用
const currentShopId = stableShopId.value;
if (!currentShopId) {
return {
items: [],
total: 0,
};
}
try {
tableLoading.value = true;
const params: PageQueryDTO<ShopDTO.ProductFilters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: currentShopId,
productName: formValues?.productName || undefined,
productCode: formValues?.productCode || undefined,
},
};
const data = await getShopProductPageApi(params);
return {
items: data.records || [],
total: data.total || 0,
};
} catch (error) {
console.error('获取商品列表失败:', error);
message.error('获取商品列表失败');
return {
items: [],
total: 0,
};
} finally {
tableLoading.value = false;
}
},
},
{
title: '商品编码',
dataIndex: 'productCode',
key: 'productCode',
ellipsis: true,
minWidth: 150,
},
};
// 搜索表单配置 - 使用稳定的对象引用
const formOptions = {
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入商品名称',
},
fieldName: 'productName',
label: '商品名称',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入商品编码',
},
fieldName: 'productCode',
label: '商品编码',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
};
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions,
showSearchForm: true,
tableTitle: '商品列表',
});
{
title: '销售额',
dataIndex: 'salesAmount',
key: 'salesAmount',
width: 150,
align: 'right',
customRender: ({ text }) => formatCurrency(text || 0),
},
{
title: '订单数',
dataIndex: 'orderCount',
key: 'orderCount',
width: 120,
align: 'right',
},
{
title: '客单价',
dataIndex: 'averageOrderValue',
key: 'averageOrderValue',
width: 150,
align: 'right',
customRender: ({ text }) => formatCurrency(text || 0),
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
width: 180,
},
];
// 初始化数据
onMounted(() => {
onMounted(async () => {
if (shopId.value) {
fetchCustomStatistics();
// 手动触发表格加载,确保 shopId 有值
setTimeout(() => {
if (gridApi && shopId.value) {
gridApi.reload();
}
}, 100);
// 等待 ShopStatistics 组件加载完成后,会自动触发 dateRangeChange 事件
// 这里不需要手动调用 fetchShopDetail
} else {
message.error('店铺ID不存在');
}
@@ -271,97 +111,73 @@ onMounted(() => {
</script>
<template>
<Page title="店铺详情" auto-content-height>
<Page auto-content-height content-class="flex flex-col">
<!-- 店铺统计信息 -->
<Card title="店铺统计信息" class="mb-4" :loading="loading">
<div class="mb-4">
<Space>
<span>选择日期范围:</span>
<DatePicker.RangePicker
v-model:value="dateRange"
format="YYYY-MM-DD"
@change="handleDateRangeChange"
/>
</Space>
</div>
<Row :gutter="16" v-if="customStats">
<Col :span="6">
<Statistic
title="销售额"
:value="customStats.salesAmount"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6">
<Statistic title="订单数" :value="customStats.orderCount" />
</Col>
<Col :span="6">
<Statistic
title="客单价"
:value="customStats.averageOrderValue"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6">
<Statistic
title="成本"
:value="customStats.costAmount"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6" class="mt-4">
<Statistic
title="退款金额"
:value="customStats.refundAmount"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6" class="mt-4">
<Statistic
title="推广费"
:value="customStats.promotionFee"
:formatter="({ value }) => formatCurrency(value as number)"
/>
</Col>
<Col :span="6" class="mt-4">
<Statistic
title="费比"
:value="customStats.feeRatio"
:formatter="({ value }) => formatPercent(value as number)"
/>
</Col>
</Row>
</Card>
<ShopStatistics
:shop-id="shopId"
@product-list-update="handleProductListUpdate"
/>
<!-- 商品列表表格 -->
<Card title="商品详细信息" :loading="tableLoading">
<Grid>
<!-- 商品主图列 -->
<template #mainImage="{ row }: { row: ShopVO.ProductDetail }">
<div
v-if="row.mainImage"
style="display: flex; justify-content: center; align-items: center"
>
<Image
:src="row.mainImage"
:alt="row.productName"
:preview="false"
style="
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 4px;
"
/>
</div>
<div
v-else
style="display: flex; justify-content: center; align-items: center"
>
<span style="color: #999">暂无图片</span>
</div>
</template>
</Grid>
<Card
title="商品详细信息"
:loading="loading"
class="flex min-h-0 flex-1 flex-col"
:body-style="{
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
flex: 1,
}"
>
<!-- 表格 -->
<div class="min-h-0 flex-1 overflow-auto">
<Table
:columns="columns"
:data-source="productList"
:loading="loading"
:pagination="false"
:scroll="{ x: 'max-content' }"
size="small"
bordered
row-key="productId"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'mainImage'">
<div
v-if="record.mainImage"
style="
display: flex;
justify-content: center;
align-items: center;
"
>
<Image
:src="record.mainImage"
:alt="record.productName"
:preview="false"
style="
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 4px;
"
/>
</div>
<div
v-else
style="
display: flex;
justify-content: center;
align-items: center;
"
>
<span style="color: #999">暂无图片</span>
</div>
</template>
</template>
</Table>
</div>
</Card>
</Page>
</template>
@@ -232,13 +232,7 @@ function handleViewDetails(record: ShopVO.Info) {
</script>
<template>
<Page title="店铺管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理电商店铺信息,包括店铺基本信息、平台信息和Logo设置
</div>
</template>
<Page auto-content-height>
<!-- VbenVxeGrid 表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->