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
@@ -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">
<!-- 工具栏工具 -->