mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 订单管理页店铺选择器支持搜索和分页加载
- 店铺选择器支持输入搜索(300ms防抖) - 滚动到底部自动加载更多(每页20条) - 替代原来一次加载1000条的方式
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
@@ -30,8 +30,16 @@ const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const loading = ref(false);
|
||||
const orderFormModalRef = ref();
|
||||
|
||||
// 下拉选项数据
|
||||
// 店铺分页数据
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const shopPage = ref(1);
|
||||
const shopPageSize = 20;
|
||||
const shopTotal = ref(0);
|
||||
const shopLoading = ref(false);
|
||||
const shopSearchKeyword = ref('');
|
||||
let shopSearchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
// 订单状态选项
|
||||
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 排序选项
|
||||
@@ -55,6 +63,60 @@ const searchForm = ref({
|
||||
sortOrder: 'desc' as string | undefined,
|
||||
});
|
||||
|
||||
// 加载店铺列表(支持分页)
|
||||
async function fetchShops(page = 1, append = false) {
|
||||
if (shopLoading.value) return;
|
||||
shopLoading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<ShopDTO.Filters> = {
|
||||
page,
|
||||
pageSize: shopPageSize,
|
||||
filters: shopSearchKeyword.value ? { name: shopSearchKeyword.value } : {},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
if (append) {
|
||||
shopOptions.value = [...shopOptions.value, ...data.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}))];
|
||||
} else {
|
||||
shopOptions.value = data.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
}
|
||||
shopTotal.value = data.total;
|
||||
shopPage.value = page;
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
} finally {
|
||||
shopLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索店铺(防抖)
|
||||
function handleShopSearch(value: string) {
|
||||
if (shopSearchTimer) clearTimeout(shopSearchTimer);
|
||||
shopSearchTimer = setTimeout(() => {
|
||||
shopSearchKeyword.value = value;
|
||||
shopPage.value = 1;
|
||||
fetchShops(1, false);
|
||||
}, 300);
|
||||
}
|
||||
|
||||
// 滚动加载更多店铺
|
||||
function handleShopPopupScroll(e: Event) {
|
||||
const target = e.target as HTMLElement;
|
||||
const { scrollTop, scrollHeight, clientHeight } = target;
|
||||
// 滚动到底部附近时加载更多
|
||||
if (scrollHeight - scrollTop - clientHeight < 50) {
|
||||
const hasMore = shopPage.value * shopPageSize < shopTotal.value;
|
||||
if (hasMore && !shopLoading.value) {
|
||||
fetchShops(shopPage.value + 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
@@ -207,9 +269,15 @@ const formOptions = computed(() => ({
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择店铺',
|
||||
placeholder: '请选择店铺(支持搜索)',
|
||||
options: shopOptions.value,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
filterOption: false,
|
||||
onSearch: handleShopSearch,
|
||||
onPopupScroll: handleShopPopupScroll,
|
||||
loading: shopLoading.value,
|
||||
dropdownMenuColumnStyle: { maxHeight: '300px', overflow: 'auto' },
|
||||
},
|
||||
fieldName: 'shopId',
|
||||
label: '店铺',
|
||||
@@ -257,22 +325,9 @@ function refreshTable() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取店铺选项
|
||||
// 获取店铺选项(首次加载)
|
||||
async function fetchShopOptions() {
|
||||
try {
|
||||
const params: PageQueryDTO<any> = {
|
||||
page: 1,
|
||||
pageSize: 1000, // 获取所有店铺
|
||||
filters: {},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shopOptions.value = data.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
}
|
||||
await fetchShops(1, false);
|
||||
}
|
||||
|
||||
// 获取订单状态选项
|
||||
|
||||
Reference in New Issue
Block a user