refactor: 推广记录 platform 字段改为外键关联 ec_platform 表,平台下拉动态加载

This commit is contained in:
小蟑螂
2026-04-30 22:26:10 +08:00
parent b063f65568
commit ddfde20efc
12 changed files with 136 additions and 99 deletions
+3 -2
View File
@@ -292,8 +292,8 @@ CREATE TABLE `ec_promotion_fee` (
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID', `company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID', `shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
`fee_type_id` bigint UNSIGNED NOT NULL COMMENT '推广费类型ID', `fee_type_id` bigint UNSIGNED NOT NULL COMMENT '推广费类型ID',
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID',
`fee_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '推广费名称', `fee_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '推广费名称',
`platform` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台(淘宝、京东、拼多多等)',
`campaign_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '推广活动名称', `campaign_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '推广活动名称',
`fee_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '推广费金额', `fee_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '推广费金额',
`base_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '基础金额(用于按比例计算)', `base_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '基础金额(用于按比例计算)',
@@ -312,12 +312,13 @@ CREATE TABLE `ec_promotion_fee` (
INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE, INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE,
INDEX `idx_fee_type_id`(`fee_type_id` ASC) USING BTREE, INDEX `idx_fee_type_id`(`fee_type_id` ASC) USING BTREE,
INDEX `idx_fee_date`(`fee_date` ASC) USING BTREE, INDEX `idx_fee_date`(`fee_date` ASC) USING BTREE,
INDEX `idx_platform`(`platform` ASC) USING BTREE, INDEX `idx_platform_id`(`platform_id` ASC) USING BTREE,
INDEX `fk_ec_promotion_fee_creator`(`create_by` ASC) USING BTREE, INDEX `fk_ec_promotion_fee_creator`(`create_by` ASC) USING BTREE,
INDEX `fk_ec_promotion_fee_updater`(`update_by` ASC) USING BTREE, INDEX `fk_ec_promotion_fee_updater`(`update_by` ASC) USING BTREE,
CONSTRAINT `fk_ec_promotion_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_ec_promotion_fee_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_ec_promotion_fee_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_ec_promotion_fee_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_platform` FOREIGN KEY (`platform_id`) REFERENCES `ec_platform` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_type` FOREIGN KEY (`fee_type_id`) REFERENCES `ec_promotion_fee_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT `fk_ec_promotion_fee_type` FOREIGN KEY (`fee_type_id`) REFERENCES `ec_promotion_fee_type` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-推广费记录表' ; ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-推广费记录表' ;
@@ -37,10 +37,10 @@ public class CreatePromotionFeeDTO {
private String feeName; private String feeName;
/** /**
* 平台(淘宝、京东、拼多多等) * 平台ID
*/ */
@Schema(description = "平台", example = "淘宝") @Schema(description = "平台ID", example = "1")
private String platform; private Long platformId;
/** /**
* 推广活动名称 * 推广活动名称
@@ -25,10 +25,10 @@ public class PromotionFeeFilterDTO {
private Long feeTypeId; private Long feeTypeId;
/** /**
* 平台 * 平台ID
*/ */
@Schema(description = "平台", example = "淘宝") @Schema(description = "平台ID", example = "1")
private String platform; private Long platformId;
/** /**
* 推广费发生日期开始 * 推广费发生日期开始
@@ -44,10 +44,10 @@ public class UpdatePromotionFeeDTO {
private String feeName; private String feeName;
/** /**
* 平台(淘宝、京东、拼多多等) * 平台ID
*/ */
@Schema(description = "平台", example = "淘宝") @Schema(description = "平台ID", example = "1")
private String platform; private Long platformId;
/** /**
* 推广活动名称 * 推广活动名称
@@ -40,18 +40,18 @@ public class PromotionFeePO {
@TableField("fee_type_id") @TableField("fee_type_id")
private Long feeTypeId; private Long feeTypeId;
/**
* 平台ID
*/
@TableField("platform_id")
private Long platformId;
/** /**
* 推广费名称 * 推广费名称
*/ */
@TableField("fee_name") @TableField("fee_name")
private String feeName; private String feeName;
/**
* 平台(淘宝、京东、拼多多等)
*/
@TableField("platform")
private String platform;
/** /**
* 推广活动名称 * 推广活动名称
*/ */
@@ -50,6 +50,18 @@ public class PromotionFeeVO {
@Schema(description = "推广费类型名称", example = "直通车") @Schema(description = "推广费类型名称", example = "直通车")
private String feeTypeName; private String feeTypeName;
/**
* 平台ID
*/
@Schema(description = "平台ID", example = "1")
private Long platformId;
/**
* 平台名称
*/
@Schema(description = "平台名称", example = "淘宝")
private String platformName;
/** /**
* 推广费名称 * 推广费名称
*/ */
@@ -17,8 +17,9 @@ import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.dto.UpdatePromotio
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.vo.PromotionFeeVO; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.vo.PromotionFeeVO;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.PromotionFeeService; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.PromotionFeeService;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.PromotionFeeTypeService; import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.PromotionFeeTypeService;
import top.xyquan.ecomdmbbackend.modules.ecom.platform.service.PlatformService;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.util.List; import java.util.List;
@@ -35,6 +36,7 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
private final CurrentUserContext currentUserContext; private final CurrentUserContext currentUserContext;
private final ShopService shopService; private final ShopService shopService;
private final PromotionFeeTypeService promotionFeeTypeService; private final PromotionFeeTypeService promotionFeeTypeService;
private final PlatformService platformService;
/** /**
* 创建推广费记录 * 创建推广费记录
@@ -110,17 +112,13 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
*/ */
@Override @Override
public PageResultVO<PromotionFeeVO> getPromotionFeePage(PageQueryDTO<PromotionFeeFilterDTO> pageQueryDTO) { public PageResultVO<PromotionFeeVO> getPromotionFeePage(PageQueryDTO<PromotionFeeFilterDTO> pageQueryDTO) {
// 从token中获取公司ID
Long companyId = currentUserContext.getCurrentCompanyId(); Long companyId = currentUserContext.getCurrentCompanyId();
// 创建分页对象
Page<PromotionFeePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); Page<PromotionFeePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
// 构建查询条件
LambdaQueryWrapper<PromotionFeePO> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PromotionFeePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(PromotionFeePO::getCompanyId, companyId); wrapper.eq(PromotionFeePO::getCompanyId, companyId);
// 添加过滤条件
PromotionFeeFilterDTO filter = pageQueryDTO.getFilters(); PromotionFeeFilterDTO filter = pageQueryDTO.getFilters();
if (filter != null) { if (filter != null) {
if (filter.getShopId() != null) { if (filter.getShopId() != null) {
@@ -129,8 +127,8 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
if (filter.getFeeTypeId() != null) { if (filter.getFeeTypeId() != null) {
wrapper.eq(PromotionFeePO::getFeeTypeId, filter.getFeeTypeId()); wrapper.eq(PromotionFeePO::getFeeTypeId, filter.getFeeTypeId());
} }
if (filter.getPlatform() != null && !filter.getPlatform().trim().isEmpty()) { if (filter.getPlatformId() != null) {
wrapper.like(PromotionFeePO::getPlatform, filter.getPlatform()); wrapper.eq(PromotionFeePO::getPlatformId, filter.getPlatformId());
} }
if (filter.getFeeDateStart() != null) { if (filter.getFeeDateStart() != null) {
wrapper.ge(PromotionFeePO::getFeeDate, filter.getFeeDateStart()); wrapper.ge(PromotionFeePO::getFeeDate, filter.getFeeDateStart());
@@ -140,19 +138,15 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
} }
} }
// 排序
wrapper.orderByDesc(PromotionFeePO::getFeeDate) wrapper.orderByDesc(PromotionFeePO::getFeeDate)
.orderByDesc(PromotionFeePO::getCreateTime); .orderByDesc(PromotionFeePO::getCreateTime);
// 执行分页查询
IPage<PromotionFeePO> pageResult = promotionFeeMapper.selectPage(page, wrapper); IPage<PromotionFeePO> pageResult = promotionFeeMapper.selectPage(page, wrapper);
// 转换为VO
List<PromotionFeeVO> voList = pageResult.getRecords().stream() List<PromotionFeeVO> voList = pageResult.getRecords().stream()
.map(this::convertToVO) .map(this::convertToVO)
.collect(Collectors.toList()); .collect(Collectors.toList());
// 构建分页结果
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
} }
@@ -182,7 +176,17 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
vo.setFeeTypeName(feeTypeVO.getTypeName()); vo.setFeeTypeName(feeTypeVO.getTypeName());
} }
} catch (Exception ignored) { } catch (Exception ignored) {
// 查询失败不影响主流程 }
}
// 填充平台名称
if (po.getPlatformId() != null) {
try {
var platform = platformService.getById(po.getPlatformId());
if (platform != null) {
vo.setPlatformName(platform.getPlatformName());
}
} catch (Exception ignored) {
} }
} }
@@ -9,8 +9,8 @@ export namespace PromotionFeeDTO {
shopId?: number; shopId?: number;
/** 推广费类型ID */ /** 推广费类型ID */
feeTypeId?: number; feeTypeId?: number;
/** 平台 */ /** 平台ID */
platform?: string; platformId?: number;
/** 推广费发生日期开始 */ /** 推广费发生日期开始 */
feeDateStart?: string; feeDateStart?: string;
/** 推广费发生日期结束 */ /** 推广费发生日期结束 */
@@ -25,8 +25,8 @@ export namespace PromotionFeeDTO {
feeTypeId: number; feeTypeId: number;
/** 推广费名称 */ /** 推广费名称 */
feeName: string; feeName: string;
/** 平台(淘宝、京东、拼多多等) */ /** 平台ID */
platform?: string; platformId?: number;
/** 推广活动名称 */ /** 推广活动名称 */
campaignName?: string; campaignName?: string;
/** 推广费金额 */ /** 推广费金额 */
@@ -57,8 +57,8 @@ export namespace PromotionFeeDTO {
feeTypeId: number; feeTypeId: number;
/** 推广费名称 */ /** 推广费名称 */
feeName: string; feeName: string;
/** 平台(淘宝、京东、拼多多等) */ /** 平台ID */
platform?: string; platformId?: number;
/** 推广活动名称 */ /** 推广活动名称 */
campaignName?: string; campaignName?: string;
/** 推广费金额 */ /** 推广费金额 */
@@ -19,8 +19,10 @@ export namespace PromotionFeeVO {
feeTypeName?: string; feeTypeName?: string;
/** 推广费名称 */ /** 推广费名称 */
feeName: string; feeName: string;
/** 平台(淘宝、京东、拼多多等) */ /** 平台ID */
platform?: string; platformId?: number;
/** 平台名称 */
platformName?: string;
/** 推广活动名称 */ /** 推广活动名称 */
campaignName?: string; campaignName?: string;
/** 推广费金额 */ /** 推广费金额 */
@@ -26,6 +26,7 @@ import {
updatePromotionFeeApi, updatePromotionFeeApi,
} from '#/api/ecommerce/promotion-fee'; } from '#/api/ecommerce/promotion-fee';
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type'; import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type';
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
import { getShopPageApi } from '#/api/ecommerce/shop'; import { getShopPageApi } from '#/api/ecommerce/shop';
defineOptions({ name: 'PromotionFeeFormModal' }); defineOptions({ name: 'PromotionFeeFormModal' });
@@ -47,7 +48,6 @@ interface Emits {
(e: 'cancel'): void; (e: 'cancel'): void;
} }
// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
draggable: true, draggable: true,
class: 'w-[800px]', class: 'w-[800px]',
@@ -66,16 +66,14 @@ const [Modal, modalApi] = useVbenModal({
}, },
}); });
// 响应式数据
const formRef = ref(); const formRef = ref();
const isEdit = ref(false); const isEdit = ref(false);
// 表单数据
const formData = ref<PromotionFeeDTO.Create>({ const formData = ref<PromotionFeeDTO.Create>({
shopId: undefined as any, shopId: undefined as any,
feeTypeId: undefined as any, feeTypeId: undefined as any,
feeName: '', feeName: '',
platform: undefined, platformId: undefined,
campaignName: '', campaignName: '',
feeAmount: undefined as any, feeAmount: undefined as any,
baseAmount: undefined, baseAmount: undefined,
@@ -87,7 +85,6 @@ const formData = ref<PromotionFeeDTO.Create>({
remark: '', remark: '',
}); });
// 表单验证规则
const rules = { const rules = {
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }], shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
feeTypeId: [ feeTypeId: [
@@ -98,16 +95,9 @@ const rules = {
feeDate: [{ required: true, message: '请选择发生日期', trigger: 'change' }], feeDate: [{ required: true, message: '请选择发生日期', trigger: 'change' }],
} as any; } as any;
// 平台选项 // 平台选项(动态加载)
const platformOptions = [ const platformList = ref<{ label: string; value: number }[]>([]);
{ label: '淘宝', value: '淘宝' }, const platformListLoading = ref(false);
{ label: '京东', value: '京东' },
{ label: '拼多多', value: '拼多多' },
{ label: '天猫', value: '天猫' },
{ label: '抖音', value: '抖音' },
{ label: '快手', value: '快手' },
{ label: '其他', value: '其他' },
];
// 店铺列表 // 店铺列表
const shopList = ref<ShopVO.Info[]>([]); const shopList = ref<ShopVO.Info[]>([]);
@@ -117,7 +107,6 @@ const shopListLoading = ref(false);
const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]); const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
const feeTypeListLoading = ref(false); const feeTypeListLoading = ref(false);
// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi
watch( watch(
() => props.open, () => props.open,
async (newVal) => { async (newVal) => {
@@ -131,7 +120,7 @@ watch(
shopId: props.promotionFeeData.shopId, shopId: props.promotionFeeData.shopId,
feeTypeId: props.promotionFeeData.feeTypeId, feeTypeId: props.promotionFeeData.feeTypeId,
feeName: props.promotionFeeData.feeName, feeName: props.promotionFeeData.feeName,
platform: props.promotionFeeData.platform, platformId: props.promotionFeeData.platformId,
campaignName: props.promotionFeeData.campaignName || '', campaignName: props.promotionFeeData.campaignName || '',
feeAmount: props.promotionFeeData.feeAmount, feeAmount: props.promotionFeeData.feeAmount,
baseAmount: props.promotionFeeData.baseAmount, baseAmount: props.promotionFeeData.baseAmount,
@@ -154,7 +143,6 @@ watch(
}, },
); );
// 加载店铺列表
const loadShopList = async () => { const loadShopList = async () => {
shopListLoading.value = true; shopListLoading.value = true;
try { try {
@@ -171,7 +159,6 @@ const loadShopList = async () => {
} }
}; };
// 加载推广费类型列表
const loadFeeTypeList = async () => { const loadFeeTypeList = async () => {
feeTypeListLoading.value = true; feeTypeListLoading.value = true;
try { 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 = () => { const resetFormData = () => {
formData.value = { formData.value = {
shopId: undefined as any, shopId: undefined as any,
feeTypeId: undefined as any, feeTypeId: undefined as any,
feeName: '', feeName: '',
platform: undefined, platformId: undefined,
campaignName: '', campaignName: '',
feeAmount: undefined as any, feeAmount: undefined as any,
baseAmount: undefined, baseAmount: undefined,
@@ -203,13 +204,11 @@ const resetFormData = () => {
}; };
}; };
// 确认操作
const handleOk = async () => { const handleOk = async () => {
try { try {
await formRef.value?.validate(); await formRef.value?.validate();
if (isEdit.value && props.promotionFeeData) { if (isEdit.value && props.promotionFeeData) {
// 更新推广费记录
const updateData: PromotionFeeDTO.Update = { const updateData: PromotionFeeDTO.Update = {
id: props.promotionFeeData.id, id: props.promotionFeeData.id,
...formData.value, ...formData.value,
@@ -217,7 +216,6 @@ const handleOk = async () => {
await updatePromotionFeeApi(updateData); await updatePromotionFeeApi(updateData);
message.success('更新成功'); message.success('更新成功');
} else { } else {
// 创建推广费记录
await createPromotionFeeApi(formData.value); await createPromotionFeeApi(formData.value);
message.success('创建成功'); message.success('创建成功');
} }
@@ -230,16 +228,15 @@ const handleOk = async () => {
} }
}; };
// 取消:关闭与重置由 onOpenChange 统一处理
const handleCancel = () => { const handleCancel = () => {
emit('cancel'); emit('cancel');
modalApi.close(); modalApi.close();
}; };
// 组件挂载时加载数据
onMounted(() => { onMounted(() => {
loadShopList(); loadShopList();
loadFeeTypeList(); loadFeeTypeList();
loadPlatformList();
}); });
</script> </script>
@@ -291,14 +288,15 @@ onMounted(() => {
/> />
</Form.Item> </Form.Item>
<Form.Item label="平台" name="platform"> <Form.Item label="平台" name="platformId">
<Select <Select
v-model:value="formData.platform" v-model:value="formData.platformId"
placeholder="请选择平台" placeholder="请选择平台"
:loading="platformListLoading"
allow-clear allow-clear
> >
<Select.Option <Select.Option
v-for="option in platformOptions" v-for="option in platformList"
:key="option.value" :key="option.value"
:value="option.value" :value="option.value"
> >
@@ -19,6 +19,7 @@ import {
getPromotionFeePageApi, getPromotionFeePageApi,
} from '#/api/ecommerce/promotion-fee'; } from '#/api/ecommerce/promotion-fee';
import { getShopPageApi } from '#/api/ecommerce/shop/apis'; import { getShopPageApi } from '#/api/ecommerce/shop/apis';
import { getActivePlatformsApi } from '#/api/ecommerce/platform/apis';
import { getAllPromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type/apis'; import { getAllPromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type/apis';
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue'; import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
@@ -83,21 +84,25 @@ async function fetchFeeTypeOptions() {
const searchForm = ref({ const searchForm = ref({
shopId: undefined as number | undefined, shopId: undefined as number | undefined,
feeTypeId: undefined as number | undefined, feeTypeId: undefined as number | undefined,
platform: '', platformId: undefined as number | undefined,
feeDateStart: undefined as string | undefined, feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined, feeDateEnd: undefined as string | undefined,
}); });
// 平台选项 // 平台选项(动态加载)
const platformOptions = [ const platformOptions = ref<{ label: string; value: number }[]>([]);
{ label: '淘宝', value: '淘宝' }, const loadPlatformOptions = async () => {
{ label: '京东', value: '京东' }, try {
{ label: '拼多多', value: '拼多多' }, const list = await getActivePlatformsApi();
{ label: '天猫', value: '天猫' }, platformOptions.value = list.map((p) => ({
{ label: '抖音', value: '抖音' }, label: p.platformName,
{ label: '快手', value: '快手' }, value: p.id,
{ label: '其他', value: '其他' }, }));
]; } catch (e) {
console.error('加载平台列表失败', e);
}
};
loadPlatformOptions();
// VbenVxeGrid 表格配置 // VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = { const gridOptions: VxeGridProps<any> = {
@@ -200,7 +205,7 @@ const gridOptions: VxeGridProps<any> = {
filters: { filters: {
shopId: searchForm.value.shopId || undefined, shopId: searchForm.value.shopId || undefined,
feeTypeId: searchForm.value.feeTypeId || undefined, feeTypeId: searchForm.value.feeTypeId || undefined,
platform: searchForm.value.platform || undefined, platformId: searchForm.value.platformId || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined, feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined, feeDateEnd: searchForm.value.feeDateEnd || undefined,
}, },
@@ -273,7 +278,7 @@ const formOptions = computed(() => ({
allowClear: true, allowClear: true,
onChange: () => gridReloadRef.value?.(), onChange: () => gridReloadRef.value?.(),
}, },
fieldName: 'platform', fieldName: 'platformId',
label: '平台', label: '平台',
}, },
{ {
@@ -352,8 +357,8 @@ const formatAmount = (amount: number) => {
}; };
// 获取平台标签颜色 // 获取平台标签颜色
const getPlatformColor = (platform: string | undefined) => { const getPlatformColor = (platformName: string | undefined) => {
switch (platform) { switch (platformName) {
case '京东': { case '京东': {
return 'red'; return 'red';
} }
@@ -409,8 +414,8 @@ const getPlatformColor = (platform: string | undefined) => {
<!-- 平台列 --> <!-- 平台列 -->
<template #platform="{ row }: { row: any }"> <template #platform="{ row }: { row: any }">
<Tag v-if="row.platform" :color="getPlatformColor(row.platform)"> <Tag v-if="row.platformName" :color="getPlatformColor(row.platformName)">
{{ row.platform }} {{ row.platformName }}
</Tag> </Tag>
<span v-else class="text-gray-400">-</span> <span v-else class="text-gray-400">-</span>
</template> </template>
@@ -4,7 +4,7 @@ import type { PromotionFeeDTO, PromotionFeeVO } from '#/api/ecommerce/promotion-
import type { ShopVO } from '#/api/ecommerce/shop/types'; import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common'; 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 { computed, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons'; import { createIconifyIcon } from '@vben/icons';
@@ -13,6 +13,7 @@ import {
deletePromotionFeeApi, deletePromotionFeeApi,
getPromotionFeePageApi, getPromotionFeePageApi,
} from '#/api/ecommerce/promotion-fee'; } from '#/api/ecommerce/promotion-fee';
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
import PromotionFeeFormModal from '#/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue'; 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 gridReloadRef = ref<(() => void) | null>(null);
const searchForm = ref({ const searchForm = ref({
platform: undefined as string | undefined, platformId: undefined as number | undefined,
feeDateStart: undefined as string | undefined, feeDateStart: undefined as string | undefined,
feeDateEnd: 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 modalVisible = ref(false);
const editingData = ref<PromotionFeeVO.Info | undefined>(); const editingData = ref<PromotionFeeVO.Info | undefined>();
@@ -42,8 +56,8 @@ const gridOptions: VxeGridProps<any> = {
columns: [ columns: [
{ type: 'seq', title: '序号', width: 60 }, { type: 'seq', title: '序号', width: 60 },
{ field: 'feeName', title: '费用名称', width: 110 }, { field: 'feeName', title: '费用名称', width: 110 },
{ field: 'platformName', title: '平台', width: 90 },
{ field: 'campaignName', title: '活动名称', minWidth: 140 }, { field: 'campaignName', title: '活动名称', minWidth: 140 },
{ field: 'platform', title: '平台', width: 90 },
{ {
field: 'feeAmount', title: '费用金额', width: 130, field: 'feeAmount', title: '费用金额', width: 130,
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`, formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
@@ -71,7 +85,7 @@ const gridOptions: VxeGridProps<any> = {
pageSize: page.pageSize, pageSize: page.pageSize,
filters: { filters: {
shopId: props.shopId || undefined, shopId: props.shopId || undefined,
platform: searchForm.value.platform, platformId: searchForm.value.platformId,
feeDateStart: searchForm.value.feeDateStart, feeDateStart: searchForm.value.feeDateStart,
feeDateEnd: searchForm.value.feeDateEnd, feeDateEnd: searchForm.value.feeDateEnd,
}, },
@@ -115,11 +129,12 @@ async function handleDelete(id: number) {
<span>推广费</span> <span>推广费</span>
</h3> </h3>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<Input <Select
v-model:value="searchForm.platform" v-model:value="searchForm.platformId"
placeholder="平台" placeholder="平台"
class="!w-24" class="!w-28"
allow-clear allow-clear
:options="platformList"
@change="() => gridReloadRef?.()" @change="() => gridReloadRef?.()"
/> />
<DatePicker <DatePicker