mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 20:29:19 +08:00
修复类型报错
This commit is contained in:
+375
@@ -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'
|
||||
|
||||
+92
-7
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user