修复类型报错

This commit is contained in:
ah--desktop
2025-09-25 23:37:37 +08:00
parent 2ddff44068
commit 0dfd0be32f
11 changed files with 1573 additions and 8 deletions
@@ -7,3 +7,6 @@ export * from './shop.apis';
// 商品相关API
export * from './product.apis';
// 推广费相关API
export * from './promotion-fee.apis';
@@ -0,0 +1,43 @@
import { requestClient } from '#/api/request';
import type { PageQueryDTO, PageResultVO } from '#/types/common';
import type { PromotionFeeDTO, PromotionFeeVO } from './types';
/**
* 推广费管理API
*/
/**
* 分页获取推广费记录列表
*/
export async function getPromotionFeePageApi(params: PageQueryDTO<PromotionFeeDTO.Filters>) {
return requestClient.post<PageResultVO<PromotionFeeVO.Info>>('/ec/promotion-fee/page', params);
}
/**
* 创建推广费记录
*/
export async function createPromotionFeeApi(data: PromotionFeeDTO.Create) {
return requestClient.post<number>('/ec/promotion-fee', data);
}
/**
* 更新推广费记录
*/
export async function updatePromotionFeeApi(data: PromotionFeeDTO.Update) {
return requestClient.put<void>('/ec/promotion-fee', data);
}
/**
* 删除推广费记录
*/
export async function deletePromotionFeeApi(id: number) {
return requestClient.delete<void>(`/ec/promotion-fee/${id}`);
}
/**
* 获取推广费记录详情
*/
export async function getPromotionFeeByIdApi(id: number) {
return requestClient.get<PromotionFeeVO.Info>(`/ec/promotion-fee/${id}`);
}
@@ -0,0 +1,81 @@
/**
* 推广费管理相关DTO类型定义
*/
export namespace PromotionFeeDTO {
/** 推广费查询过滤条件 */
export interface Filters {
/** 店铺ID */
shopId?: number;
/** 推广费类型ID */
feeTypeId?: number;
/** 平台 */
platform?: string;
/** 推广费发生日期开始 */
feeDateStart?: string;
/** 推广费发生日期结束 */
feeDateEnd?: string;
}
/** 创建推广费记录 */
export interface Create {
/** 店铺ID */
shopId: number;
/** 推广费类型ID */
feeTypeId: number;
/** 推广费名称 */
feeName: string;
/** 平台(淘宝、京东、拼多多等) */
platform?: string;
/** 推广活动名称 */
campaignName?: string;
/** 推广费金额 */
feeAmount: number;
/** 基础金额(用于按比例计算) */
baseAmount?: number;
/** 费率(用于按比例计算) */
feeRate?: number;
/** 点击次数 */
clickCount?: number;
/** 展示次数 */
impressionCount?: number;
/** 转化次数 */
conversionCount?: number;
/** 推广费发生日期 */
feeDate: string;
/** 备注 */
remark?: string;
}
/** 更新推广费记录 */
export interface Update {
/** 推广费记录ID */
id: number;
/** 店铺ID */
shopId: number;
/** 推广费类型ID */
feeTypeId: number;
/** 推广费名称 */
feeName: string;
/** 平台(淘宝、京东、拼多多等) */
platform?: string;
/** 推广活动名称 */
campaignName?: string;
/** 推广费金额 */
feeAmount: number;
/** 基础金额(用于按比例计算) */
baseAmount?: number;
/** 费率(用于按比例计算) */
feeRate?: number;
/** 点击次数 */
clickCount?: number;
/** 展示次数 */
impressionCount?: number;
/** 转化次数 */
conversionCount?: number;
/** 推广费发生日期 */
feeDate: string;
/** 备注 */
remark?: string;
}
}
@@ -5,7 +5,9 @@
// DTO类型导出
export * from './dto.shop';
export * from './dto.product';
export * from './dto.promotion-fee';
// VO类型导出
export * from './vo.shop';
export * from './vo.product';
export * from './vo.promotion-fee';
@@ -0,0 +1,51 @@
/**
* 推广费管理相关VO类型定义
*/
export namespace PromotionFeeVO {
/** 推广费记录信息 */
export interface Info {
/** 推广费记录ID */
id: number;
/** 公司ID */
companyId: number;
/** 店铺ID */
shopId: number;
/** 店铺名称 */
shopName?: string;
/** 推广费类型ID */
feeTypeId: number;
/** 推广费类型名称 */
feeTypeName?: string;
/** 推广费名称 */
feeName: string;
/** 平台(淘宝、京东、拼多多等) */
platform?: string;
/** 推广活动名称 */
campaignName?: string;
/** 推广费金额 */
feeAmount: number;
/** 基础金额(用于按比例计算) */
baseAmount?: number;
/** 费率(用于按比例计算) */
feeRate?: number;
/** 点击次数 */
clickCount?: number;
/** 展示次数 */
impressionCount?: number;
/** 转化次数 */
conversionCount?: number;
/** 推广费发生日期 */
feeDate: string;
/** 备注 */
remark?: string;
/** 创建时间 */
createTime: string;
/** 更新时间 */
updateTime?: string;
/** 创建人ID */
createBy?: number;
/** 更新人ID */
updateBy?: number;
}
}
@@ -37,6 +37,15 @@ const routes: RouteRecordRaw[] = [
title: '订单管理',
},
},
{
name: 'PromotionFeeManagement',
path: '/shop/promotion-fee-management',
component: () => import('#/views/shop/promotion-fee-management/index.vue'),
meta: {
icon: 'lucide:credit-card',
title: '推广费管理',
},
},
{
name: 'ConfigManagement',
path: '/shop/config-management',
@@ -0,0 +1,375 @@
<template>
<Modal
v-model:open="visible"
:title="getModalTitle()"
width="600px"
:footer="null"
@cancel="handleCancel"
>
<div v-if="matchDetail" class="space-y-4">
<!-- 当前匹配状态 -->
<div class="flex items-center space-x-2 mb-4">
<div
class="w-4 h-4 rounded-full flex items-center justify-center"
:class="{
'bg-green-500': matchDetail.status === 'matched',
'bg-red-500': matchDetail.status === 'failed',
'bg-yellow-500': matchDetail.status === 'partial'
}"
>
<CheckIcon
v-if="matchDetail.status === 'matched'"
class="w-3 h-3 text-white"
/>
<XIcon
v-else-if="matchDetail.status === 'failed'"
class="w-3 h-3 text-white"
/>
<AlertTriangleIcon
v-else-if="matchDetail.status === 'partial'"
class="w-3 h-3 text-white"
/>
</div>
<span class="font-medium">
{{ getStatusText(matchDetail.status) }}
</span>
<span class="text-gray-500">第 {{ matchDetail.rowIndex }} 行</span>
</div>
<!-- 原始数据 -->
<div class="bg-gray-50 rounded-lg p-4">
<h4 class="font-medium text-gray-800 mb-3">原始数据</h4>
<div class="grid grid-cols-2 gap-3 text-sm">
<div>
<span class="text-gray-600">商品名称:</span>
<span class="ml-2 font-medium">{{ matchDetail.originalData.productName }}</span>
</div>
<div>
<span class="text-gray-600">订单编号:</span>
<span class="ml-2 font-medium">{{ matchDetail.originalData.orderNumber }}</span>
</div>
<div>
<span class="text-gray-600">商品规格:</span>
<span class="ml-2 font-medium">{{ matchDetail.originalData.productSpecName }}</span>
</div>
<div>
<span class="text-gray-600">规格编码:</span>
<span class="ml-2 font-medium">{{ matchDetail.originalData.specCode }}</span>
</div>
<div>
<span class="text-gray-600">店铺名称:</span>
<span class="ml-2 font-medium">{{ matchDetail.originalData.shopName }}</span>
</div>
<div>
<span class="text-gray-600">订单状态:</span>
<span class="ml-2 font-medium">{{ matchDetail.originalData.orderStatusName }}</span>
</div>
</div>
</div>
<!-- 当前字段匹配信息 -->
<div class="border rounded-lg p-4">
<div class="flex items-center justify-between mb-3">
<h4 class="font-medium text-gray-800">{{ getFieldTitle() }}</h4>
<div class="flex items-center space-x-2">
<div
class="w-3 h-3 rounded-full"
:class="getFieldMatchStatusClass()"
></div>
<span class="text-sm">
{{ getFieldMatchStatusText() }}
</span>
</div>
</div>
<!-- 当前匹配信息 -->
<div v-if="getCurrentMatchInfo()" class="bg-green-50 border border-green-200 rounded p-3 mb-3">
<div class="text-sm">
<div class="font-medium text-green-800">{{ getCurrentMatchInfo()?.name }}</div>
<div class="text-green-600">ID: {{ getCurrentMatchInfo()?.id }}</div>
<div v-if="getCurrentMatchInfo()?.specCode" class="text-green-600">
编码: {{ getCurrentMatchInfo()?.specCode }}
</div>
</div>
</div>
<!-- 未匹配信息 -->
<div v-else class="bg-red-50 border border-red-200 rounded p-3 mb-3">
<div class="text-sm text-red-700">
{{ getFieldName() }} "{{ getFieldValue() }}" 未找到匹配
</div>
</div>
<!-- 匹配选项下拉框 -->
<div class="space-y-3">
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">
选择匹配的{{ getFieldTitle() }}:
</label>
<Select
v-model:value="selectedMatchId"
placeholder="请选择匹配项"
style="width: 100%"
:options="getMatchOptions()"
@change="(value: any) => handleMatchChange(value)"
/>
</div>
<div v-if="selectedMatchId" class="bg-blue-50 border border-blue-200 rounded p-3">
<div class="text-sm">
<div class="font-medium text-blue-800">已选择匹配项</div>
<div class="text-blue-600">ID: {{ selectedMatchId }}</div>
</div>
</div>
</div>
</div>
<!-- 相同数据提示 -->
<div v-if="sameDataCount && sameDataCount > 1" class="bg-blue-50 border border-blue-200 rounded-lg p-3">
<div class="flex items-center space-x-2">
<InfoIcon class="w-4 h-4 text-blue-500" />
<span class="text-sm text-blue-800">
检测到 {{ sameDataCount }} 条相同数据,切换匹配将同时应用到所有相同数据
</span>
</div>
</div>
</div>
<template #footer>
<div class="flex justify-end space-x-2">
<Button @click="handleCancel">关闭</Button>
<Button
type="primary"
@click="handleApplyMatch"
:disabled="!selectedMatchId"
>
应用匹配
</Button>
<Button
v-if="sameDataCount && sameDataCount > 1"
type="primary"
@click="handleApplyToAll"
:disabled="!selectedMatchId"
>
应用到所有相同数据
</Button>
</div>
</template>
</Modal>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { Modal, Button, Select } from 'ant-design-vue'
import { createIconifyIcon } from '@vben/icons'
import type { MatchDetail } from '../services/EntityMatchingService'
// 创建图标组件
const CheckIcon = createIconifyIcon('lucide:check')
const XIcon = createIconifyIcon('lucide:x')
const AlertTriangleIcon = createIconifyIcon('lucide:alert-triangle')
const InfoIcon = createIconifyIcon('lucide:info')
interface Props {
visible: boolean
matchDetail: MatchDetail | null
fieldType: 'shop' | 'product' | 'spec' | 'orderStatus'
sameDataCount?: number
}
interface Emits {
(e: 'update:visible', value: boolean): void
(e: 'applyMatch', rowIndex: number, fieldType: string, matchId: string): void
(e: 'applyToAll', rowIndex: number, fieldType: string, matchId: string): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const visible = ref(false)
const selectedMatchId = ref<string>('')
watch(() => props.visible, (newVal) => {
visible.value = newVal
if (newVal && props.matchDetail) {
// 初始化选中的匹配项
selectedMatchId.value = getCurrentMatchId() || ''
}
})
watch(visible, (newVal) => {
emit('update:visible', newVal)
})
const getStatusText = (status: string) => {
switch (status) {
case 'matched':
return '匹配成功'
case 'failed':
return '匹配失败'
case 'partial':
return '部分匹配'
default:
return '未知状态'
}
}
// 获取模态框标题
const getModalTitle = () => {
const titles = {
shop: '店铺匹配切换',
product: '商品匹配切换',
spec: '规格匹配切换',
orderStatus: '订单状态匹配切换'
}
return titles[props.fieldType] || '匹配切换'
}
// 获取字段标题
const getFieldTitle = () => {
const titles = {
shop: '店铺',
product: '商品',
spec: '规格',
orderStatus: '订单状态'
}
return titles[props.fieldType] || '字段'
}
// 获取字段名称
const getFieldName = () => {
const names = {
shop: '店铺',
product: '商品',
spec: '规格',
orderStatus: '订单状态'
}
return names[props.fieldType] || '字段'
}
// 获取字段值
const getFieldValue = () => {
if (!props.matchDetail) return ''
switch (props.fieldType) {
case 'shop':
return props.matchDetail.originalData.shopName
case 'product':
return props.matchDetail.originalData.productName
case 'spec':
return props.matchDetail.originalData.productSpecName
case 'orderStatus':
return props.matchDetail.originalData.orderStatusName
default:
return ''
}
}
// 获取当前匹配信息
const getCurrentMatchInfo = () => {
if (!props.matchDetail) return null
switch (props.fieldType) {
case 'shop':
return props.matchDetail.matchedShop ? {
name: props.matchDetail.matchedShop.name,
id: props.matchDetail.matchedShop.id
} : null
case 'product':
return props.matchDetail.matchedProduct ? {
name: props.matchDetail.matchedProduct.name,
id: props.matchDetail.matchedProduct.id
} : null
case 'spec':
return props.matchDetail.matchedSpec ? {
name: props.matchDetail.matchedSpec.name,
id: props.matchDetail.matchedSpec.id,
specCode: props.matchDetail.matchedSpec.specCode
} : null
case 'orderStatus':
return props.matchDetail.matchedOrderStatusId ? {
name: props.matchDetail.originalData.orderStatusName,
id: props.matchDetail.matchedOrderStatusId
} : null
default:
return null
}
}
// 获取当前匹配ID
const getCurrentMatchId = () => {
const matchInfo = getCurrentMatchInfo()
return matchInfo?.id?.toString() || ''
}
// 获取字段匹配状态样式
const getFieldMatchStatusClass = () => {
const matchInfo = getCurrentMatchInfo()
return matchInfo ? 'bg-green-500' : 'bg-red-500'
}
// 获取字段匹配状态文本
const getFieldMatchStatusText = () => {
const matchInfo = getCurrentMatchInfo()
return matchInfo ? '已匹配' : '未匹配'
}
// 获取匹配选项(模拟数据,实际应该从API获取)
const getMatchOptions = () => {
// 这里应该根据fieldType从API获取可选的匹配项
// 暂时返回模拟数据
const mockOptions = {
shop: [
{ label: '锐泽创意家居', value: '123' },
{ label: '其他店铺1', value: '124' },
{ label: '其他店铺2', value: '125' }
],
product: [
{ label: '创意台灯', value: '456' },
{ label: '其他商品1', value: '457' },
{ label: '其他商品2', value: '458' }
],
spec: [
{ label: '白色', value: '789' },
{ label: '黑色', value: '790' },
{ label: '红色', value: '791' }
],
orderStatus: [
{ label: '已发货,待收货', value: '1' },
{ label: '未发货,退款成功', value: '2' },
{ label: '已取消', value: '3' }
]
}
return mockOptions[props.fieldType] || []
}
// 处理匹配选择变化
const handleMatchChange = (value: string) => {
selectedMatchId.value = value
}
// 处理应用匹配
const handleApplyMatch = () => {
if (props.matchDetail && selectedMatchId.value) {
emit('applyMatch', props.matchDetail.rowIndex, props.fieldType, selectedMatchId.value)
}
visible.value = false
}
// 处理应用到所有相同数据
const handleApplyToAll = () => {
if (props.matchDetail && selectedMatchId.value) {
emit('applyToAll', props.matchDetail.rowIndex, props.fieldType, selectedMatchId.value)
}
visible.value = false
}
const handleCancel = () => {
visible.value = false
}
</script>
<style scoped>
/* 自定义样式 */
</style>
@@ -103,6 +103,106 @@
</div>
</template>
<!-- 商品名称列 -->
<template #productName="{ row }: { row: any }">
<div class="flex items-center space-x-2">
<div
class="w-4 h-4 rounded-full flex items-center justify-center cursor-pointer"
:class="{
'bg-green-500': getProductMatchStatus(row) === 'matched',
'bg-red-500': getProductMatchStatus(row) === 'failed',
'bg-gray-300': getProductMatchStatus(row) === 'none'
}"
@click="showMatchModal(row, 'product')"
>
<CheckIcon
v-if="getProductMatchStatus(row) === 'matched'"
class="w-2.5 h-2.5 text-white"
/>
<XIcon
v-else-if="getProductMatchStatus(row) === 'failed'"
class="w-2.5 h-2.5 text-white"
/>
</div>
<span>{{ row.productName }}</span>
</div>
</template>
<!-- 订单状态列 -->
<template #orderStatusName="{ row }: { row: any }">
<div class="flex items-center space-x-2">
<div
class="w-4 h-4 rounded-full flex items-center justify-center cursor-pointer"
:class="{
'bg-green-500': getOrderStatusMatchStatus(row) === 'matched',
'bg-red-500': getOrderStatusMatchStatus(row) === 'failed',
'bg-gray-300': getOrderStatusMatchStatus(row) === 'none'
}"
@click="showMatchModal(row, 'orderStatus')"
>
<CheckIcon
v-if="getOrderStatusMatchStatus(row) === 'matched'"
class="w-2.5 h-2.5 text-white"
/>
<XIcon
v-else-if="getOrderStatusMatchStatus(row) === 'failed'"
class="w-2.5 h-2.5 text-white"
/>
</div>
<span>{{ row.orderStatusName }}</span>
</div>
</template>
<!-- 商品规格列 -->
<template #productSpecName="{ row }: { row: any }">
<div class="flex items-center space-x-2">
<div
class="w-4 h-4 rounded-full flex items-center justify-center cursor-pointer"
:class="{
'bg-green-500': getSpecMatchStatus(row) === 'matched',
'bg-red-500': getSpecMatchStatus(row) === 'failed',
'bg-gray-300': getSpecMatchStatus(row) === 'none'
}"
@click="showMatchModal(row, 'spec')"
>
<CheckIcon
v-if="getSpecMatchStatus(row) === 'matched'"
class="w-2.5 h-2.5 text-white"
/>
<XIcon
v-else-if="getSpecMatchStatus(row) === 'failed'"
class="w-2.5 h-2.5 text-white"
/>
</div>
<span>{{ row.productSpecName }}</span>
</div>
</template>
<!-- 店铺名称列 -->
<template #shopName="{ row }: { row: any }">
<div class="flex items-center space-x-2">
<div
class="w-4 h-4 rounded-full flex items-center justify-center cursor-pointer"
:class="{
'bg-green-500': getShopMatchStatus(row) === 'matched',
'bg-red-500': getShopMatchStatus(row) === 'failed',
'bg-gray-300': getShopMatchStatus(row) === 'none'
}"
@click="showMatchModal(row, 'shop')"
>
<CheckIcon
v-if="getShopMatchStatus(row) === 'matched'"
class="w-2.5 h-2.5 text-white"
/>
<XIcon
v-else-if="getShopMatchStatus(row) === 'failed'"
class="w-2.5 h-2.5 text-white"
/>
</div>
<span>{{ row.shopName }}</span>
</div>
</template>
<!-- 实收金额列 -->
<template #receivedAmount="{ row }: { row: any }">
<span style="color: #52c41a; font-weight: bold;">
@@ -152,6 +252,16 @@
@success="handleEntityCreationSuccess"
@cancel="handleEntityCreationCancel"
/>
<!-- 匹配切换模态框 -->
<MatchSwitchModal
v-model:visible="showMatchSwitchModal"
:match-detail="currentMatchDetail"
:field-type="currentFieldType"
:same-data-count="getSameDataCount(currentRowData)"
@apply-match="handleApplyMatch"
@apply-to-all="handleApplyToAll"
/>
</Page>
</template>
@@ -166,7 +276,8 @@ import FieldMapping from '#/views/ecommerce/data-import/components/FieldMapping.
import FileUploadArea from './components/FileUploadArea.vue'
import FileUploadModal from './components/FileUploadModal.vue'
import EntityCreationModal from './components/EntityCreationModal.vue'
import { EntityMatchingService, type EntityMatchingResult } from './services/EntityMatchingService'
import MatchSwitchModal from './components/MatchSwitchModal.vue'
import { EntityMatchingService, type EntityMatchingResult, type MatchDetail } from './services/EntityMatchingService'
import { batchImportOrdersApi } from '#/api/ecommerce'
import { parseOrderCSV, extractShopNameFromFilename, convertToCSVOrderData } from './utils/csvParser'
import { useVbenVxeGrid } from '#/adapter/vxe-table'
@@ -175,6 +286,8 @@ import type { VxeGridProps } from '#/adapter/vxe-table'
// 创建图标组件
const UploadIcon = createIconifyIcon('lucide:upload')
const CheckCircleIcon = createIconifyIcon('lucide:check-circle')
const CheckIcon = createIconifyIcon('lucide:check')
const XIcon = createIconifyIcon('lucide:x')
// 响应式数据
const uploadedFile = ref<File | null>(null)
@@ -191,6 +304,12 @@ const showEntityCreationModal = ref(false)
const importLoading = ref(false)
const importProgress = ref(0)
// 匹配切换相关
const showMatchSwitchModal = ref(false)
const currentMatchDetail = ref<MatchDetail | null>(null)
const currentRowData = ref<any>(null)
const currentFieldType = ref<'shop' | 'product' | 'spec' | 'orderStatus'>('shop')
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
@@ -209,6 +328,7 @@ const gridOptions: VxeGridProps<any> = {
title: '商品名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
slots: { default: 'productName' },
},
{
field: 'orderNumber',
@@ -220,6 +340,7 @@ const gridOptions: VxeGridProps<any> = {
field: 'orderStatusName',
title: '订单状态',
minWidth: 'auto',
slots: { default: 'orderStatusName' },
},
{
field: 'quantity',
@@ -237,6 +358,7 @@ const gridOptions: VxeGridProps<any> = {
title: '商品规格',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
slots: { default: 'productSpecName' },
},
{
field: 'specCode',
@@ -249,6 +371,7 @@ const gridOptions: VxeGridProps<any> = {
title: '店铺名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
slots: { default: 'shopName' },
},
{
field: 'afterSaleStatus',
@@ -490,6 +613,100 @@ const handleMatchRow = (row: any) => {
message.info('匹配功能待实现')
}
// 获取匹配详情
const getMatchDetail = (row: any) => {
if (!matchingResult.value) return null
return matchingResult.value.matchDetails.find(
detail => detail.originalData.orderNumber === row.orderNumber &&
detail.originalData.productName === row.productName
)
}
// 店铺匹配状态
const getShopMatchStatus = (row: any): 'matched' | 'failed' | 'none' => {
const matchDetail = getMatchDetail(row)
if (!matchDetail) return 'none'
if (matchDetail.matchedShop) return 'matched'
if (matchDetail.status === 'failed' && !matchDetail.matchedShop) return 'failed'
return 'none'
}
// 商品匹配状态
const getProductMatchStatus = (row: any): 'matched' | 'failed' | 'none' => {
const matchDetail = getMatchDetail(row)
if (!matchDetail) return 'none'
if (matchDetail.matchedProduct) return 'matched'
if (matchDetail.status === 'failed' && !matchDetail.matchedProduct) return 'failed'
return 'none'
}
// 规格匹配状态
const getSpecMatchStatus = (row: any): 'matched' | 'failed' | 'none' => {
const matchDetail = getMatchDetail(row)
if (!matchDetail) return 'none'
if (matchDetail.matchedSpec) return 'matched'
if (matchDetail.status === 'failed' && !matchDetail.matchedSpec) return 'failed'
return 'none'
}
// 订单状态匹配状态
const getOrderStatusMatchStatus = (row: any): 'matched' | 'failed' | 'none' => {
const matchDetail = getMatchDetail(row)
if (!matchDetail) return 'none'
if (matchDetail.matchedOrderStatusId) return 'matched'
if (matchDetail.status === 'failed' && !matchDetail.matchedOrderStatusId) return 'failed'
return 'none'
}
// 显示匹配模态框
const showMatchModal = (row: any, fieldType: 'shop' | 'product' | 'spec' | 'orderStatus') => {
const matchDetail = getMatchDetail(row)
if (matchDetail) {
currentMatchDetail.value = matchDetail
currentRowData.value = row
currentFieldType.value = fieldType
showMatchSwitchModal.value = true
} else {
message.warning('未找到该行的匹配信息')
}
}
// 获取相同数据的数量
const getSameDataCount = (row: any) => {
if (!row || !matchingResult.value) return 1
return matchingResult.value.matchDetails.filter(detail =>
detail.originalData.productName === row.productName &&
detail.originalData.orderNumber === row.orderNumber
).length
}
// 处理应用匹配
const handleApplyMatch = (rowIndex: number, fieldType: string, matchId: string) => {
message.success(`已应用${fieldType}匹配 - 行 ${rowIndex}, 匹配ID: ${matchId}`)
// 这里可以实现具体的匹配应用逻辑
// 1. 更新匹配详情
// 2. 重新计算匹配状态
// 3. 更新表格显示
}
// 处理应用到所有相同数据
const handleApplyToAll = (rowIndex: number, fieldType: string, matchId: string) => {
message.success(`已应用${fieldType}匹配到所有相同数据 - 行 ${rowIndex}, 匹配ID: ${matchId}`)
// 这里可以实现应用到所有相同数据的逻辑
// 1. 找到所有相同的数据行
// 2. 批量更新匹配详情
// 3. 重新计算匹配状态
// 4. 更新表格显示
}
// 格式化文件大小
const formatFileSize = (bytes: number) => {
if (bytes === 0) return '0 Bytes'
@@ -22,6 +22,29 @@ export interface EntityMatchingResult {
products: string[];
specs: { productName: string; specCode: string }[];
};
/** 匹配详情信息 */
matchDetails: MatchDetail[];
}
export interface MatchDetail {
/** 行索引 */
rowIndex: number;
/** 原始数据 */
originalData: CSVOrderData;
/** 匹配状态 */
status: 'matched' | 'failed' | 'partial';
/** 匹配的店铺信息 */
matchedShop?: ShopVO.Info;
/** 匹配的商品信息 */
matchedProduct?: ProductVO.Info;
/** 匹配的规格信息 */
matchedSpec?: ProductVO.SpecInfo;
/** 匹配的订单状态ID */
matchedOrderStatusId?: number;
/** 失败原因 */
failureReason?: string;
/** 生成的订单数据(如果匹配成功) */
orderData?: OrderDTO.Create;
}
export interface FailedRecord {
@@ -101,6 +124,7 @@ export class EntityMatchingService {
const matchedOrders: OrderDTO.Create[] = [];
const failedRecords: FailedRecord[] = [];
const matchDetails: MatchDetail[] = [];
const entitiesToCreate = {
shops: new Set<string>(),
products: new Set<string>(),
@@ -112,10 +136,17 @@ export class EntityMatchingService {
// 检查行数据是否存在
if (!row) {
failedRecords.push({
const failedRecord = {
rowIndex: i + 1,
originalData: null,
reason: '行数据为空'
};
failedRecords.push(failedRecord);
matchDetails.push({
rowIndex: i + 1,
originalData: row || {} as CSVOrderData,
status: 'failed',
failureReason: '行数据为空'
});
continue;
}
@@ -125,10 +156,17 @@ export class EntityMatchingService {
const shop = this.shopCache.get(row.shopName);
if (!shop) {
entitiesToCreate.shops.add(row.shopName);
failedRecords.push({
const failedRecord = {
rowIndex: i + 1,
originalData: row,
reason: `店铺 "${row.shopName}" 不存在`
};
failedRecords.push(failedRecord);
matchDetails.push({
rowIndex: i + 1,
originalData: row,
status: 'failed',
failureReason: `店铺 "${row.shopName}" 不存在`
});
continue;
}
@@ -137,10 +175,18 @@ export class EntityMatchingService {
const product = this.productCache.get(row.productName);
if (!product) {
entitiesToCreate.products.add(row.productName);
failedRecords.push({
const failedRecord = {
rowIndex: i + 1,
originalData: row,
reason: `商品 "${row.productName}" 不存在`
};
failedRecords.push(failedRecord);
matchDetails.push({
rowIndex: i + 1,
originalData: row,
status: 'failed',
matchedShop: shop,
failureReason: `商品 "${row.productName}" 不存在`
});
continue;
}
@@ -150,10 +196,19 @@ export class EntityMatchingService {
const spec = this.specCache.get(specKey);
if (!spec) {
entitiesToCreate.specs.add({ productName: row.productName, specCode: row.specCode });
failedRecords.push({
const failedRecord = {
rowIndex: i + 1,
originalData: row,
reason: `商品规格 "${row.productName}" - "${row.specCode}" 不存在`
};
failedRecords.push(failedRecord);
matchDetails.push({
rowIndex: i + 1,
originalData: row,
status: 'failed',
matchedShop: shop,
matchedProduct: product,
failureReason: `商品规格 "${row.productName}" - "${row.specCode}" 不存在`
});
continue;
}
@@ -161,10 +216,20 @@ export class EntityMatchingService {
// 匹配订单状态
const orderStatusId = this.orderStatusMap.get(row.orderStatusName);
if (!orderStatusId) {
failedRecords.push({
const failedRecord = {
rowIndex: i + 1,
originalData: row,
reason: `订单状态 "${row.orderStatusName}" 不存在`
};
failedRecords.push(failedRecord);
matchDetails.push({
rowIndex: i + 1,
originalData: row,
status: 'failed',
matchedShop: shop,
matchedProduct: product,
matchedSpec: spec,
failureReason: `订单状态 "${row.orderStatusName}" 不存在`
});
continue;
}
@@ -202,11 +267,30 @@ export class EntityMatchingService {
};
matchedOrders.push(orderData);
// 添加匹配成功的详情
matchDetails.push({
rowIndex: i + 1,
originalData: row,
status: 'matched',
matchedShop: shop,
matchedProduct: product,
matchedSpec: spec,
matchedOrderStatusId: orderStatusId,
orderData: orderData
});
} catch (error) {
failedRecords.push({
const failedRecord = {
rowIndex: i + 1,
originalData: row,
reason: `处理失败: ${error instanceof Error ? error.message : '未知错误'}`
};
failedRecords.push(failedRecord);
matchDetails.push({
rowIndex: i + 1,
originalData: row,
status: 'failed',
failureReason: `处理失败: ${error instanceof Error ? error.message : '未知错误'}`
});
}
}
@@ -218,7 +302,8 @@ export class EntityMatchingService {
shops: Array.from(entitiesToCreate.shops),
products: Array.from(entitiesToCreate.products),
specs: Array.from(entitiesToCreate.specs)
}
},
matchDetails
};
}
@@ -0,0 +1,354 @@
<template>
<Modal
v-model:open="visible"
:title="isEdit ? '编辑推广费记录' : '新增推广费记录'"
width="800px"
@ok="handleOk"
@cancel="handleCancel"
>
<Form
ref="formRef"
:model="formData"
:rules="rules"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 18 }"
>
<Form.Item label="店铺" name="shopId">
<Select
v-model:value="formData.shopId"
placeholder="请选择店铺"
:loading="shopListLoading"
>
<Select.Option
v-for="shop in shopList"
:key="shop.id"
:value="shop.id"
>
{{ shop.name }}
</Select.Option>
</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="feeName">
<Input
v-model:value="formData.feeName"
placeholder="请输入推广费名称"
/>
</Form.Item>
<Form.Item label="平台" name="platform">
<Select
v-model:value="formData.platform"
placeholder="请选择平台"
allow-clear
>
<Select.Option
v-for="option in platformOptions"
:key="option.value"
:value="option.value"
>
{{ option.label }}
</Select.Option>
</Select>
</Form.Item>
<Form.Item label="推广活动名称" name="campaignName">
<Input
v-model:value="formData.campaignName"
placeholder="请输入推广活动名称"
/>
</Form.Item>
<Form.Item label="推广费金额" name="feeAmount">
<InputNumber
v-model:value="formData.feeAmount"
placeholder="请输入推广费金额"
:min="0"
:precision="2"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="基础金额" name="baseAmount">
<InputNumber
v-model:value="formData.baseAmount"
placeholder="请输入基础金额(用于按比例计算)"
:min="0"
:precision="2"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="费率" name="feeRate">
<InputNumber
v-model:value="formData.feeRate"
placeholder="请输入费率(用于按比例计算)"
:min="0"
:max="1"
:precision="4"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="点击次数" name="clickCount">
<InputNumber
v-model:value="formData.clickCount"
placeholder="请输入点击次数"
:min="0"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="展示次数" name="impressionCount">
<InputNumber
v-model:value="formData.impressionCount"
placeholder="请输入展示次数"
:min="0"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="转化次数" name="conversionCount">
<InputNumber
v-model:value="formData.conversionCount"
placeholder="请输入转化次数"
:min="0"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="发生日期" name="feeDate">
<DatePicker
v-model:value="formData.feeDate"
placeholder="请选择推广费发生日期"
style="width: 100%"
/>
</Form.Item>
<Form.Item label="备注" name="remark">
<Input.TextArea
v-model:value="formData.remark"
placeholder="请输入备注"
:rows="3"
/>
</Form.Item>
</Form>
</Modal>
</template>
<script setup lang="ts">
import { ref, watch, onMounted } from 'vue';
import { Modal, Form, Input, Select, InputNumber, DatePicker, message } from 'ant-design-vue';
import { createPromotionFeeApi, updatePromotionFeeApi } from '#/api/shop';
import { getShopPageApi } from '#/api/shop';
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce';
import type { PromotionFeeDTO, PromotionFeeVO, ShopVO } from '#/api/shop/types';
import type { PromotionFeeTypeVO } from '#/api/ecommerce/types';
defineOptions({ name: 'PromotionFeeFormModal' });
// Props
interface Props {
open: boolean;
promotionFeeData?: PromotionFeeVO.Info | null;
}
// Emits
interface Emits {
(e: 'update:open', value: boolean): void;
(e: 'success'): void;
(e: 'cancel'): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
// 响应式数据
const visible = ref(false);
const formRef = ref();
const isEdit = ref(false);
// 表单数据
const formData = ref<PromotionFeeDTO.Create>({
shopId: undefined as any,
feeTypeId: undefined as any,
feeName: '',
platform: undefined,
campaignName: '',
feeAmount: undefined as any,
baseAmount: undefined,
feeRate: undefined,
clickCount: undefined,
impressionCount: undefined,
conversionCount: undefined,
feeDate: undefined as any,
remark: '',
});
// 表单验证规则
const rules = {
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
feeTypeId: [{ required: true, message: '请选择推广费类型', trigger: 'change' }],
feeName: [{ required: true, message: '请输入推广费名称', trigger: 'blur' }],
feeAmount: [{ required: true, message: '请输入推广费金额', trigger: 'blur' }],
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 shopList = ref<ShopVO.Info[]>([]);
const shopListLoading = ref(false);
// 推广费类型列表
const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
const feeTypeListLoading = ref(false);
// 监听props变化
watch(() => props.open, (newVal) => {
visible.value = newVal;
if (newVal) {
isEdit.value = !!props.promotionFeeData;
if (props.promotionFeeData) {
// 编辑模式,填充表单数据
formData.value = {
shopId: props.promotionFeeData.shopId,
feeTypeId: props.promotionFeeData.feeTypeId,
feeName: props.promotionFeeData.feeName,
platform: props.promotionFeeData.platform,
campaignName: props.promotionFeeData.campaignName || '',
feeAmount: props.promotionFeeData.feeAmount,
baseAmount: props.promotionFeeData.baseAmount,
feeRate: props.promotionFeeData.feeRate,
clickCount: props.promotionFeeData.clickCount,
impressionCount: props.promotionFeeData.impressionCount,
conversionCount: props.promotionFeeData.conversionCount,
feeDate: props.promotionFeeData.feeDate,
remark: props.promotionFeeData.remark || '',
};
} else {
// 新增模式,重置表单数据
resetFormData();
}
}
});
// 监听visible变化,同步到父组件
watch(visible, (newVal) => {
emit('update:open', newVal);
});
// 加载店铺列表
const loadShopList = async () => {
shopListLoading.value = true;
try {
const response = await getShopPageApi({
page: 1,
pageSize: 1000,
filters: {},
});
shopList.value = response.records;
} catch (error) {
console.error('加载店铺列表失败:', error);
} finally {
shopListLoading.value = false;
}
};
// 加载推广费类型列表
const loadFeeTypeList = async () => {
feeTypeListLoading.value = true;
try {
const response = await getActivePromotionFeeTypeListApi();
feeTypeList.value = response;
} catch (error) {
console.error('加载推广费类型列表失败:', error);
} finally {
feeTypeListLoading.value = false;
}
};
// 重置表单数据
const resetFormData = () => {
formData.value = {
shopId: undefined as any,
feeTypeId: undefined as any,
feeName: '',
platform: undefined,
campaignName: '',
feeAmount: undefined as any,
baseAmount: undefined,
feeRate: undefined,
clickCount: undefined,
impressionCount: undefined,
conversionCount: undefined,
feeDate: undefined as any,
remark: '',
};
};
// 确认操作
const handleOk = async () => {
try {
await formRef.value?.validate();
if (isEdit.value && props.promotionFeeData) {
// 更新推广费记录
const updateData: PromotionFeeDTO.Update = {
id: props.promotionFeeData.id,
...formData.value,
};
await updatePromotionFeeApi(updateData);
message.success('更新成功');
} else {
// 创建推广费记录
await createPromotionFeeApi(formData.value);
message.success('创建成功');
}
emit('success');
visible.value = false;
} catch (error) {
console.error('操作失败:', error);
message.error(isEdit.value ? '更新失败' : '创建失败');
}
};
// 取消操作
const handleCancel = () => {
emit('cancel');
visible.value = false;
resetFormData();
};
// 组件挂载时加载数据
onMounted(() => {
loadShopList();
loadFeeTypeList();
});
</script>
@@ -0,0 +1,345 @@
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, message, Space, Tag } from 'ant-design-vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {
getPromotionFeePageApi,
deletePromotionFeeApi,
} from '#/api/shop';
import type { PromotionFeeVO, PromotionFeeDTO } from '#/api/shop/types';
import type { PageQueryDTO } from '#/types/common';
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
// 创建图标组件
const PlusIcon = createIconifyIcon('lucide:plus');
defineOptions({ name: 'PromotionFeeManagement' });
// 响应式数据
const loading = ref(false);
const formModalVisible = ref(false);
const currentPromotionFeeData = ref<PromotionFeeVO.Info | null>(null);
// 搜索表单
const searchForm = ref({
shopId: undefined as number | undefined,
feeTypeId: undefined as number | undefined,
platform: '',
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: '其他' },
];
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [
{
type: 'seq' as const,
minWidth: 'auto',
title: '序号',
},
{
field: 'feeName',
title: '推广费名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'shopName',
title: '店铺名称',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
field: 'feeTypeName',
title: '推广费类型',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
title: '平台',
minWidth: 'auto',
slots: { default: 'platform' },
},
{
field: 'campaignName',
title: '推广活动',
minWidth: 'auto',
showOverflow: 'tooltip' as const,
},
{
title: '推广费金额',
minWidth: 'auto',
slots: { default: 'feeAmount' },
},
{
field: 'feeDate',
title: '发生日期',
minWidth: 'auto',
},
{
title: '操作',
minWidth: 'auto',
fixed: 'right' as const,
slots: { default: 'action' },
},
],
height: 'auto',
border: true,
stripe: true,
showOverflow: true,
size: 'small',
toolbarConfig: {
custom: true,
refresh: true,
zoom: true,
},
data: [],
pagerConfig: {
enabled: true,
pageSizes: [10, 20, 50, 100],
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
},
// 配置远程加载
proxyConfig: {
ajax: {
query: async ({ page }) => {
try {
loading.value = true;
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: searchForm.value.shopId || undefined,
feeTypeId: searchForm.value.feeTypeId || undefined,
platform: searchForm.value.platform || undefined,
feeDateStart: searchForm.value.feeDateStart || undefined,
feeDateEnd: searchForm.value.feeDateEnd || undefined,
},
};
const data = await getPromotionFeePageApi(params);
return {
items: data.records,
total: data.total,
};
} catch (error) {
console.error('获取推广费记录列表失败:', error);
message.error('获取推广费记录列表失败');
return {
items: [],
total: 0,
};
} finally {
loading.value = false;
}
},
},
},
};
// 搜索表单配置
const formOptions = computed(() => ({
schema: [
{
component: 'Select',
componentProps: {
placeholder: '请选择店铺',
// TODO: 这里需要从店铺API获取店铺列表
options: [],
allowClear: true,
},
fieldName: 'shopId',
label: '店铺',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择推广费类型',
// TODO: 这里需要从推广费类型API获取类型列表
options: [],
allowClear: true,
},
fieldName: 'feeTypeId',
label: '推广费类型',
},
{
component: 'Select',
componentProps: {
placeholder: '请选择平台',
options: platformOptions,
allowClear: true,
},
fieldName: 'platform',
label: '平台',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '开始日期',
style: { width: '100%' },
},
fieldName: 'feeDateStart',
label: '发生日期',
},
{
component: 'DatePicker',
componentProps: {
placeholder: '结束日期',
style: { width: '100%' },
},
fieldName: 'feeDateEnd',
label: '至',
},
],
showDefaultActions: true,
collapsed: true,
collapsedRows: 1,
}));
// 刷新表格数据
function refreshTable() {
if (gridApi) {
gridApi.reload();
}
}
// 创建 VbenVxeGrid 实例
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
formOptions: formOptions.value,
showSearchForm: true,
tableTitle: '推广费管理',
});
// 处理新增
const handleAdd = () => {
currentPromotionFeeData.value = null;
formModalVisible.value = true;
};
// 处理编辑
const handleEdit = (record: PromotionFeeVO.Info) => {
currentPromotionFeeData.value = record;
formModalVisible.value = true;
};
// 处理删除
const handleDelete = async (id: number) => {
try {
await deletePromotionFeeApi(id);
message.success('删除成功');
refreshTable();
} catch (error) {
message.error('删除失败');
}
};
// 处理表单成功
const handleFormSuccess = () => {
refreshTable();
};
// 格式化金额
const formatAmount = (amount: number) => {
return `¥${amount.toFixed(2)}`;
};
// 获取平台标签颜色
const getPlatformColor = (platform: string | undefined) => {
switch (platform) {
case '淘宝':
return 'orange';
case '京东':
return 'red';
case '拼多多':
return 'green';
case '天猫':
return 'purple';
case '抖音':
return 'blue';
case '快手':
return 'cyan';
default:
return 'default';
}
};
</script>
<template>
<Page title="推广费管理" auto-content-height>
<template #description>
<div class="text-foreground/80 mt-2">
管理店铺推广费用记录,支持按店铺、类型、平台等维度查询和统计
</div>
</template>
<template #extra>
<Space>
<Button type="primary" @click="handleAdd">
<PlusIcon class="w-4 h-4 mr-2" />
新增推广费记录
</Button>
</Space>
</template>
<!-- 数据表格 -->
<Grid :loading="loading">
<!-- 工具栏工具 -->
<template #toolbar-tools>
<Space>
<span class="text-gray-500">支持按店铺、类型、平台等维度查询推广费记录</span>
</Space>
</template>
<!-- 平台列 -->
<template #platform="{ row }: { row: any }">
<Tag v-if="row.platform" :color="getPlatformColor(row.platform)">
{{ row.platform }}
</Tag>
<span v-else class="text-gray-400">-</span>
</template>
<!-- 推广费金额列 -->
<template #feeAmount="{ row }: { row: any }">
<span class="font-medium text-red-600">
{{ formatAmount(row.feeAmount) }}
</span>
</template>
<!-- 操作列 -->
<template #action="{ row }: { row: any }">
<Space>
<Button size="small" @click="handleEdit(row)">
编辑
</Button>
<Button size="small" danger @click="handleDelete(row.id)">
删除
</Button>
</Space>
</template>
</Grid>
<!-- 表单弹窗 -->
<PromotionFeeFormModal
v-model:open="formModalVisible"
:promotion-fee-data="currentPromotionFeeData"
@success="handleFormSuccess"
@cancel="formModalVisible = false"
/>
</Page>
</template>