mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 07:49:19 +08:00
refactor: 推广记录 platform 字段改为外键关联 ec_platform 表,平台下拉动态加载
This commit is contained in:
@@ -9,8 +9,8 @@ export namespace PromotionFeeDTO {
|
||||
shopId?: number;
|
||||
/** 推广费类型ID */
|
||||
feeTypeId?: number;
|
||||
/** 平台 */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
/** 推广费发生日期开始 */
|
||||
feeDateStart?: string;
|
||||
/** 推广费发生日期结束 */
|
||||
@@ -25,8 +25,8 @@ export namespace PromotionFeeDTO {
|
||||
feeTypeId: number;
|
||||
/** 推广费名称 */
|
||||
feeName: string;
|
||||
/** 平台(淘宝、京东、拼多多等) */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
/** 推广活动名称 */
|
||||
campaignName?: string;
|
||||
/** 推广费金额 */
|
||||
@@ -57,8 +57,8 @@ export namespace PromotionFeeDTO {
|
||||
feeTypeId: number;
|
||||
/** 推广费名称 */
|
||||
feeName: string;
|
||||
/** 平台(淘宝、京东、拼多多等) */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
/** 推广活动名称 */
|
||||
campaignName?: string;
|
||||
/** 推广费金额 */
|
||||
@@ -78,4 +78,4 @@ export namespace PromotionFeeDTO {
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,10 @@ export namespace PromotionFeeVO {
|
||||
feeTypeName?: string;
|
||||
/** 推广费名称 */
|
||||
feeName: string;
|
||||
/** 平台(淘宝、京东、拼多多等) */
|
||||
platform?: string;
|
||||
/** 平台ID */
|
||||
platformId?: number;
|
||||
/** 平台名称 */
|
||||
platformName?: string;
|
||||
/** 推广活动名称 */
|
||||
campaignName?: string;
|
||||
/** 推广费金额 */
|
||||
@@ -48,4 +50,4 @@ export namespace PromotionFeeVO {
|
||||
/** 更新人ID */
|
||||
updateBy?: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
-30
@@ -26,6 +26,7 @@ import {
|
||||
updatePromotionFeeApi,
|
||||
} from '#/api/ecommerce/promotion-fee';
|
||||
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
defineOptions({ name: 'PromotionFeeFormModal' });
|
||||
@@ -47,7 +48,6 @@ interface Emits {
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[800px]',
|
||||
@@ -66,16 +66,14 @@ const [Modal, modalApi] = useVbenModal({
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<PromotionFeeDTO.Create>({
|
||||
shopId: undefined as any,
|
||||
feeTypeId: undefined as any,
|
||||
feeName: '',
|
||||
platform: undefined,
|
||||
platformId: undefined,
|
||||
campaignName: '',
|
||||
feeAmount: undefined as any,
|
||||
baseAmount: undefined,
|
||||
@@ -87,7 +85,6 @@ const formData = ref<PromotionFeeDTO.Create>({
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
feeTypeId: [
|
||||
@@ -98,16 +95,9 @@ const rules = {
|
||||
feeDate: [{ required: true, message: '请选择发生日期', trigger: 'change' }],
|
||||
} as any;
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
{ label: '抖音', value: '抖音' },
|
||||
{ label: '快手', value: '快手' },
|
||||
{ label: '其他', value: '其他' },
|
||||
];
|
||||
// 平台选项(动态加载)
|
||||
const platformList = ref<{ label: string; value: number }[]>([]);
|
||||
const platformListLoading = ref(false);
|
||||
|
||||
// 店铺列表
|
||||
const shopList = ref<ShopVO.Info[]>([]);
|
||||
@@ -117,7 +107,6 @@ const shopListLoading = ref(false);
|
||||
const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
|
||||
const feeTypeListLoading = ref(false);
|
||||
|
||||
// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi
|
||||
watch(
|
||||
() => props.open,
|
||||
async (newVal) => {
|
||||
@@ -131,7 +120,7 @@ watch(
|
||||
shopId: props.promotionFeeData.shopId,
|
||||
feeTypeId: props.promotionFeeData.feeTypeId,
|
||||
feeName: props.promotionFeeData.feeName,
|
||||
platform: props.promotionFeeData.platform,
|
||||
platformId: props.promotionFeeData.platformId,
|
||||
campaignName: props.promotionFeeData.campaignName || '',
|
||||
feeAmount: props.promotionFeeData.feeAmount,
|
||||
baseAmount: props.promotionFeeData.baseAmount,
|
||||
@@ -154,7 +143,6 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
// 加载店铺列表
|
||||
const loadShopList = async () => {
|
||||
shopListLoading.value = true;
|
||||
try {
|
||||
@@ -171,7 +159,6 @@ const loadShopList = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 加载推广费类型列表
|
||||
const loadFeeTypeList = async () => {
|
||||
feeTypeListLoading.value = true;
|
||||
try {
|
||||
@@ -184,13 +171,27 @@ const loadFeeTypeList = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 重置表单数据
|
||||
const loadPlatformList = async () => {
|
||||
platformListLoading.value = true;
|
||||
try {
|
||||
const list = await getActivePlatformsApi();
|
||||
platformList.value = list.map((p) => ({
|
||||
label: p.platformName,
|
||||
value: p.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('加载平台列表失败:', error);
|
||||
} finally {
|
||||
platformListLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const resetFormData = () => {
|
||||
formData.value = {
|
||||
shopId: undefined as any,
|
||||
feeTypeId: undefined as any,
|
||||
feeName: '',
|
||||
platform: undefined,
|
||||
platformId: undefined,
|
||||
campaignName: '',
|
||||
feeAmount: undefined as any,
|
||||
baseAmount: undefined,
|
||||
@@ -203,13 +204,11 @@ const resetFormData = () => {
|
||||
};
|
||||
};
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && props.promotionFeeData) {
|
||||
// 更新推广费记录
|
||||
const updateData: PromotionFeeDTO.Update = {
|
||||
id: props.promotionFeeData.id,
|
||||
...formData.value,
|
||||
@@ -217,7 +216,6 @@ const handleOk = async () => {
|
||||
await updatePromotionFeeApi(updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
// 创建推广费记录
|
||||
await createPromotionFeeApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
@@ -230,16 +228,15 @@ const handleOk = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 取消:关闭与重置由 onOpenChange 统一处理
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
modalApi.close();
|
||||
};
|
||||
|
||||
// 组件挂载时加载数据
|
||||
onMounted(() => {
|
||||
loadShopList();
|
||||
loadFeeTypeList();
|
||||
loadPlatformList();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -291,14 +288,15 @@ onMounted(() => {
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Form.Item label="平台" name="platformId">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
v-model:value="formData.platformId"
|
||||
placeholder="请选择平台"
|
||||
:loading="platformListLoading"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in platformOptions"
|
||||
v-for="option in platformList"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
@@ -389,4 +387,4 @@ onMounted(() => {
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
</template>
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
getPromotionFeePageApi,
|
||||
} from '#/api/ecommerce/promotion-fee';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform/apis';
|
||||
import { getAllPromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type/apis';
|
||||
|
||||
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
|
||||
@@ -83,21 +84,25 @@ async function fetchFeeTypeOptions() {
|
||||
const searchForm = ref({
|
||||
shopId: undefined as number | undefined,
|
||||
feeTypeId: undefined as number | undefined,
|
||||
platform: '',
|
||||
platformId: undefined as number | undefined,
|
||||
feeDateStart: undefined as string | undefined,
|
||||
feeDateEnd: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
{ label: '抖音', value: '抖音' },
|
||||
{ label: '快手', value: '快手' },
|
||||
{ label: '其他', value: '其他' },
|
||||
];
|
||||
// 平台选项(动态加载)
|
||||
const platformOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const loadPlatformOptions = async () => {
|
||||
try {
|
||||
const list = await getActivePlatformsApi();
|
||||
platformOptions.value = list.map((p) => ({
|
||||
label: p.platformName,
|
||||
value: p.id,
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
};
|
||||
loadPlatformOptions();
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
@@ -200,7 +205,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
filters: {
|
||||
shopId: searchForm.value.shopId || undefined,
|
||||
feeTypeId: searchForm.value.feeTypeId || undefined,
|
||||
platform: searchForm.value.platform || undefined,
|
||||
platformId: searchForm.value.platformId || undefined,
|
||||
feeDateStart: searchForm.value.feeDateStart || undefined,
|
||||
feeDateEnd: searchForm.value.feeDateEnd || undefined,
|
||||
},
|
||||
@@ -273,7 +278,7 @@ const formOptions = computed(() => ({
|
||||
allowClear: true,
|
||||
onChange: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'platform',
|
||||
fieldName: 'platformId',
|
||||
label: '平台',
|
||||
},
|
||||
{
|
||||
@@ -352,8 +357,8 @@ const formatAmount = (amount: number) => {
|
||||
};
|
||||
|
||||
// 获取平台标签颜色
|
||||
const getPlatformColor = (platform: string | undefined) => {
|
||||
switch (platform) {
|
||||
const getPlatformColor = (platformName: string | undefined) => {
|
||||
switch (platformName) {
|
||||
case '京东': {
|
||||
return 'red';
|
||||
}
|
||||
@@ -409,8 +414,8 @@ const getPlatformColor = (platform: string | undefined) => {
|
||||
|
||||
<!-- 平台列 -->
|
||||
<template #platform="{ row }: { row: any }">
|
||||
<Tag v-if="row.platform" :color="getPlatformColor(row.platform)">
|
||||
{{ row.platform }}
|
||||
<Tag v-if="row.platformName" :color="getPlatformColor(row.platformName)">
|
||||
{{ row.platformName }}
|
||||
</Tag>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
|
||||
+23
-8
@@ -4,7 +4,7 @@ import type { PromotionFeeDTO, PromotionFeeVO } from '#/api/ecommerce/promotion-
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { Button, DatePicker, Input, Popconfirm, Space } from 'ant-design-vue';
|
||||
import { Button, DatePicker, Popconfirm, Select, Space } from 'ant-design-vue';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
deletePromotionFeeApi,
|
||||
getPromotionFeePageApi,
|
||||
} from '#/api/ecommerce/promotion-fee';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
|
||||
|
||||
import PromotionFeeFormModal from '#/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue';
|
||||
|
||||
@@ -30,11 +31,24 @@ const kpi = computed(() => props.data);
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
|
||||
const searchForm = ref({
|
||||
platform: undefined as string | undefined,
|
||||
platformId: undefined as number | undefined,
|
||||
feeDateStart: undefined as string | undefined,
|
||||
feeDateEnd: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 平台选项(动态加载)
|
||||
const platformList = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
const loadPlatformList = async () => {
|
||||
try {
|
||||
const list = await getActivePlatformsApi();
|
||||
platformList.value = list.map((p) => ({ label: p.platformName, value: p.id }));
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
};
|
||||
loadPlatformList();
|
||||
|
||||
const modalVisible = ref(false);
|
||||
const editingData = ref<PromotionFeeVO.Info | undefined>();
|
||||
|
||||
@@ -42,8 +56,8 @@ const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{ type: 'seq', title: '序号', width: 60 },
|
||||
{ field: 'feeName', title: '费用名称', width: 110 },
|
||||
{ field: 'platformName', title: '平台', width: 90 },
|
||||
{ field: 'campaignName', title: '活动名称', minWidth: 140 },
|
||||
{ field: 'platform', title: '平台', width: 90 },
|
||||
{
|
||||
field: 'feeAmount', title: '费用金额', width: 130,
|
||||
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
|
||||
@@ -71,7 +85,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: props.shopId || undefined,
|
||||
platform: searchForm.value.platform,
|
||||
platformId: searchForm.value.platformId,
|
||||
feeDateStart: searchForm.value.feeDateStart,
|
||||
feeDateEnd: searchForm.value.feeDateEnd,
|
||||
},
|
||||
@@ -115,11 +129,12 @@ async function handleDelete(id: number) {
|
||||
<span>推广费</span>
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<Input
|
||||
v-model:value="searchForm.platform"
|
||||
<Select
|
||||
v-model:value="searchForm.platformId"
|
||||
placeholder="平台"
|
||||
class="!w-24"
|
||||
class="!w-28"
|
||||
allow-clear
|
||||
:options="platformList"
|
||||
@change="() => gridReloadRef?.()"
|
||||
/>
|
||||
<DatePicker
|
||||
@@ -179,4 +194,4 @@ async function handleDelete(id: number) {
|
||||
@success="gridReloadRef?.()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
Reference in New Issue
Block a user