feat(order): 订单管理搜索表单添加商品选择器,支持按商品名称搜索并按商品ID过滤

This commit is contained in:
小蟑螂
2026-04-25 13:18:40 +08:00
parent 0de9d4cdd2
commit 55eb2a1d3f
4 changed files with 121 additions and 2 deletions
@@ -69,4 +69,10 @@ public class OrderFilterDTO {
*/
@Schema(description = "确认", example = "1")
private Integer confirm;
/**
* 商品ID
*/
@Schema(description = "商品ID", example = "1")
private Long productId;
}
@@ -312,6 +312,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
if (filter.getConfirm() != null) {
wrapper.eq(OrderPO::getConfirm, filter.getConfirm());
}
if (filter.getProductId() != null) {
wrapper.eq(OrderPO::getProductId, filter.getProductId());
}
}
// 排序(支持多字段自定义排序,默认按下单时间降序 + 创建时间降序)
@@ -89,6 +89,8 @@ export namespace OrderDTO {
startOrderTime?: string;
/** 下单时间范围-结束时间 */
endOrderTime?: string;
/** 商品ID */
productId?: number;
}
/** 批量导入订单参数 */
@@ -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<typeof setTimeout> = 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<typeof setTimeout> = 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<ProductDTO.Filters> = {
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<any> = {
columns: [
@@ -278,6 +350,7 @@ const gridOptions: VxeGridProps<any> = {
statusId: searchParams.statusId ?? searchForm.value.statusId,
startOrderTime: searchForm.value.startOrderTime,
endOrderTime: searchForm.value.endOrderTime,
productId: searchParams.productId ?? searchForm.value.productId,
};
const params: PageQueryDTO<OrderDTO.Filters> = {
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();
// 店铺、订单状态、商品选择器改为点击时懒加载,不再预加载
});
</script>