This commit is contained in:
ah--desktop
2025-12-11 08:04:56 +08:00
parent a3b8797955
commit 5129657f7f
69 changed files with 1695 additions and 545 deletions
@@ -0,0 +1,77 @@
import type { ProductSpecDTO, ProductSpecVO } from './types';
import type { ProductVO } from '#/api/ecommerce/product/types';
import type { PageQueryDTO, PageResultVO } from '#/types/common';
import { requestClient } from '#/api/request';
/**
* 商品规格管理API
*/
/**
* 创建商品规格
*/
export async function createProductSpecApi(data: ProductSpecDTO.Create) {
return requestClient.post<ProductSpecVO.Info>(
'/ec/product-spec/create',
data,
);
}
/**
* 更新商品规格
*/
export async function updateProductSpecApi(
id: number,
data: ProductSpecDTO.Update,
) {
return requestClient.put<ProductSpecVO.Info>(
`/ec/product-spec/update/${id}`,
data,
);
}
/**
* 删除商品规格
*/
export async function deleteProductSpecApi(id: number) {
return requestClient.delete(`/ec/product-spec/delete/${id}`);
}
/**
* 分页获取商品规格列表
*/
export async function getProductSpecPageApi(
params: PageQueryDTO<ProductSpecDTO.Filters>,
) {
return requestClient.post<PageResultVO<ProductSpecVO.Info>>(
'/ec/product-spec/page',
params,
);
}
/**
* 根据商品名称和规格编码精准查询商品规格
*/
export async function getProductSpecByProductAndSpecApi(
productName: string,
specCode: string,
) {
return requestClient.get<ProductSpecVO.Info>(
`/ec/product-spec/find-by-product-and-spec/${encodeURIComponent(productName)}/${encodeURIComponent(specCode)}`,
);
}
/**
* 批量根据商品名称和规格编码查询商品规格
* 返回商品信息列表,每个商品包含匹配的规格信息
*/
export async function getProductSpecsByProductAndSpecsApi(
queries: ProductSpecDTO.Query[],
) {
return requestClient.post<ProductVO.Info[]>(
'/ec/product-spec/find-by-product-and-specs',
queries,
);
}
@@ -0,0 +1,6 @@
/**
* 商品规格模块API导出
*/
export * from './apis';
export * from './types';
@@ -0,0 +1,2 @@
export * from './types.dto';
export * from './types.vo';
@@ -0,0 +1,47 @@
/**
* 商品规格相关DTO类型定义
*/
export namespace ProductSpecDTO {
/** 创建商品规格参数 */
export interface Create {
/** 商品ID */
productId: number;
/** 规格名称 */
name: string;
/** 规格编码 */
specCode?: string;
/** 成本价 */
costPrice: number;
}
/** 更新商品规格参数 */
export interface Update {
/** 规格名称 */
name: string;
/** 规格编码 */
specCode?: string;
/** 成本价 */
costPrice: number;
}
/** 商品规格过滤条件 */
export interface Filters {
/** 商品ID */
productId?: number;
/** 规格ID */
id?: number;
/** 规格名称 */
name?: string;
/** 规格编码 */
specCode?: string;
}
/** 商品规格查询DTO(用于批量查询) */
export interface Query {
/** 商品名称 */
productName: string;
/** 规格编码 */
specCode: string;
}
}
@@ -0,0 +1,31 @@
/**
* 商品规格相关VO类型定义
*/
export namespace ProductSpecVO {
/** 商品规格信息 */
export interface Info {
/** 规格ID */
id: number;
/** 公司ID */
companyId: number;
/** 商品ID */
productId: number;
/** 商品名称 */
productName: string;
/** 规格名称 */
name: string;
/** 规格编码 */
specCode?: string;
/** 成本价 */
costPrice: number;
/** 创建时间 */
createTime: string;
/** 更新时间 */
updateTime: string;
/** 创建人ID */
createBy?: number;
/** 更新人ID */
updateBy?: number;
}
}
@@ -40,96 +40,3 @@ export async function updateProductApi(id: number, data: ProductDTO.Update) {
export async function deleteProductApi(id: number) {
return requestClient.delete(`/ec/product/delete/${id}`);
}
/**
* 商品规格管理API
*/
/**
* 分页获取商品规格列表
*/
export async function getProductSpecPageApi(
params: PageQueryDTO<ProductDTO.SpecFilters>,
) {
return requestClient.post<PageResultVO<ProductVO.SpecInfo>>(
'/ec/product-spec/page',
params,
);
}
/**
* 创建商品规格
*/
export async function createProductSpecApi(data: ProductDTO.CreateSpec) {
return requestClient.post<ProductVO.SpecInfo>(
'/ec/product-spec/create',
data,
);
}
/**
* 更新商品规格
*/
export async function updateProductSpecApi(
id: number,
data: ProductDTO.UpdateSpec,
) {
return requestClient.put<ProductVO.SpecInfo>(
`/ec/product-spec/update/${id}`,
data,
);
}
/**
* 删除商品规格
*/
export async function deleteProductSpecApi(id: number) {
return requestClient.delete(`/ec/product-spec/delete/${id}`);
}
/**
* 精准查询API - 用于数据导入
*/
/**
* 根据名称精准查询商品
*/
export async function getProductByNameApi(name: string) {
return requestClient.get<ProductVO.Info>(
`/ec/product/find-by-name/${encodeURIComponent(name)}`,
);
}
/**
* 批量根据名称查询商品
*/
export async function getProductsByNamesApi(names: string[]) {
return requestClient.post<ProductVO.Info[]>(
'/ec/product/find-by-names',
names,
);
}
/**
* 根据商品名称和规格编码精准查询商品规格
*/
export async function getProductSpecByProductAndSpecApi(
productName: string,
specCode: string,
) {
return requestClient.get<ProductVO.SpecInfo>(
`/ec/product-spec/find-by-product-and-spec/${encodeURIComponent(productName)}/${encodeURIComponent(specCode)}`,
);
}
/**
* 批量根据商品名称和规格编码查询商品规格
*/
export async function getProductSpecsByProductAndSpecsApi(
queries: { productName: string; specCode: string }[],
) {
return requestClient.post<ProductVO.Info[]>(
'/ec/product-spec/find-by-product-and-specs',
queries,
);
}
@@ -21,14 +21,8 @@ export namespace ProductDTO {
name: string;
/** 商品编码 */
productCode?: string;
/** 商品编码 */
specCode?: string;
/** 商品SKU */
skuCode?: string;
/** 主图图片ID */
mainImageId?: number;
/** 成本价 */
costPrice: number;
}
/** 商品规格DTO */
@@ -65,18 +59,12 @@ export namespace ProductDTO {
/** 商品过滤条件 */
export interface Filters {
/** 商品ID */
id?: number;
/** 商品名称(模糊查询) */
name?: string;
/** 商品编码(模糊查询) */
productCode?: string;
/** 商品编码(模糊查询) */
specCode?: string;
/** 商品SKU(模糊查询) */
skuCode?: string;
/** 成本价范围-最小值 */
minCostPrice?: number;
/** 成本价范围-最大值 */
maxCostPrice?: number;
}
/** 商品规格过滤条件 */
@@ -50,21 +50,29 @@ export async function uploadShopLogoApi(file: File) {
}
/**
* 精准查询API - 用于数据导入
* 获取店铺当月统计信息
*/
/**
* 根据名称精准查询店铺
*/
export async function getShopByNameApi(name: string) {
return requestClient.get<ShopVO.Info>(
`/ec/shop/find-by-name/${encodeURIComponent(name)}`,
export async function getShopCurrentMonthStatisticsApi(id: number) {
return requestClient.get<ShopVO.Statistics>(
`/ec/shop/statistics/current-month/${id}`,
);
}
/**
* 批量根据名称查询店铺
* 获取店铺统计信息
*/
export async function getShopsByNamesApi(names: string[]) {
return requestClient.post<ShopVO.Info[]>('/ec/shop/find-by-names', names);
export async function getShopStatisticsApi(params: ShopDTO.StatisticsQuery) {
return requestClient.post<ShopVO.Statistics>('/ec/shop/statistics', params);
}
/**
* 分页获取店铺商品详细信息
*/
export async function getShopProductPageApi(
params: PageQueryDTO<ShopDTO.ProductFilters>,
) {
return requestClient.post<PageResultVO<ShopVO.ProductDetail>>(
'/ec/shop/products/page',
params,
);
}
@@ -30,4 +30,26 @@ export namespace ShopDTO {
/** 平台 */
platform?: string;
}
/** 店铺统计查询参数 */
export interface StatisticsQuery {
/** 店铺ID */
shopId: number;
/** 开始日期 */
startDate: string;
/** 结束日期 */
endDate: string;
}
/** 店铺商品过滤条件 */
export interface ProductFilters {
/** 店铺ID */
shopId: number;
/** 商品名称(模糊查询) */
productName?: string;
/** 商品编码(模糊查询) */
productCode?: string;
/** 统计日期(不传默认为当日) */
statDate?: string;
}
}
@@ -26,4 +26,48 @@ export namespace ShopVO {
/** 更新人ID */
updateBy?: number;
}
/** 店铺统计信息 */
export interface Statistics {
/** 销售额(商家实收金额总和) */
salesAmount: number;
/** 订单数 */
orderCount: number;
/** 客单价(销售额/订单数) */
averageOrderValue: number;
/** 成本(成本价*数量总和) */
costAmount: number;
/** 退款金额(已退款订单的实收金额总和) */
refundAmount: number;
/** 推广费 */
promotionFee: number;
/** 费比(推广费/销售额) */
feeRatio: number;
}
/** 店铺商品详细信息 */
export interface ProductDetail {
/** 商品ID */
productId: number;
/** 商品名称 */
productName: string;
/** 商品编码 */
productCode?: string;
/** 主图URL */
mainImage?: string;
/** 关联ID */
relationId: number;
/** 排序 */
sortOrder: number;
/** 创建时间 */
createTime: string;
/** 更新时间 */
updateTime: string;
/** 销售额(商家实收金额总和) */
salesAmount: number;
/** 订单数 */
orderCount: number;
/** 客单价(销售额/订单数) */
averageOrderValue: number;
}
}
@@ -19,15 +19,6 @@ const routes: RouteRecordRaw[] = [
title: '数据导入',
},
},
{
name: 'DataAnalysis',
path: '/data/analysis',
component: () => import('#/views/ecommerce/data-analysis/index.vue'),
meta: {
icon: 'lucide:bar-chart-3',
title: '数据分析',
},
},
],
},
];
@@ -1,81 +0,0 @@
import type { RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'lucide:store',
order: 50,
title: '店铺管理',
},
name: 'Shop',
path: '/shop',
children: [
{
name: 'ShopManagement',
path: '/shop/shop-management',
component: () => import('#/views/shop/shop/index.vue'),
meta: {
icon: 'lucide:store',
title: '店铺管理',
},
},
{
name: 'ProductManagement',
path: '/shop/product-management',
component: () => import('#/views/shop/product/index.vue'),
meta: {
icon: 'lucide:package',
title: '商品管理',
},
},
{
name: 'OrderManagement',
path: '/shop/order-management',
component: () => import('#/views/shop/order/index.vue'),
meta: {
icon: 'lucide:shopping-cart',
title: '订单管理',
},
},
{
name: 'PromotionFeeManagement',
path: '/shop/promotion-fee-management',
component: () => import('#/views/shop/promotion-fee/index.vue'),
meta: {
icon: 'lucide:credit-card',
title: '推广费管理',
},
},
{
name: 'ConfigManagement',
path: '/shop/config-management',
meta: {
icon: 'lucide:settings',
title: '配置管理',
},
children: [
{
name: 'OrderStatusConfig',
path: '/shop/config-management/order-status',
component: () => import('#/views/shop/config/order-status-config/index.vue'),
meta: {
icon: 'lucide:list-checks',
title: '订单状态类型',
},
},
{
name: 'PromotionFeeTypeConfig',
path: '/shop/config-management/promotion-fee-type',
component: () => import('#/views/shop/config/promotion-fee-type-config/index.vue'),
meta: {
icon: 'lucide:percent',
title: '推广费用类型',
},
},
],
},
],
},
];
export default routes;
@@ -1,9 +1,15 @@
<script lang="ts" setup>
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
import type {
ProductSpecDTO,
ProductSpecVO,
} from '#/api/ecommerce/product-spec/types';
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { ref } from 'vue';
import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
@@ -14,11 +20,14 @@ import {
InputNumber,
message,
Select,
Spin,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import { createOrderApi, updateOrderApi } from '#/api/ecommerce/order';
import { getActiveOrderStatusListApi } from '#/api/ecommerce/order-status';
import { getProductPageApi } from '#/api/ecommerce/product';
import { getProductSpecPageApi } from '#/api/ecommerce/product-spec';
import { getShopPageApi } from '#/api/ecommerce/shop';
const emit = defineEmits<{
@@ -63,6 +72,20 @@ const formData = ref<Partial<OrderDTO.Create>>({
const shopOptions = ref<{ label: string; value: number }[]>([]);
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
// 商品选项数据
const productOptions = ref<
{ label: string; product: ProductVO.Info; value: number }[]
>([]);
const productLoading = ref(false);
const productSearchKeyword = ref('');
// 规格选项数据
const productSpecOptions = ref<
{ label: string; spec: ProductSpecVO.Info; value: number }[]
>([]);
const productSpecLoading = ref(false);
const productSpecSearchKeyword = ref('');
// 表单验证规则
const rules = {
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
@@ -71,7 +94,7 @@ const rules = {
{ required: true, message: '请输入实收金额', trigger: 'blur' },
],
orderDate: [{ required: true, message: '请选择下单时间', trigger: 'change' }],
productId: [{ required: true, message: '请输入商品ID', trigger: 'blur' }],
productId: [{ required: true, message: '请选择商品', trigger: 'change' }],
productName: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
quantity: [{ required: true, message: '请输入数量', trigger: 'blur' }],
unitPrice: [{ required: true, message: '请输入销售单价', trigger: 'blur' }],
@@ -112,8 +135,114 @@ async function fetchOrderStatusOptions() {
}
}
// 搜索商品
async function searchProducts(keyword: string) {
productSearchKeyword.value = keyword;
productLoading.value = true;
try {
const params: PageQueryDTO<ProductDTO.Filters> = {
page: 1,
pageSize: 50,
filters: {
name: keyword || undefined,
},
};
const data = await getProductPageApi(params);
productOptions.value = data.records.map((product: ProductVO.Info) => ({
label: `${product.name}${product.productCode ? ` (${product.productCode})` : ''}`,
value: product.id,
product,
}));
} catch (error) {
console.error('搜索商品失败:', error);
message.error('搜索商品失败');
} finally {
productLoading.value = false;
}
}
// 搜索规格
async function searchProductSpecs(keyword: string) {
if (!formData.value.productId) {
productSpecOptions.value = [];
return;
}
productSpecSearchKeyword.value = keyword;
productSpecLoading.value = true;
try {
const params: PageQueryDTO<ProductSpecDTO.Filters> = {
page: 1,
pageSize: 50,
filters: {
productId: formData.value.productId,
name: keyword || undefined,
},
};
const data = await getProductSpecPageApi(params);
productSpecOptions.value = data.records.map((spec: ProductSpecVO.Info) => ({
label: `${spec.name}${spec.specCode ? ` (${spec.specCode})` : ''}`,
value: spec.id,
spec,
}));
} catch (error) {
console.error('搜索规格失败:', error);
message.error('搜索规格失败');
} finally {
productSpecLoading.value = false;
}
}
// 处理商品选择
function handleProductChange(productId: number | undefined) {
if (productId) {
const selectedProduct = productOptions.value.find(
(opt) => opt.value === productId,
);
if (selectedProduct) {
formData.value.productName = selectedProduct.product.name;
// 加载该商品的规格列表
searchProductSpecs('');
}
} else {
formData.value.productName = '';
formData.value.productSpecId = undefined;
formData.value.specName = '';
formData.value.costPrice = 0;
productSpecOptions.value = [];
}
}
// 处理规格选择
function handleProductSpecChange(specId: number | undefined) {
if (specId) {
const selectedSpec = productSpecOptions.value.find(
(opt) => opt.value === specId,
);
if (selectedSpec) {
formData.value.specName = selectedSpec.spec.name;
formData.value.costPrice = selectedSpec.spec.costPrice;
}
} else {
formData.value.specName = '';
formData.value.costPrice = 0;
}
}
// 监听商品ID变化,加载规格列表
watch(
() => formData.value.productId,
(newProductId) => {
if (newProductId) {
searchProductSpecs('');
} else {
productSpecOptions.value = [];
formData.value.productSpecId = undefined;
}
},
);
// 打开模态框
function open(edit: boolean, record?: OrderVO.Info) {
async function open(edit: boolean, record?: OrderVO.Info) {
isEdit.value = edit;
currentRecord.value = record || null;
@@ -156,6 +285,41 @@ function open(edit: boolean, record?: OrderVO.Info) {
unitPrice: 0,
costPrice: 0,
};
// 如果是编辑模式且有商品ID,加载商品和规格选项
if (edit && record?.productId) {
await searchProducts(record.productName || '');
// 确保选中的商品在选项中
if (!productOptions.value.some((opt) => opt.value === record.productId)) {
productOptions.value.push({
label: record.productName,
value: record.productId,
product: {
id: record.productId,
name: record.productName,
} as ProductVO.Info,
});
}
if (record.productSpecId) {
await searchProductSpecs(record.specName || '');
// 确保选中的规格在选项中
if (
!productSpecOptions.value.some(
(opt) => opt.value === record.productSpecId,
)
) {
productSpecOptions.value.push({
label: record.specName || '',
value: record.productSpecId,
spec: {
id: record.productSpecId,
name: record.specName || '',
costPrice: record.costPrice,
} as ProductSpecVO.Info,
});
}
}
}
}
// 关闭模态框
@@ -272,22 +436,57 @@ defineExpose({
</div>
<div class="grid grid-cols-2 gap-4">
<Form.Item label="商品ID" name="productId">
<InputNumber
<Form.Item label="商品" name="productId">
<Select
v-model:value="formData.productId"
placeholder="请输入商品ID"
style="width: 100%"
:min="1"
/>
placeholder="请搜索并选择商品"
show-search
:filter-option="false"
:loading="productLoading"
:options="productOptions"
@search="searchProducts"
@change="(value) => handleProductChange(value as number)"
>
<template #notFoundContent>
<div v-if="productLoading" class="py-4 text-center">
<Spin size="small" />
<div class="mt-2">加载中...</div>
</div>
<div v-else class="py-4 text-center text-gray-400">
{{ productSearchKeyword ? '未找到商品' : '请输入商品名称搜索' }}
</div>
</template>
</Select>
</Form.Item>
<Form.Item label="商品规格ID" name="productSpecId">
<InputNumber
<Form.Item label="商品规格" name="productSpecId">
<Select
v-model:value="formData.productSpecId"
placeholder="请输入商品规格ID(可选)"
style="width: 100%"
:min="1"
/>
placeholder="请先选择商品,然后搜索规格"
show-search
:filter-option="false"
:loading="productSpecLoading"
:disabled="!formData.productId"
:options="productSpecOptions"
@search="searchProductSpecs"
@change="(value) => handleProductSpecChange(value as number)"
>
<template #notFoundContent>
<div v-if="productSpecLoading" class="py-4 text-center">
<Spin size="small" />
<div class="mt-2">加载中...</div>
</div>
<div v-else class="py-4 text-center text-gray-400">
{{
formData.productId
? productSpecSearchKeyword
? '未找到规格'
: '请输入规格名称搜索'
: '请先选择商品'
}}
</div>
</template>
</Select>
</Form.Item>
</div>
@@ -6,15 +6,7 @@ import { computed, h, onUnmounted, ref, resolveComponent } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import {
Button,
Form,
Input,
InputNumber,
message,
Space,
Table,
} from 'ant-design-vue';
import { Button, Form, Input, message, Space, Table } from 'ant-design-vue';
import { createProductApi, updateProductApi } from '#/api/ecommerce/product';
import { uploadImageApi } from '#/api/media/image';
@@ -180,10 +172,7 @@ async function handleSubmit() {
const updateData: ProductDTO.Update = {
name: submitData.name,
productCode: submitData.productCode || undefined,
specCode: submitData.specCode || undefined,
skuCode: submitData.skuCode || undefined,
mainImageId: submitData.mainImageId,
costPrice: submitData.costPrice,
};
await updateProductApi(currentProductData.value.id, updateData);
message.success('更新成功');
@@ -528,30 +517,6 @@ onUnmounted(() => {
/>
</Form.Item>
<Form.Item v-if="isEdit" label="规格编码" name="specCode">
<Input v-model:value="formData.specCode" placeholder="请输入规格编码" />
</Form.Item>
<Form.Item v-if="isEdit" label="商品SKU" name="skuCode">
<Input v-model:value="formData.skuCode" placeholder="请输入商品SKU" />
</Form.Item>
<Form.Item
v-if="isEdit"
label="成本价"
name="costPrice"
:rules="[{ required: true, message: '请输入成本价' }]"
>
<InputNumber
v-model:value="formData.costPrice"
placeholder="请输入成本价"
style="width: 100%"
:min="0"
:precision="2"
:step="0.01"
/>
</Form.Item>
<!-- 规格管理 -->
<Form.Item v-if="!isEdit" label="商品规格">
<div class="space-y-4">
@@ -1,5 +1,9 @@
<script lang="ts" setup>
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
import type {
ProductSpecDTO,
ProductSpecVO,
} from '#/api/ecommerce/product-spec/types';
import type { ProductVO } from '#/api/ecommerce/product/types';
import type { PageQueryDTO } from '#/types/common';
import { h, ref } from 'vue';
@@ -21,7 +25,7 @@ import {
deleteProductSpecApi,
getProductSpecPageApi,
updateProductSpecApi,
} from '#/api/ecommerce/product';
} from '#/api/ecommerce/product-spec';
interface Emits {
(e: 'success'): void;
@@ -34,7 +38,7 @@ const currentProduct = ref<null | ProductVO.Info>(null);
// 响应式数据
const specLoading = ref(false);
const specList = ref<ProductVO.SpecInfo[]>([]);
const specList = ref<ProductSpecVO.Info[]>([]);
const specTotal = ref(0);
const specCurrent = ref(1);
const specPageSize = ref(10);
@@ -73,7 +77,7 @@ async function handleSpecSubmit() {
if (isEditSpec.value && currentSpecId.value) {
await updateProductSpecApi(
currentSpecId.value,
specFormData.value as ProductDTO.UpdateSpec,
specFormData.value as ProductSpecDTO.Update,
);
message.success('更新成功');
} else {
@@ -82,7 +86,7 @@ async function handleSpecSubmit() {
return;
}
const createData: ProductDTO.CreateSpec = {
const createData: ProductSpecDTO.Create = {
productId: currentProduct.value.id,
...specFormData.value,
};
@@ -149,7 +153,7 @@ const columns = [
dataIndex: 'costPrice',
key: 'costPrice',
width: 120,
customRender: ({ record }: { record: ProductVO.SpecInfo }) => {
customRender: ({ record }: { record: ProductSpecVO.Info }) => {
return `¥${record.costPrice.toFixed(2)}`;
},
},
@@ -164,7 +168,7 @@ const columns = [
key: 'action',
width: 150,
fixed: 'right' as const,
customRender: ({ record }: { record: ProductVO.SpecInfo }) => {
customRender: ({ record }: { record: ProductSpecVO.Info }) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
h(
Button,
@@ -200,7 +204,7 @@ async function fetchSpecList() {
try {
specLoading.value = true;
const params: PageQueryDTO<ProductDTO.SpecFilters> = {
const params: PageQueryDTO<ProductSpecDTO.Filters> = {
page: specCurrent.value,
pageSize: specPageSize.value,
filters: {
@@ -239,7 +243,7 @@ function handleAddSpec() {
}
// 处理编辑规格
function handleEditSpec(record: ProductVO.SpecInfo) {
function handleEditSpec(record: ProductSpecVO.Info) {
isEditSpec.value = true;
currentSpecId.value = record.id;
specFormData.value = {
@@ -252,7 +256,7 @@ function handleEditSpec(record: ProductVO.SpecInfo) {
}
// 处理删除规格
async function handleDeleteSpec(record: ProductVO.SpecInfo) {
async function handleDeleteSpec(record: ProductSpecVO.Info) {
try {
await deleteProductSpecApi(record.id);
message.success('删除成功');
@@ -30,12 +30,9 @@ const productGridViewRef = ref<null | { refreshTable: () => void }>(null);
// 搜索表单
const searchForm = ref({
id: undefined as number | undefined,
name: '',
productCode: '',
specCode: '',
skuCode: '',
minCostPrice: undefined as number | undefined,
maxCostPrice: undefined as number | undefined,
});
// 刷新表格数据
@@ -27,12 +27,9 @@ defineOptions({ name: 'ProductGridView' });
const props = defineProps<{
searchForm: {
maxCostPrice?: number;
minCostPrice?: number;
id?: number;
name: string;
productCode: string;
skuCode: string;
specCode: string;
};
}>();
@@ -54,12 +51,9 @@ const scrollContainerRef = ref<HTMLElement | null>(null);
// 本地搜索表单副本(用于 v-model)
const localSearchForm = ref({
id: props.searchForm.id,
name: props.searchForm.name,
productCode: props.searchForm.productCode,
specCode: props.searchForm.specCode,
skuCode: props.searchForm.skuCode,
minCostPrice: props.searchForm.minCostPrice,
maxCostPrice: props.searchForm.maxCostPrice,
});
// 监听 props 变化,同步到本地
@@ -67,19 +61,13 @@ watch(
() => props.searchForm,
(newForm) => {
if (
localSearchForm.value.id !== newForm.id ||
localSearchForm.value.name !== newForm.name ||
localSearchForm.value.productCode !== newForm.productCode ||
localSearchForm.value.specCode !== newForm.specCode ||
localSearchForm.value.skuCode !== newForm.skuCode ||
localSearchForm.value.minCostPrice !== newForm.minCostPrice ||
localSearchForm.value.maxCostPrice !== newForm.maxCostPrice
localSearchForm.value.productCode !== newForm.productCode
) {
localSearchForm.value.id = newForm.id;
localSearchForm.value.name = newForm.name;
localSearchForm.value.productCode = newForm.productCode;
localSearchForm.value.specCode = newForm.specCode;
localSearchForm.value.skuCode = newForm.skuCode;
localSearchForm.value.minCostPrice = newForm.minCostPrice;
localSearchForm.value.maxCostPrice = newForm.maxCostPrice;
// 重置分页和列表
current.value = 1;
productList.value = [];
@@ -95,12 +83,9 @@ watch(
localSearchForm,
(newForm) => {
if (
props.searchForm.id !== newForm.id ||
props.searchForm.name !== newForm.name ||
props.searchForm.productCode !== newForm.productCode ||
props.searchForm.specCode !== newForm.specCode ||
props.searchForm.skuCode !== newForm.skuCode ||
props.searchForm.minCostPrice !== newForm.minCostPrice ||
props.searchForm.maxCostPrice !== newForm.maxCostPrice
props.searchForm.productCode !== newForm.productCode
) {
emit('update:searchForm', { ...newForm });
}
@@ -118,12 +103,9 @@ const loadProductList = async (reset = false) => {
page: current.value,
pageSize: pageSize.value,
filters: {
id: localSearchForm.value.id,
name: localSearchForm.value.name || undefined,
productCode: localSearchForm.value.productCode || undefined,
specCode: localSearchForm.value.specCode || undefined,
skuCode: localSearchForm.value.skuCode || undefined,
minCostPrice: localSearchForm.value.minCostPrice,
maxCostPrice: localSearchForm.value.maxCostPrice,
},
};
@@ -164,10 +146,7 @@ const handleReset = () => {
localSearchForm.value = {
name: '',
productCode: '',
specCode: '',
skuCode: '',
minCostPrice: undefined,
maxCostPrice: undefined,
id: undefined,
};
handleSearch();
};
@@ -249,43 +228,15 @@ onUnmounted(() => {
@press-enter="handleSearch"
/>
</Form.Item>
<Form.Item label="规格编码" class="mb-0">
<Input
v-model:value="localSearchForm.specCode"
placeholder="请输入规格编码"
<Form.Item label="商品ID" class="mb-0">
<InputNumber
v-model:value="localSearchForm.id"
placeholder="请输入商品ID"
style="width: 150px"
allow-clear
@press-enter="handleSearch"
/>
</Form.Item>
<Form.Item label="商品SKU" class="mb-0">
<Input
v-model:value="localSearchForm.skuCode"
placeholder="请输入商品SKU"
style="width: 150px"
allow-clear
@press-enter="handleSearch"
/>
</Form.Item>
<Form.Item label="成本价范围" class="mb-0">
<div class="flex items-center gap-2">
<InputNumber
v-model:value="localSearchForm.minCostPrice"
placeholder="最小值"
style="width: 100px"
:min="0"
:precision="2"
/>
<span class="text-gray-500">-</span>
<InputNumber
v-model:value="localSearchForm.maxCostPrice"
placeholder="最大值"
style="width: 100px"
:min="0"
:precision="2"
/>
</div>
</Form.Item>
<Form.Item class="mb-0">
<Space>
<Button type="primary" @click="handleSearch">搜索</Button>
@@ -14,12 +14,9 @@ defineOptions({ name: 'ProductListView' });
const props = defineProps<{
searchForm: {
maxCostPrice?: number;
minCostPrice?: number;
id?: number;
name: string;
productCode: string;
skuCode: string;
specCode: string;
};
}>();
@@ -35,12 +32,9 @@ const loading = ref(false);
// 本地搜索表单副本(用于 v-model)
const localSearchForm = ref({
id: props.searchForm.id,
name: props.searchForm.name,
productCode: props.searchForm.productCode,
specCode: props.searchForm.specCode,
skuCode: props.searchForm.skuCode,
minCostPrice: props.searchForm.minCostPrice,
maxCostPrice: props.searchForm.maxCostPrice,
});
// 监听 props 变化,同步到本地
@@ -48,19 +42,13 @@ watch(
() => props.searchForm,
(newForm) => {
if (
localSearchForm.value.id !== newForm.id ||
localSearchForm.value.name !== newForm.name ||
localSearchForm.value.productCode !== newForm.productCode ||
localSearchForm.value.specCode !== newForm.specCode ||
localSearchForm.value.skuCode !== newForm.skuCode ||
localSearchForm.value.minCostPrice !== newForm.minCostPrice ||
localSearchForm.value.maxCostPrice !== newForm.maxCostPrice
localSearchForm.value.productCode !== newForm.productCode
) {
localSearchForm.value.id = newForm.id;
localSearchForm.value.name = newForm.name;
localSearchForm.value.productCode = newForm.productCode;
localSearchForm.value.specCode = newForm.specCode;
localSearchForm.value.skuCode = newForm.skuCode;
localSearchForm.value.minCostPrice = newForm.minCostPrice;
localSearchForm.value.maxCostPrice = newForm.maxCostPrice;
refreshTable();
}
},
@@ -72,12 +60,9 @@ watch(
localSearchForm,
(newForm) => {
if (
props.searchForm.id !== newForm.id ||
props.searchForm.name !== newForm.name ||
props.searchForm.productCode !== newForm.productCode ||
props.searchForm.specCode !== newForm.specCode ||
props.searchForm.skuCode !== newForm.skuCode ||
props.searchForm.minCostPrice !== newForm.minCostPrice ||
props.searchForm.maxCostPrice !== newForm.maxCostPrice
props.searchForm.productCode !== newForm.productCode
) {
emit('update:searchForm', { ...newForm });
}
@@ -177,12 +162,9 @@ const gridOptions: VxeGridProps<any> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
id: localSearchForm.value.id,
name: localSearchForm.value.name || undefined,
productCode: localSearchForm.value.productCode || undefined,
specCode: localSearchForm.value.specCode || undefined,
skuCode: localSearchForm.value.skuCode || undefined,
minCostPrice: localSearchForm.value.minCostPrice,
maxCostPrice: localSearchForm.value.maxCostPrice,
},
};
const data = await getProductPageApi(params);
@@ -224,43 +206,14 @@ const formOptions = computed(() => ({
fieldName: 'productCode',
label: '商品编码',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入规格编码',
},
fieldName: 'specCode',
label: '规格编码',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入商品SKU',
},
fieldName: 'skuCode',
label: '商品SKU',
},
{
component: 'InputNumber',
componentProps: {
placeholder: '最小值',
min: 0,
precision: 2,
placeholder: '请输入商品ID',
style: { width: '100%' },
},
fieldName: 'minCostPrice',
label: '成本价最小值',
},
{
component: 'InputNumber',
componentProps: {
placeholder: '最大值',
min: 0,
precision: 2,
style: { width: '100%' },
},
fieldName: 'maxCostPrice',
label: '成本价最大值',
fieldName: 'id',
label: '商品ID',
},
],
showDefaultActions: true,
@@ -0,0 +1,367 @@
<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 { 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 { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
getShopProductPageApi,
getShopStatisticsApi,
} from '#/api/ecommerce/shop';
defineOptions({ name: 'ShopDetails' });
const route = useRoute();
// 店铺ID(从路由参数获取)
const shopId = computed(() => {
const id = route.params.id;
return id ? Number(id) : 0;
});
// 响应式数据
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(),
]);
// 格式化金额
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 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,
},
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
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'
)[],
},
// 配置远程加载
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;
}
},
},
},
};
// 搜索表单配置 - 使用稳定的对象引用
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: '商品列表',
});
// 初始化数据
onMounted(() => {
if (shopId.value) {
fetchCustomStatistics();
// 手动触发表格加载,确保 shopId 有值
setTimeout(() => {
if (gridApi && shopId.value) {
gridApi.reload();
}
}, 100);
} else {
message.error('店铺ID不存在');
}
});
</script>
<template>
<Page title="店铺详情" auto-content-height>
<!-- 店铺统计信息 -->
<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>
<!-- 商品列表表格 -->
<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>
</Page>
</template>
@@ -4,6 +4,7 @@ import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
@@ -17,6 +18,8 @@ import ShopFormModal from './components/ShopFormModal.vue';
defineOptions({ name: 'ShopManagement' });
const router = useRouter();
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
@@ -59,6 +62,7 @@ const gridOptions: VxeGridProps<any> = {
title: '店铺名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
slots: { default: 'name' },
},
{
field: 'platform',
@@ -220,6 +224,11 @@ async function handleDelete(record: ShopVO.Info) {
function handleModalSuccess() {
refreshTable();
}
// 处理查看详情
function handleViewDetails(record: ShopVO.Info) {
router.push(`/ecom/shop/details/${record.id}`);
}
</script>
<template>
@@ -267,9 +276,22 @@ function handleModalSuccess() {
</div>
</template>
<!-- 店铺名称列 -->
<template #name="{ row }: { row: ShopVO.Info }">
<a
class="text-primary cursor-pointer hover:underline"
@click="handleViewDetails(row)"
>
{{ row.name }}
</a>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" type="primary" @click="handleViewDetails(row)">
查看详情
</Button>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Popconfirm
title="确定要删除这个店铺吗?"