From 55eb2a1d3f0dfc44397d7dc67bff7776877c462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Sat, 25 Apr 2026 13:18:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(order):=20=E8=AE=A2=E5=8D=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=90=9C=E7=B4=A2=E8=A1=A8=E5=8D=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=95=86=E5=93=81=E9=80=89=E6=8B=A9=E5=99=A8=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E5=95=86=E5=93=81=E5=90=8D=E7=A7=B0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=B9=B6=E6=8C=89=E5=95=86=E5=93=81ID=E8=BF=87?= =?UTF-8?q?=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ecom/order/model/dto/OrderFilterDTO.java | 6 + .../order/service/impl/OrderServiceImpl.java | 3 + .../api/ecommerce/order/types/types.dto.ts | 2 + .../src/views/ecommerce/order/index.vue | 112 +++++++++++++++++- 4 files changed, 121 insertions(+), 2 deletions(-) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/model/dto/OrderFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/model/dto/OrderFilterDTO.java index 5cf1e8ee..ba6c22b5 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/model/dto/OrderFilterDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/model/dto/OrderFilterDTO.java @@ -69,4 +69,10 @@ public class OrderFilterDTO { */ @Schema(description = "确认", example = "1") private Integer confirm; + + /** + * 商品ID + */ + @Schema(description = "商品ID", example = "1") + private Long productId; } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/service/impl/OrderServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/service/impl/OrderServiceImpl.java index 2cde7022..7117c1a5 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/service/impl/OrderServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/order/service/impl/OrderServiceImpl.java @@ -312,6 +312,9 @@ public class OrderServiceImpl extends ServiceImpl implemen if (filter.getConfirm() != null) { wrapper.eq(OrderPO::getConfirm, filter.getConfirm()); } + if (filter.getProductId() != null) { + wrapper.eq(OrderPO::getProductId, filter.getProductId()); + } } // 排序(支持多字段自定义排序,默认按下单时间降序 + 创建时间降序) diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/order/types/types.dto.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/order/types/types.dto.ts index 3704d888..0b5ddfaf 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/order/types/types.dto.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/order/types/types.dto.ts @@ -89,6 +89,8 @@ export namespace OrderDTO { startOrderTime?: string; /** 下单时间范围-结束时间 */ endOrderTime?: string; + /** 商品ID */ + productId?: number; } /** 批量导入订单参数 */ diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue index 460ee425..2e275aad 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order/index.vue @@ -2,6 +2,7 @@ import type { VxeGridProps } from '#/adapter/vxe-table'; import type { OrderDTO, OrderVO } from '#/api/ecommerce/order'; import type { OrderStatusVO } from '#/api/ecommerce/order-status/types'; +import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types'; import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types'; import type { PageQueryDTO } from '#/types/common'; @@ -26,6 +27,7 @@ import { import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { deleteOrderApi, getOrderPageApi } from '#/api/ecommerce/order'; import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status'; +import { getProductPageApi } from '#/api/ecommerce/product'; import { getShopPageApi } from '#/api/ecommerce/shop'; import OrderFormModal from './components/OrderFormModal.vue'; @@ -54,10 +56,22 @@ const shopPageSize = 20; const shopTotal = ref(0); const shopLoading = ref(false); const shopSearchKeyword = ref(''); +const shopLoaded = ref(false); let shopSearchTimer: null | ReturnType = null; // 订单状态选项 const orderStatusOptions = ref<{ label: string; value: number }[]>([]); +const orderStatusLoaded = ref(false); + +// 商品分页数据 +const productOptions = ref<{ label: string; value: number }[]>([]); +const productPage = ref(1); +const productPageSize = 20; +const productTotal = ref(0); +const productLoading = ref(false); +const productSearchKeyword = ref(''); +const productLoaded = ref(false); +let productSearchTimer: null | ReturnType = null; // 搜索表单 const searchForm = ref({ @@ -66,6 +80,7 @@ const searchForm = ref({ statusId: undefined as number | undefined, startOrderTime: undefined as string | undefined, endOrderTime: undefined as string | undefined, + productId: undefined as number | undefined, }); // 当前排序状态 @@ -96,6 +111,7 @@ async function fetchShops(page = 1, append = false) { })); shopTotal.value = data.total; shopPage.value = page; + shopLoaded.value = true; } catch (error) { console.error('获取店铺列表失败:', error); } finally { @@ -126,6 +142,62 @@ function handleShopPopupScroll(e: Event) { } } +// 加载商品列表(支持分页) +async function fetchProducts(page = 1, append = false) { + if (productLoading.value) return; + productLoading.value = true; + try { + const params: PageQueryDTO = { + page, + pageSize: productPageSize, + filters: productSearchKeyword.value ? { name: productSearchKeyword.value } : {}, + }; + const data = await getProductPageApi(params); + productOptions.value = append + ? [ + ...productOptions.value, + ...data.records.map((product: ProductVO.Info) => ({ + label: product.name, + value: product.id, + })), + ] + : data.records.map((product: ProductVO.Info) => ({ + label: product.name, + value: product.id, + })); + productTotal.value = data.total; + productPage.value = page; + productLoaded.value = true; + } catch (error) { + console.error('获取商品列表失败:', error); + } finally { + productLoading.value = false; + } +} + +// 搜索商品(防抖) +function handleProductSearch(value: string) { + if (productSearchTimer) clearTimeout(productSearchTimer); + productSearchTimer = setTimeout(() => { + productSearchKeyword.value = value; + productPage.value = 1; + fetchProducts(1, false); + }, 300); +} + +// 滚动加载更多商品 +function handleProductPopupScroll(e: Event) { + const target = e.target as HTMLElement; + const { scrollTop, scrollHeight, clientHeight } = target; + // 滚动到底部附近时加载更多 + if (scrollHeight - scrollTop - clientHeight < 50) { + const hasMore = productPage.value * productPageSize < productTotal.value; + if (hasMore && !productLoading.value) { + fetchProducts(productPage.value + 1, true); + } + } +} + // VbenVxeGrid 表格配置 const gridOptions: VxeGridProps = { columns: [ @@ -278,6 +350,7 @@ const gridOptions: VxeGridProps = { statusId: searchParams.statusId ?? searchForm.value.statusId, startOrderTime: searchForm.value.startOrderTime, endOrderTime: searchForm.value.endOrderTime, + productId: searchParams.productId ?? searchForm.value.productId, }; const params: PageQueryDTO = { page: page.currentPage, @@ -335,6 +408,11 @@ const formOptions = computed(() => ({ showSearch: true, filterOption: false, onSearch: handleShopSearch, + onFocus: () => { + if (!shopLoaded.value) { + fetchShops(1, false); + } + }, onPopupScroll: handleShopPopupScroll, onChange: (val: any) => { searchForm.value.shopId = val; @@ -346,12 +424,42 @@ const formOptions = computed(() => ({ fieldName: 'shopId', label: '店铺', }, + { + component: 'Select', + componentProps: { + placeholder: '请选择商品(支持搜索)', + options: productOptions, + allowClear: true, + showSearch: true, + filterOption: false, + onSearch: handleProductSearch, + onFocus: () => { + if (!productLoaded.value) { + fetchProducts(1, false); + } + }, + onPopupScroll: handleProductPopupScroll, + onChange: (val: any) => { + searchForm.value.productId = val ?? undefined; + gridReloadRef.value?.(); + }, + loading: productLoading, + dropdownMenuColumnStyle: { maxHeight: '300px', overflow: 'auto' }, + }, + fieldName: 'productId', + label: '商品', + }, { component: 'Select', componentProps: { placeholder: '请选择状态', options: orderStatusOptions, allowClear: true, + onFocus: () => { + if (!orderStatusLoaded.value) { + fetchOrderStatusOptions(); + } + }, onChange: (val: any) => { searchForm.value.statusId = val; gridReloadRef.value?.(); @@ -418,6 +526,7 @@ async function fetchOrderStatusOptions() { label: status.statusName, value: status.id, })); + orderStatusLoaded.value = true; } catch (error) { console.error('获取订单状态列表失败:', error); } @@ -461,8 +570,7 @@ function handleModalSuccess() { // 初始化 onMounted(async () => { - await fetchShopOptions(); - await fetchOrderStatusOptions(); + // 店铺、订单状态、商品选择器改为点击时懒加载,不再预加载 });