fix: 推广费管理搜索表单选择器onChange未更新searchForm

- 店铺和推广费类型选择器onChange现在正确更新searchForm并刷新表格
This commit is contained in:
小蟑螂
2026-04-20 13:03:34 +08:00
parent a0f487b0c7
commit 06224ddd95
@@ -18,6 +18,8 @@ import {
deletePromotionFeeApi,
getPromotionFeePageApi,
} from '#/api/ecommerce/promotion-fee';
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
import { getAllPromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type/apis';
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
@@ -31,6 +33,52 @@ const loading = ref(false);
const formModalVisible = ref(false);
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
// 店铺选择器(懒加载)
const shopOptions = ref<{ label: string; value: number }[]>([]);
const shopLoading = ref(false);
const shopFetched = ref(false);
// 推广费类型选择器(懒加载)
const feeTypeOptions = ref<{ label: string; value: number }[]>([]);
const feeTypeLoading = ref(false);
const feeTypeFetched = ref(false);
// 获取店铺列表(首次触发时加载)
async function fetchShopOptions() {
if (shopFetched.value || shopLoading.value) return;
shopLoading.value = true;
try {
const data = await getShopPageApi({ page: 1, pageSize: 100, filters: {} });
shopOptions.value = (data.records || []).map((shop: any) => ({
label: shop.name,
value: shop.id,
}));
shopFetched.value = true;
} catch (error) {
console.error('获取店铺列表失败:', error);
} finally {
shopLoading.value = false;
}
}
// 获取推广费类型列表(首次触发时加载)
async function fetchFeeTypeOptions() {
if (feeTypeFetched.value || feeTypeLoading.value) return;
feeTypeLoading.value = true;
try {
const data = await getAllPromotionFeeTypeListApi();
feeTypeOptions.value = (data || []).map((type: any) => ({
label: type.typeName,
value: type.id,
}));
feeTypeFetched.value = true;
} catch (error) {
console.error('获取推广费类型列表失败:', error);
} finally {
feeTypeLoading.value = false;
}
}
// 搜索表单
const searchForm = ref({
shopId: undefined as number | undefined,
@@ -185,10 +233,16 @@ const formOptions = computed(() => ({
component: 'Select',
componentProps: {
placeholder: '请选择店铺',
// TODO: 这里需要从店铺API获取店铺列表
options: [],
options: shopOptions,
allowClear: true,
onChange: () => gridReloadRef.value?.(),
showSearch: true,
filterOption: false,
loading: shopLoading,
onFocus: fetchShopOptions,
onChange: (val: any) => {
searchForm.value.shopId = val;
gridReloadRef.value?.();
},
},
fieldName: 'shopId',
label: '店铺',
@@ -197,10 +251,16 @@ const formOptions = computed(() => ({
component: 'Select',
componentProps: {
placeholder: '请选择推广费类型',
// TODO: 这里需要从推广费类型API获取类型列表
options: [],
options: feeTypeOptions,
allowClear: true,
onChange: () => gridReloadRef.value?.(),
showSearch: true,
filterOption: false,
loading: feeTypeLoading,
onFocus: fetchFeeTypeOptions,
onChange: (val: any) => {
searchForm.value.feeTypeId = val;
gridReloadRef.value?.();
},
},
fieldName: 'feeTypeId',
label: '推广费类型',