mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:49:19 +08:00
feat(promotion-fee): 新增推广费类目级归属,区分商品级/类目级/全店比例池
This commit is contained in:
@@ -9,6 +9,8 @@ export namespace PromotionFeeDTO {
|
||||
shopId?: number;
|
||||
/** 推广费类型ID */
|
||||
feeTypeId?: number;
|
||||
/** 类目ID(可选) */
|
||||
categoryId?: number;
|
||||
/** 商品ID(可选) */
|
||||
productId?: number;
|
||||
/** 推广费发生日期开始 */
|
||||
@@ -23,6 +25,8 @@ export namespace PromotionFeeDTO {
|
||||
shopId: number;
|
||||
/** 推广费类型ID */
|
||||
feeTypeId: number;
|
||||
/** 类目ID(可选,类目级推广费) */
|
||||
categoryId?: number;
|
||||
/** 商品ID(可选,关联到具体商品) */
|
||||
productId?: number;
|
||||
/** 推广活动名称 */
|
||||
@@ -43,6 +47,8 @@ export namespace PromotionFeeDTO {
|
||||
shopId: number;
|
||||
/** 推广费类型ID */
|
||||
feeTypeId: number;
|
||||
/** 类目ID(可选,类目级推广费) */
|
||||
categoryId?: number;
|
||||
/** 商品ID(可选,关联到具体商品) */
|
||||
productId?: number;
|
||||
/** 推广活动名称 */
|
||||
|
||||
@@ -17,6 +17,10 @@ export namespace PromotionFeeVO {
|
||||
feeTypeId: number;
|
||||
/** 推广费类型名称 */
|
||||
feeTypeName?: string;
|
||||
/** 类目ID(可选) */
|
||||
categoryId?: number;
|
||||
/** 类目名称 */
|
||||
categoryName?: string;
|
||||
/** 商品ID(可选) */
|
||||
productId?: number;
|
||||
/** 商品名称 */
|
||||
|
||||
+78
-7
@@ -7,7 +7,7 @@ import type {
|
||||
import type { ProductVO } from '#/api/ecommerce/product/types';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { nextTick, onMounted, ref, watch } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import type { Dayjs } from 'dayjs';
|
||||
import dayjs from 'dayjs';
|
||||
@@ -21,12 +21,14 @@ import {
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
TreeSelect,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPromotionFeeApi,
|
||||
updatePromotionFeeApi,
|
||||
} from '#/api/ecommerce/promotion-fee';
|
||||
import { getCategoryTreeApi } from '#/api/ecommerce/category';
|
||||
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type';
|
||||
import { getProductPageApi } from '#/api/ecommerce/product';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
@@ -79,6 +81,7 @@ type PromotionFeeFormState = Omit<PromotionFeeDTO.Create, 'feeDate'> & {
|
||||
const formData = ref<PromotionFeeFormState>({
|
||||
shopId: undefined as any,
|
||||
feeTypeId: undefined as any,
|
||||
categoryId: undefined,
|
||||
productId: undefined,
|
||||
campaignName: '',
|
||||
feeAmount: undefined as any,
|
||||
@@ -103,10 +106,36 @@ const shopListLoading = ref(false);
|
||||
const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
|
||||
const feeTypeListLoading = ref(false);
|
||||
|
||||
// 类目树(与商品卡片 TreeSelect 一致:label=name, value=id)
|
||||
const categoryOptions = ref<any[]>([]);
|
||||
const categoryTreeLoading = ref(false);
|
||||
|
||||
// 商品列表
|
||||
const productList = ref<ProductVO.Info[]>([]);
|
||||
const productListLoading = ref(false);
|
||||
|
||||
const filteredProductList = computed(() => {
|
||||
const cid = formData.value.categoryId;
|
||||
if (cid == null) {
|
||||
return productList.value;
|
||||
}
|
||||
return productList.value.filter((p) => p.categoryId === cid);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => formData.value.categoryId,
|
||||
(cid) => {
|
||||
const pid = formData.value.productId;
|
||||
if (pid == null || cid == null) {
|
||||
return;
|
||||
}
|
||||
const p = productList.value.find((x) => x.id === pid);
|
||||
if (p && p.categoryId !== cid) {
|
||||
formData.value.productId = undefined;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
async (newVal) => {
|
||||
@@ -119,6 +148,7 @@ watch(
|
||||
formData.value = {
|
||||
shopId: props.promotionFeeData.shopId,
|
||||
feeTypeId: props.promotionFeeData.feeTypeId,
|
||||
categoryId: props.promotionFeeData.categoryId,
|
||||
productId: props.promotionFeeData.productId,
|
||||
campaignName: props.promotionFeeData.campaignName || '',
|
||||
feeAmount: props.promotionFeeData.feeAmount,
|
||||
@@ -134,6 +164,18 @@ watch(
|
||||
modalApi.open();
|
||||
await nextTick();
|
||||
formRef.value?.clearValidate?.();
|
||||
|
||||
if (props.promotionFeeData?.productId && productList.value.length > 0) {
|
||||
const p = productList.value.find(
|
||||
(x) => x.id === props.promotionFeeData!.productId,
|
||||
);
|
||||
if (
|
||||
p?.categoryId != null &&
|
||||
(formData.value.categoryId == null || formData.value.categoryId === undefined)
|
||||
) {
|
||||
formData.value.categoryId = p.categoryId;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -165,6 +207,18 @@ const loadFeeTypeList = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadCategoryTree = async () => {
|
||||
categoryTreeLoading.value = true;
|
||||
try {
|
||||
categoryOptions.value = (await getCategoryTreeApi()) ?? [];
|
||||
} catch (error) {
|
||||
console.error('加载类目树失败:', error);
|
||||
categoryOptions.value = [];
|
||||
} finally {
|
||||
categoryTreeLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const loadProductList = async () => {
|
||||
productListLoading.value = true;
|
||||
try {
|
||||
@@ -185,6 +239,7 @@ const resetFormData = () => {
|
||||
formData.value = {
|
||||
shopId: undefined as any,
|
||||
feeTypeId: undefined as any,
|
||||
categoryId: undefined,
|
||||
productId: undefined,
|
||||
campaignName: '',
|
||||
feeAmount: undefined as any,
|
||||
@@ -196,6 +251,11 @@ const resetFormData = () => {
|
||||
/** 发生日期仅表示日历日,格式化为本地 YYYY-MM-DD,避免 JSON 序列化为 UTC ISO 后日期错位 */
|
||||
const feeDateToApiString = (v: Dayjs) => dayjs(v).format('YYYY-MM-DD');
|
||||
|
||||
function productSelectFilterOption(input: string, option?: any) {
|
||||
const o = filteredProductList.value.find((x) => x.id === option?.value);
|
||||
return (o?.name ?? '').toLowerCase().includes(input.toLowerCase());
|
||||
}
|
||||
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
@@ -234,6 +294,7 @@ const handleCancel = () => {
|
||||
onMounted(() => {
|
||||
loadShopList();
|
||||
loadFeeTypeList();
|
||||
loadCategoryTree();
|
||||
loadProductList();
|
||||
});
|
||||
</script>
|
||||
@@ -279,20 +340,30 @@ onMounted(() => {
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="类目(可选)" name="categoryId">
|
||||
<TreeSelect
|
||||
v-model:value="formData.categoryId"
|
||||
class="w-full"
|
||||
placeholder="请选择类目(可选,用于类目级推广费或筛选商品)"
|
||||
:tree-data="categoryOptions"
|
||||
:field-names="{ label: 'name', value: 'id', children: 'children' }"
|
||||
:loading="categoryTreeLoading"
|
||||
allow-clear
|
||||
tree-default-expand-all
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="商品(可选)" name="productId">
|
||||
<Select
|
||||
v-model:value="formData.productId"
|
||||
placeholder="请选择商品(可选,不选则为店铺级推广费)"
|
||||
placeholder="请选择商品(可选;已选类目时仅显示该类目下商品)"
|
||||
:loading="productListLoading"
|
||||
allow-clear
|
||||
show-search
|
||||
:filter-option="(input: string, option: any) =>
|
||||
option?.children?.props?.children?.props?.children?.props?.children?.props?.children?.props?.children
|
||||
?.toLowerCase?.().includes?.(input.toLowerCase()) ?? false
|
||||
"
|
||||
:filter-option="productSelectFilterOption"
|
||||
>
|
||||
<Select.Option
|
||||
v-for="product in productList"
|
||||
v-for="product in filteredProductList"
|
||||
:key="product.id"
|
||||
:value="product.id"
|
||||
>
|
||||
|
||||
@@ -97,6 +97,13 @@ const gridOptions: VxeGridProps<any> = {
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'categoryName',
|
||||
title: '类目',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
slots: { default: 'category' },
|
||||
},
|
||||
{
|
||||
field: 'productName',
|
||||
title: '商品',
|
||||
@@ -328,6 +335,10 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<template #category="{ row }: { row: any }">
|
||||
<span>{{ row.categoryName || '—' }}</span>
|
||||
</template>
|
||||
|
||||
<template #feeAmount="{ row }: { row: any }">
|
||||
<span class="font-medium text-red-600">
|
||||
{{ formatAmount(row.feeAmount) }}
|
||||
|
||||
Reference in New Issue
Block a user