refactor: 重构内部推广费模块

This commit is contained in:
2026-08-17 10:20:34 +08:00
parent b4455a4788
commit d91b7cd168
60 changed files with 901 additions and 2586 deletions
@@ -100,7 +100,7 @@ const summaryTablesPanel = computed(
const router = useRouter();
const ImportOrderIcon = createIconifyIcon('lucide:upload');
const PromotionFeeIcon = createIconifyIcon('lucide:dollar-sign');
const AdFeeIcon = createIconifyIcon('lucide:dollar-sign');
const ToolbarToggleIcon = createIconifyIcon('lucide:sliders-horizontal');
const ReceiptIcon = createIconifyIcon('lucide:receipt');
const CalendarIcon = createIconifyIcon('lucide:calendar');
@@ -110,8 +110,8 @@ function goToImportOrder() {
void router.push('/import/order');
}
function goToImportPromotionFee() {
void router.push('/import/promotion-fee');
function goToImportAdFee() {
void router.push('/import/ad-fee');
}
/** 快捷区间 + 自定义 RangePicker */
@@ -171,15 +171,15 @@ const importMenuItems: MenuProps['items'] = [
icon: () => h(ImportOrderIcon, { class: 'size-4' }),
},
{
key: 'promotion',
label: '导入推广费',
icon: () => h(PromotionFeeIcon, { class: 'size-4' }),
key: 'ad-fee',
label: '导入广告费',
icon: () => h(AdFeeIcon, { class: 'size-4' }),
},
];
const onImportMenuClick: MenuProps['onClick'] = ({ key }) => {
if (key === 'order') goToImportOrder();
else if (key === 'promotion') goToImportPromotionFee();
else if (key === 'ad-fee') goToImportAdFee();
};
const switchTimeRange = (type: TimeRangeKey) => {
@@ -1,13 +1,12 @@
<script setup lang="ts">
import type { PromotionFeeTypeVO } from '#/api/ec/promotion-fee/type';
import type {
PromotionFeeDTO,
PromotionFeeVO,
} from '#/api/ec/promotion-fee/types';
AdFeeDTO,
AdFeeVO,
} from '#/api/ec/ad-fee/types';
import type { ProductVO } from '#/api/ec/product/types';
import type { ShopVO } from '#/api/ec/shop/types';
import { computed, nextTick, onMounted, ref, watch } from 'vue';
import { nextTick, onMounted, ref, watch } from 'vue';
import type { Dayjs } from 'dayjs';
import dayjs from 'dayjs';
@@ -21,23 +20,20 @@ import {
InputNumber,
message,
Select,
TreeSelect,
} from 'ant-design-vue';
import {
createPromotionFeeApi,
updatePromotionFeeApi,
} from '#/api/ec/promotion-fee';
import { getCategoryTreeApi } from '#/api/ec/product/category';
import { getActivePromotionFeeTypeListApi } from '#/api/ec/promotion-fee/type';
createAdFeeApi,
updateAdFeeApi,
} from '#/api/ec/ad-fee';
import { getProductPageApi } from '#/api/ec/product';
import { getShopPageApi } from '#/api/ec/shop';
defineOptions({ name: 'PromotionFeeFormModal' });
defineOptions({ name: 'AdFeeFormModal' });
interface Props {
open: boolean;
promotionFeeData?: null | PromotionFeeVO.Info;
adFeeData?: null | AdFeeVO.Info;
/** 新增时预填店铺(编辑时忽略) */
presetShopId?: number | null;
}
@@ -76,14 +72,12 @@ const formRef = ref();
const isEdit = ref(false);
/** 表单内用 Dayjs,提交时再格式化为 YYYY-MM-DD */
type PromotionFeeFormState = Omit<PromotionFeeDTO.Create, 'feeDate'> & {
type AdFeeFormState = Omit<AdFeeDTO.Create, 'feeDate'> & {
feeDate?: Dayjs;
};
const formData = ref<PromotionFeeFormState>({
const formData = ref<AdFeeFormState>({
shopId: undefined as any,
feeTypeId: undefined as any,
categoryId: undefined,
productId: undefined,
campaignName: '',
feeAmount: undefined as any,
@@ -93,10 +87,7 @@ const formData = ref<PromotionFeeFormState>({
const rules = {
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
feeTypeId: [
{ required: true, message: '请选择推广费类型', trigger: 'change' },
],
feeAmount: [{ required: true, message: '请输入推广费金额', trigger: 'blur' }],
feeAmount: [{ required: true, message: '请输入广告费金额', trigger: 'blur' }],
feeDate: [{ required: true, message: '请选择发生日期', trigger: 'change' }],
} as any;
@@ -104,40 +95,10 @@ const rules = {
const shopList = ref<ShopVO.Info[]>([]);
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) => {
@@ -145,19 +106,17 @@ watch(
modalApi.close();
return;
}
isEdit.value = !!props.promotionFeeData;
if (props.promotionFeeData) {
isEdit.value = !!props.adFeeData;
if (props.adFeeData) {
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,
feeDate: props.promotionFeeData.feeDate
? dayjs(props.promotionFeeData.feeDate)
shopId: props.adFeeData.shopId,
productId: props.adFeeData.productId,
campaignName: props.adFeeData.campaignName || '',
feeAmount: props.adFeeData.feeAmount,
feeDate: props.adFeeData.feeDate
? dayjs(props.adFeeData.feeDate)
: undefined,
remark: props.promotionFeeData.remark || '',
remark: props.adFeeData.remark || '',
};
} else {
resetFormData();
@@ -169,18 +128,6 @@ 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;
}
}
},
);
@@ -200,30 +147,6 @@ const loadShopList = async () => {
}
};
const loadFeeTypeList = async () => {
feeTypeListLoading.value = true;
try {
const response = await getActivePromotionFeeTypeListApi();
feeTypeList.value = response;
} catch (error) {
console.error('加载推广费类型列表失败:', error);
} finally {
feeTypeListLoading.value = false;
}
};
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 {
@@ -243,8 +166,6 @@ const loadProductList = async () => {
const resetFormData = () => {
formData.value = {
shopId: undefined as any,
feeTypeId: undefined as any,
categoryId: undefined,
productId: undefined,
campaignName: '',
feeAmount: undefined as any,
@@ -257,7 +178,7 @@ const resetFormData = () => {
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);
const o = productList.value.find((x) => x.id === option?.value);
return (o?.name ?? '').toLowerCase().includes(input.toLowerCase());
}
@@ -267,16 +188,16 @@ const handleOk = async () => {
const feeDate = feeDateToApiString(formData.value.feeDate!);
if (isEdit.value && props.promotionFeeData) {
const updateData: PromotionFeeDTO.Update = {
id: props.promotionFeeData.id,
if (isEdit.value && props.adFeeData) {
const updateData: AdFeeDTO.Update = {
id: props.adFeeData.id,
...formData.value,
feeDate,
};
await updatePromotionFeeApi(updateData);
await updateAdFeeApi(updateData);
message.success('更新成功');
} else {
await createPromotionFeeApi({
await createAdFeeApi({
...formData.value,
feeDate,
});
@@ -298,14 +219,12 @@ const handleCancel = () => {
onMounted(() => {
loadShopList();
loadFeeTypeList();
loadCategoryTree();
loadProductList();
});
</script>
<template>
<Modal :title="isEdit ? '编辑推广费记录' : '新增推广费记录'">
<Modal :title="isEdit ? '编辑广告费记录' : '新增广告费记录'">
<Form
ref="formRef"
:model="formData"
@@ -329,46 +248,17 @@ onMounted(() => {
</Select>
</Form.Item>
<Form.Item label="推广费类型" name="feeTypeId">
<Select
v-model:value="formData.feeTypeId"
placeholder="请选择推广费类型"
:loading="feeTypeListLoading"
>
<Select.Option
v-for="feeType in feeTypeList"
:key="feeType.id"
:value="feeType.id"
>
{{ feeType.typeName }}
</Select.Option>
</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="productSelectFilterOption"
>
<Select.Option
v-for="product in filteredProductList"
v-for="product in productList"
:key="product.id"
:value="product.id"
>
@@ -384,10 +274,10 @@ onMounted(() => {
/>
</Form.Item>
<Form.Item label="推广费金额" name="feeAmount">
<Form.Item label="广告费金额" name="feeAmount">
<InputNumber
v-model:value="formData.feeAmount"
placeholder="请输入推广费金额"
placeholder="请输入广告费金额"
:min="0"
:precision="2"
style="width: 100%"
@@ -397,7 +287,7 @@ onMounted(() => {
<Form.Item label="发生日期" name="feeDate">
<DatePicker
v-model:value="formData.feeDate"
placeholder="请选择推广费发生日期"
placeholder="请选择广告费发生日期"
style="width: 100%"
/>
</Form.Item>
@@ -1,12 +1,12 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type {
PromotionFeeDTO,
PromotionFeeVO,
} from '#/api/ec/promotion-fee/types';
AdFeeDTO,
AdFeeVO,
} from '#/api/ec/ad-fee/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, ref, watch } from 'vue';
import { computed, ref, watch } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
@@ -18,21 +18,19 @@ import {
Flex,
message,
Popconfirm,
Select,
Space,
} from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePromotionFeeApi,
getPromotionFeePageApi,
} from '#/api/ec/promotion-fee';
import { getAllPromotionFeeTypeListApi } from '#/api/ec/promotion-fee/type/apis';
deleteAdFeeApi,
getAdFeePageApi,
} from '#/api/ec/ad-fee';
import ShopSidebarList from '#/views/ec/components/ShopSidebarList.vue';
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
import AdFeeFormModal from './components/AdFeeFormModal.vue';
defineOptions({ name: 'PromotionFeeManagement' });
defineOptions({ name: 'AdFeeManagement' });
const PlusIcon = createIconifyIcon('lucide:plus');
@@ -43,34 +41,10 @@ const selectedShopId = ref<number | undefined>(undefined);
const selectedShopName = ref<string | undefined>(undefined);
const formModalVisible = ref(false);
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
const currentAdFeeData = ref<null | AdFeeVO.Info>(null);
const presetShopIdForModal = ref<number | null>(null);
const feeTypeOptions = ref<{ label: string; value: number }[]>([]);
const feeTypeLoading = ref(false);
const feeTypeFetched = ref(false);
async function fetchFeeTypeOptions() {
if (feeTypeFetched.value || feeTypeLoading.value) return;
feeTypeLoading.value = true;
try {
const data = await getAllPromotionFeeTypeListApi();
feeTypeOptions.value = (data || []).map(
(type: { id: number; typeName: string }) => ({
label: type.typeName,
value: type.id,
}),
);
feeTypeFetched.value = true;
} catch {
message.error('获取推广费类型失败');
} finally {
feeTypeLoading.value = false;
}
}
const searchForm = ref({
feeTypeId: undefined as number | undefined,
feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined,
});
@@ -93,12 +67,12 @@ function onShopSelect(shop: { id: number; name: string } | null) {
}
function handleAddForShop(shopId: number) {
currentPromotionFeeData.value = null;
currentAdFeeData.value = null;
presetShopIdForModal.value = shopId;
formModalVisible.value = true;
}
const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
const gridOptions: VxeGridProps<AdFeeVO.Info> = {
columns: [
{
type: 'seq' as const,
@@ -111,13 +85,6 @@ const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
minWidth: 120,
showOverflow: 'tooltip' as const,
},
{
field: 'categoryName',
title: '类目',
minWidth: 120,
showOverflow: 'tooltip' as const,
slots: { default: 'category' },
},
{
field: 'productName',
title: '商品',
@@ -125,12 +92,6 @@ const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
showOverflow: 'tooltip' as const,
slots: { default: 'product' },
},
{
field: 'feeTypeName',
title: '推广费类型',
minWidth: 110,
showOverflow: 'tooltip' as const,
},
{
field: 'campaignName',
title: '推广活动',
@@ -138,7 +99,7 @@ const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
showOverflow: 'tooltip' as const,
},
{
title: '推广费金额',
title: '广告费金额',
minWidth: 110,
slots: { default: 'feeAmount' },
},
@@ -194,20 +155,19 @@ const gridOptions: VxeGridProps<PromotionFeeVO.Info> = {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
const params: PageQueryDTO<AdFeeDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: selectedShopId.value,
feeTypeId: searchForm.value.feeTypeId || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined,
},
};
const data = await getPromotionFeePageApi(params);
const data = await getAdFeePageApi(params);
return { items: data.records, total: data.total };
} catch {
message.error('获取推广费记录列表失败');
message.error('获取广告费记录列表失败');
return { items: [], total: 0 };
} finally {
loading.value = false;
@@ -231,29 +191,25 @@ watch(selectedShopId, () => {
gridApi.reload();
});
onMounted(() => {
void fetchFeeTypeOptions();
});
function resetModalPreset() {
presetShopIdForModal.value = null;
}
const handleAdd = () => {
currentPromotionFeeData.value = null;
currentAdFeeData.value = null;
resetModalPreset();
formModalVisible.value = true;
};
const handleEdit = (record: PromotionFeeVO.Info) => {
const handleEdit = (record: AdFeeVO.Info) => {
resetModalPreset();
currentPromotionFeeData.value = record;
currentAdFeeData.value = record;
formModalVisible.value = true;
};
async function handleDelete(id: number) {
try {
await deletePromotionFeeApi(id);
await deleteAdFeeApi(id);
message.success('删除成功');
refreshTable();
} catch {
@@ -275,10 +231,10 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
</script>
<template>
<Page title="推广费管理" :auto-content-height="true">
<Page title="广告费管理" :auto-content-height="true">
<template #description>
<div class="text-foreground/80 mt-2">
左侧选择店铺筛选右侧推广记录;未选店铺时展示全部记录。可在店铺行快捷新增该店铺推广费。
左侧选择店铺筛选右侧推广记录;未选店铺时展示全部记录。可在店铺行快捷新增该店铺广告费。
</div>
</template>
@@ -286,7 +242,7 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="mr-2 h-4 w-4" />
新增推广费
新增广告费
</Button>
</Space>
</template>
@@ -313,20 +269,6 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
</template>
<template #extra>
<Space wrap size="small" class="max-w-[min(100%,42rem)]">
<Select
v-model:value="searchForm.feeTypeId"
allow-clear
show-search
:options="feeTypeOptions"
:loading="feeTypeLoading"
placeholder="类型"
class="min-w-[120px]"
option-filter-prop="label"
@dropdown-visible-change="
(open: boolean) => open && fetchFeeTypeOptions()
"
@change="() => refreshTable()"
/>
<DatePicker
v-model:value="searchForm.feeDateStart"
value-format="YYYY-MM-DD"
@@ -359,14 +301,10 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
<Grid :loading="loading" class="h-full min-h-0">
<template #toolbar-tools>
<span class="text-xs text-muted-foreground">
使用上方类型与日期筛选;表格在区域内滚动
使用上方日期筛选;表格在区域内滚动
</span>
</template>
<template #category="{ row }">
<span>{{ row.categoryName || '—' }}</span>
</template>
<template #feeAmount="{ row }">
<span class="font-semibold text-red-600">
{{ formatAmount(row.feeAmount) }}
@@ -389,7 +327,7 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
<Space>
<Button size="small" @click="handleEdit(row)">编辑</Button>
<Popconfirm
title="确定要删除这条推广费记录吗?"
title="确定要删除这条广告费记录吗?"
@confirm="handleDelete(row.id)"
>
<Button size="small" danger>删除</Button>
@@ -401,9 +339,9 @@ const formatAmount = (amount: number) => `¥${amount.toFixed(2)}`;
</Card>
</Flex>
<PromotionFeeFormModal
<AdFeeFormModal
v-model:open="formModalVisible"
:promotion-fee-data="currentPromotionFeeData"
:ad-fee-data="currentAdFeeData"
:preset-shop-id="presetShopIdForModal"
@success="handleFormSuccess"
@cancel="handleFormCancel"
@@ -5,7 +5,7 @@ import { createIconifyIcon } from '@vben/icons';
import { message, Spin } from 'ant-design-vue';
defineOptions({ name: 'PromotionFeeFileUploadArea' });
defineOptions({ name: 'AdFeeFileUploadArea' });
const props = withDefaults(
defineProps<{
@@ -1,5 +1,5 @@
<script setup lang="ts">
import type { PromotionFeeFieldVO } from '#/api/ec/promotion-fee/types';
import type { AdFeeFieldVO } from '#/api/ec/ad-fee/types';
import type { ImportMappingVO } from '#/api/ec/import/mapping';
import type { ImportTaskDTO } from '#/api/ec/import/task';
import type { ShopVO } from '#/api/ec/shop/types';
@@ -16,7 +16,7 @@ import {
ImportMappingType,
updateImportMappingApi,
} from '#/api/ec/import/mapping';
import { getPromotionFeeFieldsApi } from '#/api/ec/promotion-fee/apis';
import { getAdFeeFieldsApi } from '#/api/ec/ad-fee/apis';
import { getShopPageApi } from '#/api/ec/shop';
import { createImportTaskApi } from '#/api/ec/import/task';
import { useImportTaskStore } from '#/store';
@@ -30,7 +30,7 @@ interface FieldMappingItem {
required: boolean;
}
defineOptions({ name: 'PromotionFeeImportTaskWizard' });
defineOptions({ name: 'AdFeeImportTaskWizard' });
const emit = defineEmits<{
success: [];
@@ -54,9 +54,9 @@ const shopSearchValue = ref('');
const feeDate = ref<any>(undefined);
const fieldDefs = ref<PromotionFeeFieldVO.Info[]>([]);
const fieldDefs = ref<AdFeeFieldVO.Info[]>([]);
const fieldMappings = ref<
Record<string, { fieldDef: PromotionFeeFieldVO.Info; mappedHeader?: string }>
Record<string, { fieldDef: AdFeeFieldVO.Info; mappedHeader?: string }>
>({});
const mappingTemplates = ref<ImportMappingVO.ImportMappingInfoVO[]>([]);
@@ -178,8 +178,8 @@ const handleShopScroll = (e: any) => {
const fetchFieldDefs = async () => {
try {
fieldDefsLoading.value = true;
const result = await getPromotionFeeFieldsApi();
fieldDefs.value = (result || []) as unknown as PromotionFeeFieldVO.Info[];
const result = await getAdFeeFieldsApi();
fieldDefs.value = (result || []) as unknown as AdFeeFieldVO.Info[];
initFieldMappings();
} catch (error) {
console.error('获取字段定义失败:', error);
@@ -392,11 +392,9 @@ const handlePrev = () => {
};
const buildPatchedCsv = (): File => {
const headers = [...csvHeaders.value, 'feeTypeId', 'categoryId', 'productId'];
const headers = [...csvHeaders.value, 'productId'];
const rows = previewData.value.map((row: any) =>
headers.map((h: string) => {
if (h === 'feeTypeId') return row._feeTypeId ?? '';
if (h === 'categoryId') return row._categoryId ?? '';
if (h === 'productId') return row._productId ?? '';
return row[h] ?? '';
}),
@@ -411,7 +409,7 @@ const buildPatchedCsv = (): File => {
};
const buildPatchedFileName = (_original: string): string => {
return 'promotion_fee_import_patched.csv';
return 'ad_fee_import_patched.csv';
};
const handleCreateTask = async () => {
@@ -424,7 +422,7 @@ const handleCreateTask = async () => {
return;
}
if (!feeDate.value) {
message.warning('请选择推广费发生日期');
message.warning('请选择广告费发生日期');
return;
}
@@ -433,7 +431,7 @@ const handleCreateTask = async () => {
message.loading('正在上传文件...', 0);
const patchedFile = buildPatchedCsv();
const fileInfo = await uploadFileToOss(patchedFile, {
category: 'promotion-fee-import',
category: 'ad-fee-import',
errorMessage: '文件上传失败,请重试',
});
message.destroy();
@@ -572,7 +570,7 @@ const shopOptions = computed(() => {
>
<div class="mb-3 flex shrink-0 flex-wrap items-center justify-between gap-2 gap-y-3">
<div class="text-sm text-gray-600 dark:text-gray-300">
请为每个推广费字段选择对应的CSV列,必填字段必须绑定
请为每个广告费字段选择对应的CSV列,必填字段必须绑定
</div>
<div class="flex items-center space-x-2">
<Select
@@ -651,7 +649,7 @@ const shopOptions = computed(() => {
系统
</span>
<span class="text-xs font-medium text-slate-600 dark:text-slate-300">
推广费字段
广告费字段
</span>
</div>
<div class="flex flex-wrap items-center gap-x-2 gap-y-1">
@@ -753,7 +751,7 @@ const shopOptions = computed(() => {
<Form.Item label="发生日期" required>
<DatePicker
v-model:value="feeDate"
placeholder="选择推广费发生日期"
placeholder="选择广告费发生日期"
style="width: 100%"
/>
</Form.Item>
@@ -783,7 +781,7 @@ const shopOptions = computed(() => {
<span class="font-medium">{{ Object.values(fieldMappings).filter((m) => m.mappedHeader).length }}/{{ fieldDefs.length }}</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-gray-600 dark:text-gray-300">推广费类型/类目/商品</span>
<span class="text-gray-600 dark:text-gray-300">商品</span>
<span class="font-medium text-green-600">表格中逐行设置</span>
</div>
</div>
@@ -11,14 +11,10 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
import ImportTaskWizard from './components/ImportTaskWizard.vue';
import FileUploadArea from './components/FileUploadArea.vue';
import { parseFileToRawData } from '#/views/ec/import/order/utils/fileParser';
import { getActivePromotionFeeTypeListApi } from '#/api/ec/promotion-fee/type/apis';
import { getCategoryTreeApi } from '#/api/ec/product/category/apis';
import { getProductPageApi } from '#/api/ec/product/apis';
import type { PromotionFeeTypeVO } from '#/api/ec/promotion-fee/type/types';
import type { CategoryVO } from '#/api/ec/product/category/types';
import type { ProductVO } from '#/api/ec/product/types';
defineOptions({ name: 'PromotionFeeImport' });
defineOptions({ name: 'AdFeeImport' });
const csvData = ref<any[]>([]);
const csvHeaders = ref<string[]>([]);
@@ -29,27 +25,21 @@ const tableHeight = ref<number>(600);
const importTaskWizardRef = ref<InstanceType<typeof ImportTaskWizard>>();
const feeTypeOptions = ref<PromotionFeeTypeVO.Info[]>([]);
const categoryTree = ref<CategoryVO.Info[]>([]);
const productList = ref<ProductVO.Info[]>([]);
const loadReferenceData = async () => {
try {
const [feeTypesRes, categoryRes, productRes] = await Promise.all([
getActivePromotionFeeTypeListApi(),
getCategoryTreeApi(),
getProductPageApi({ page: 1, pageSize: 9999, filters: {} }),
]);
feeTypeOptions.value = feeTypesRes as unknown as PromotionFeeTypeVO.Info[];
categoryTree.value = categoryRes as unknown as CategoryVO.Info[];
const productRes = await getProductPageApi({
page: 1,
pageSize: 9999,
filters: {},
});
productList.value = ((productRes as any).records || []) as ProductVO.Info[];
} catch (e) {
console.error('加载参考数据失败', e);
}
};
const gridColumns = computed(() => {
if (csvHeaders.value.length === 0) return [];
@@ -66,64 +56,26 @@ const gridColumns = computed(() => {
});
});
columns.push(
{
field: '_feeTypeId',
title: '推广费类型',
width: 160,
fixed: 'right' as const,
cellRender: {
name: 'CellSelect',
props: {
options: feeTypeOptions.value.map((t) => ({
label: t.typeName,
value: t.id,
})),
allowClear: true,
placeholder: '请选择',
},
columns.push({
field: '_productId',
title: '商品',
width: 180,
fixed: 'right' as const,
cellRender: {
name: 'CellSelect',
props: {
options: productList.value.map((p) => ({
label: `${p.name}${p.productCode ? ` (${p.productCode})` : ''}`,
value: p.id,
})),
allowClear: true,
placeholder: '请选择商品',
showSearch: true,
filterOption: (input: string, option: any) =>
option.label.toLowerCase().includes(input.toLowerCase()),
},
},
{
field: '_categoryId',
title: '类目',
width: 160,
fixed: 'right' as const,
cellRender: {
name: 'CellTreeSelect',
props: {
treeData: categoryTree.value,
fieldNames: { label: 'name', value: 'id', children: 'children' },
allowClear: true,
placeholder: '请选择',
treeDefaultExpandAll: false,
},
},
},
{
field: '_productId',
title: '商品',
width: 180,
fixed: 'right' as const,
cellRender: {
name: 'CellSelect',
props: {
options: productList.value.map((p) => ({
label: `${p.name}${p.productCode ? ` (${p.productCode})` : ''}`,
value: p.id,
categoryId: (p as any).categoryId,
})),
filterByRowField: '_categoryId',
filterOptionKey: 'categoryId',
allowClear: true,
placeholder: '请选择商品',
showSearch: true,
filterOption: (input: string, option: any) =>
option.label.toLowerCase().includes(input.toLowerCase()),
},
},
},
);
});
return columns;
});
@@ -311,12 +263,12 @@ onUnmounted(() => {
<h1
class="mb-2 text-3xl font-black tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)] sm:text-4xl"
>
推广费导入中心
广告费导入中心
</h1>
<p
class="text-sm font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] sm:text-base"
>
请上传 CSV / Excel 格式的推广费原始数据
请上传 CSV / Excel 格式的广告费原始数据
</p>
</div>
<div
@@ -1,221 +0,0 @@
<script lang="ts" setup>
import type {
PromotionFeeTypeDTO,
PromotionFeeTypeVO,
} from '#/api/ec/promotion-fee/type';
import { ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import {
Form,
Input,
InputNumber,
message,
Select,
Switch,
} from 'ant-design-vue';
import {
createPromotionFeeTypeApi,
updatePromotionFeeTypeApi,
} from '#/api/ec/promotion-fee/type';
const emit = defineEmits<{
cancel: [];
success: [];
}>();
// 创建 vben modal
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[600px]',
onCancel() {
close();
},
onConfirm() {
handleSubmit();
},
});
// 响应式数据
const loading = ref(false);
const isEdit = ref(false);
const currentRecord = ref<null | PromotionFeeTypeVO.Info>(null);
// 表单数据
const formData = ref<Partial<PromotionFeeTypeDTO.Create>>({
typeName: '',
description: '',
calculationMethod: 1,
sortOrder: 0,
isActive: 1,
});
// 计算方式选项
const calculationMethodOptions = [
{ label: '固定金额', value: 1 },
{ label: '按比例', value: 2 },
{ label: '按点击', value: 3 },
{ label: '按展示', value: 4 },
];
// 表单验证规则
const rules = {
typeCode: [{ required: true, message: '请输入类型编码', trigger: 'blur' }],
typeName: [{ required: true, message: '请输入类型名称', trigger: 'blur' }],
sortOrder: [{ required: true, message: '请输入排序', trigger: 'blur' }],
};
// 表单引用
const formRef = ref();
// 打开模态框
function open(edit: boolean, record?: PromotionFeeTypeVO.Info) {
isEdit.value = edit;
currentRecord.value = record || null;
modalApi.open();
// 根据模式填充表单数据
formData.value =
edit && record
? {
typeName: record.typeName,
description: record.description || '',
calculationMethod: record.calculationMethod || 1,
sortOrder: record.sortOrder || 0,
isActive: record.isActive || 1,
}
: {
typeName: '',
description: '',
calculationMethod: 1,
sortOrder: 0,
isActive: 1,
};
}
// 关闭模态框
function close() {
modalApi.close();
formRef.value?.resetFields();
emit('cancel');
}
// 提交表单
async function handleSubmit() {
try {
await formRef.value?.validate();
loading.value = true;
if (isEdit.value && currentRecord.value) {
// 更新推广费类型
const updateData: PromotionFeeTypeDTO.Update = {
id: currentRecord.value.id,
typeName: formData.value.typeName!,
description: formData.value.description,
calculationMethod: formData.value.calculationMethod,
sortOrder: formData.value.sortOrder,
isActive: formData.value.isActive,
};
await updatePromotionFeeTypeApi(updateData);
message.success('更新推广费类型成功');
} else {
// 创建推广费类型
const createData: PromotionFeeTypeDTO.Create = {
typeName: formData.value.typeName!,
description: formData.value.description,
calculationMethod: formData.value.calculationMethod,
sortOrder: formData.value.sortOrder,
isActive: formData.value.isActive,
};
await createPromotionFeeTypeApi(createData);
message.success('创建推广费类型成功');
}
emit('success');
close();
} catch (error) {
console.error('提交推广费类型失败:', (error as any).message);
} finally {
loading.value = false;
}
}
// 监听 modal 关闭状态
watch(
() => modalApi.useStore()?.value?.isOpen,
(newVal) => {
if (!newVal) {
formRef.value?.resetFields();
}
},
);
// 暴露方法
defineExpose({
open,
close,
});
</script>
<template>
<Modal
:title="isEdit ? '编辑推广费类型' : '添加推广费类型'"
:confirm-loading="loading"
>
<Form
ref="formRef"
:model="formData"
:rules="rules as any"
layout="vertical"
>
<div class="grid grid-cols-2 gap-4">
<Form.Item label="类型名称" name="typeName">
<Input
v-model:value="formData.typeName"
placeholder="请输入类型名称"
/>
</Form.Item>
</div>
<Form.Item label="类型描述" name="description">
<Input.TextArea
v-model:value="formData.description"
placeholder="请输入类型描述(可选)"
:rows="3"
/>
</Form.Item>
<div class="grid grid-cols-3 gap-4">
<Form.Item label="计算方式" name="calculationMethod">
<Select
v-model:value="formData.calculationMethod"
placeholder="请选择计算方式"
:options="calculationMethodOptions"
/>
</Form.Item>
<Form.Item label="排序" name="sortOrder">
<InputNumber
v-model:value="formData.sortOrder"
placeholder="请输入排序"
style="width: 100%"
:min="0"
/>
</Form.Item>
<Form.Item label="启用状态" name="isActive">
<Switch
v-model:checked="formData.isActive"
:checked-value="1"
:un-checked-value="0"
checked-children="启用"
un-checked-children="禁用"
/>
</Form.Item>
</div>
</Form>
</Modal>
</template>
@@ -1,265 +0,0 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PromotionFeeTypeVO } from '#/api/ec/promotion-fee/type';
import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePromotionFeeTypeApi,
getAllPromotionFeeTypeListApi,
} from '#/api/ec/promotion-fee/type';
import PromotionFeeTypeFormModal from './components/PromotionFeeTypeFormModal.vue';
defineOptions({ name: 'PromotionFeeTypeConfig' });
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
// 响应式数据
const loading = ref(false);
const promotionFeeTypeFormModalRef = ref();
// 计算方式选项
const calculationMethodOptions = [
{ label: '固定金额', value: 1 },
{ label: '按比例', value: 2 },
{ label: '按点击', value: 3 },
{ label: '按展示', value: 4 },
];
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
width: 80,
title: '序号',
},
{
field: 'typeName',
title: '类型名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'description',
title: '类型描述',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
title: '计算方式',
minWidth: 'auto',
slots: { default: 'calculationMethod' },
},
{
field: 'sortOrder',
title: '排序',
minWidth: 'auto',
},
{
title: '状态',
minWidth: 'auto',
slots: { default: 'status' },
},
{
field: 'createTime',
title: '创建时间',
minWidth: 'auto',
},
{
field: 'updateTime',
title: '更新时间',
minWidth: 'auto',
},
{
title: '操作',
minWidth: 'auto',
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
rowConfig: { isHover: true },
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: false,
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async () => {
try {
loading.value = true;
const data = await getAllPromotionFeeTypeListApi();
return {
items: data,
total: data.length,
};
} catch (error) {
console.error('获取推广费类型列表失败:', error);
message.error('获取推广费类型列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 搜索表单配置
const gridReloadRef = ref<(() => void) | null>(null);
const formOptions = computed(() => ({
schema: [
{
component: 'Input',
componentProps: {
placeholder: '请输入类型名称(回车搜索)',
onPressEnter: () => gridReloadRef.value?.(),
},
fieldName: 'typeName',
label: '类型名称',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择状态',
options: [
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 },
],
allowClear: true,
onChange: () => gridReloadRef.value?.(),
},
fieldName: 'isActive',
label: '状态',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '推广费用类型配置',
});
gridReloadRef.value = () => gridApi.reload();
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 处理添加推广费类型
function handleAdd() {
promotionFeeTypeFormModalRef.value?.open(false);
}
// 处理编辑推广费类型
function handleEdit(record: PromotionFeeTypeVO.Info) {
promotionFeeTypeFormModalRef.value?.open(true, record);
}
// 处理删除推广费类型
async function handleDelete(record: PromotionFeeTypeVO.Info) {
try {
await deletePromotionFeeTypeApi(record.id);
message.success('删除成功');
refreshTable();
} catch (error) {
console.error('删除推广费类型失败:', error);
message.error('删除推广费类型失败');
}
}
// 处理模态框成功
function handleModalSuccess() {
refreshTable();
}
</script>
<template>
<Page title="推广费用类型配置" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理推广费用类型,包括费用类型名称、描述、计算方式和启用状态
</div>
</template>
<!-- VbenVxeGrid 表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon />
添加类型
</Button>
</Space>
</template>
<!-- 计算方式列 -->
<template #calculationMethod="{ row }: { row: any }">
<Tag color="blue">
{{
calculationMethodOptions.find(
(opt) => opt.value === row.calculationMethod,
)?.label || '未设置'
}}
</Tag>
</template>
<!-- 状态列 -->
<template #status="{ row }: { row: any }">
<Tag :color="row.isActive === 1 ? 'green' : 'red'">
{{ row.isActive === 1 ? '启用' : '禁用' }}
</Tag>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
<Popconfirm
title="确定要删除这个推广费类型吗?"
@confirm="handleDelete(row)"
>
<Button size="small" danger> 删除 </Button>
</Popconfirm>
</Space>
</template>
</Grid>
<!-- 推广费类型表单模态框 -->
<PromotionFeeTypeFormModal
ref="promotionFeeTypeFormModalRef"
@success="handleModalSuccess"
/>
</Page>
</template>
@@ -28,8 +28,6 @@ const createModalRef = ref<InstanceType<typeof CreateApiKeyModal>>();
const permissionLabelMap: Record<string, string> = {
'open:scope:order:import': '订单导入',
'open:scope:order:read': '订单字段',
'open:scope:promotion_fee:import': '推广费导入',
'open:scope:promotion_fee:read': '推广费字段',
'open:scope:import_task:read': '导入任务',
'open:scope:meta:read': '元数据',
};