mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
1
This commit is contained in:
+514
-51
@@ -5,6 +5,7 @@ import type {
|
||||
ImportMappingVO,
|
||||
} from '#/api/ecommerce/import-mapping';
|
||||
import type { ImportTaskDTO } from '#/api/ecommerce/import-task';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
@@ -25,8 +26,11 @@ import { getFieldDefsByTypeApi } from '#/api/ecommerce/import-field-def';
|
||||
import {
|
||||
createImportMappingApi,
|
||||
getImportMappingPageApi,
|
||||
ImportMappingType,
|
||||
updateImportMappingApi,
|
||||
} from '#/api/ecommerce/import-mapping';
|
||||
import { createImportTaskApi } from '#/api/ecommerce/import-task';
|
||||
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
import { uploadFileApi } from '#/api/media/file';
|
||||
import { useImportTaskStore } from '#/store';
|
||||
@@ -43,6 +47,14 @@ interface FieldMappingItem {
|
||||
required: boolean;
|
||||
}
|
||||
|
||||
// 定义订单状态映射项数据结构
|
||||
interface StatusMappingItem {
|
||||
/** CSV中的订单状态值 */
|
||||
csvStatus: string;
|
||||
/** 映射到的订单状态ID */
|
||||
mappedStatusId: number;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'CreateImportTaskModal' });
|
||||
|
||||
// 创建 vben modal
|
||||
@@ -60,6 +72,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
const currentStep = ref(0);
|
||||
const loading = ref(false);
|
||||
const csvHeaders = ref<string[]>([]);
|
||||
const csvData = ref<any[]>([]);
|
||||
const selectedFile = ref<File | null>(null);
|
||||
|
||||
// 第一步:店铺选择
|
||||
@@ -90,6 +103,18 @@ const templateLoading = ref(false);
|
||||
const savingTemplate = ref(false);
|
||||
const templateName = ref('');
|
||||
|
||||
// 第三步:订单状态映射
|
||||
const statusMappings = ref<Record<string, number>>({});
|
||||
const uniqueStatusValues = ref<string[]>([]);
|
||||
const statusMappingTemplates = ref<ImportMappingVO.ImportMappingInfoVO[]>([]);
|
||||
const selectedStatusTemplateId = ref<number | undefined>();
|
||||
const statusTemplateLoading = ref(false);
|
||||
const savingStatusTemplate = ref(false);
|
||||
const statusTemplateName = ref('');
|
||||
// 订单状态列表
|
||||
const orderStatusList = ref<OrderStatusVO.Info[]>([]);
|
||||
const orderStatusLoading = ref(false);
|
||||
|
||||
// 创建保存模板的 vben modal
|
||||
const [SaveTemplateModal, saveTemplateModalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
@@ -106,8 +131,21 @@ const [SaveTemplateModal, saveTemplateModalApi] = useVbenModal({
|
||||
},
|
||||
});
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
// 创建保存订单状态映射模板的 vben modal
|
||||
const [SaveStatusTemplateModal, saveStatusTemplateModalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
title: '保存订单状态映射模板',
|
||||
showCancelButton: true,
|
||||
showConfirmButton: true,
|
||||
confirmText: '保存',
|
||||
cancelText: '取消',
|
||||
onConfirm: handleConfirmSaveStatusTemplate,
|
||||
onCancel() {
|
||||
statusTemplateName.value = '';
|
||||
saveStatusTemplateModalApi.close();
|
||||
},
|
||||
});
|
||||
|
||||
// 导入任务store
|
||||
const importTaskStore = useImportTaskStore();
|
||||
@@ -124,6 +162,12 @@ const canGoToNextStep = computed(() => {
|
||||
return mapping && mapping.mappedHeader;
|
||||
});
|
||||
}
|
||||
if (currentStep.value === 2) {
|
||||
// 订单状态映射步骤:所有唯一的订单状态值都必须映射
|
||||
return uniqueStatusValues.value.every(
|
||||
(status) => statusMappings.value[status] !== undefined,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -230,10 +274,19 @@ const fetchMappingTemplates = async () => {
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
filters: {
|
||||
type: 'order',
|
||||
type: ImportMappingType.ORDER,
|
||||
},
|
||||
});
|
||||
mappingTemplates.value = result.records || [];
|
||||
|
||||
// 修复:自动选择第一个模板并应用
|
||||
if (mappingTemplates.value.length > 0 && !selectedTemplateId.value) {
|
||||
const firstTemplate = mappingTemplates.value[0];
|
||||
if (firstTemplate?.id) {
|
||||
selectedTemplateId.value = firstTemplate.id;
|
||||
await handleSelectTemplate(firstTemplate.id);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取映射模板列表失败:', error);
|
||||
message.error('获取映射模板列表失败');
|
||||
@@ -242,10 +295,62 @@ const fetchMappingTemplates = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 获取订单状态列表
|
||||
const fetchOrderStatusList = async () => {
|
||||
if (orderStatusLoading.value) return;
|
||||
|
||||
try {
|
||||
orderStatusLoading.value = true;
|
||||
const result = await getAllOrderStatusListApi();
|
||||
orderStatusList.value = result || [];
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
message.error('获取订单状态列表失败');
|
||||
} finally {
|
||||
orderStatusLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取订单状态映射模板列表
|
||||
const fetchStatusMappingTemplates = async () => {
|
||||
try {
|
||||
statusTemplateLoading.value = true;
|
||||
const result = await getImportMappingPageApi({
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
filters: {
|
||||
type: ImportMappingType.ORDER_STATUS,
|
||||
},
|
||||
});
|
||||
statusMappingTemplates.value = result.records || [];
|
||||
|
||||
// 修复:自动选择第一个模板并应用
|
||||
if (
|
||||
statusMappingTemplates.value.length > 0 &&
|
||||
!selectedStatusTemplateId.value
|
||||
) {
|
||||
const firstTemplate = statusMappingTemplates.value[0];
|
||||
if (firstTemplate?.id) {
|
||||
selectedStatusTemplateId.value = firstTemplate.id;
|
||||
await handleSelectStatusTemplate(firstTemplate.id);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取订单状态映射模板列表失败:', error);
|
||||
message.error('获取订单状态映射模板列表失败');
|
||||
} finally {
|
||||
statusTemplateLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 选择映射模板
|
||||
const handleSelectTemplate = async (value: any) => {
|
||||
const templateId = typeof value === 'number' ? value : undefined;
|
||||
if (!templateId) {
|
||||
// 如果清空选择,重置映射
|
||||
if (fieldDefs.value.length > 0) {
|
||||
initFieldMappings();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -290,7 +395,43 @@ const handleSelectTemplate = async (value: any) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 打开保存模板模态框
|
||||
// 选择订单状态映射模板
|
||||
const handleSelectStatusTemplate = async (value: any) => {
|
||||
const templateId = typeof value === 'number' ? value : undefined;
|
||||
if (!templateId) {
|
||||
// 如果清空选择,重置映射
|
||||
statusMappings.value = {};
|
||||
return;
|
||||
}
|
||||
|
||||
const template = statusMappingTemplates.value.find(
|
||||
(t) => t.id === templateId,
|
||||
);
|
||||
if (!template) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 解析模板的 mapping JSON
|
||||
const mappingItems: StatusMappingItem[] = JSON.parse(template.mapping);
|
||||
|
||||
// 根据模板填充订单状态映射
|
||||
const mappings: typeof statusMappings.value = {};
|
||||
mappingItems.forEach((item) => {
|
||||
if (uniqueStatusValues.value.includes(item.csvStatus)) {
|
||||
mappings[item.csvStatus] = item.mappedStatusId;
|
||||
}
|
||||
});
|
||||
|
||||
statusMappings.value = mappings;
|
||||
message.success('已应用订单状态映射模板');
|
||||
} catch (error) {
|
||||
console.error('应用订单状态映射模板失败:', error);
|
||||
message.error('应用订单状态映射模板失败,模板格式可能不正确');
|
||||
}
|
||||
};
|
||||
|
||||
// 打开保存/更新模板模态框
|
||||
const handleSaveTemplate = () => {
|
||||
// 验证是否有映射数据
|
||||
const mappingItems: FieldMappingItem[] = Object.values(fieldMappings.value)
|
||||
@@ -307,11 +448,46 @@ const handleSaveTemplate = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
templateName.value = '';
|
||||
// 如果选择了模板,使用模板名称;否则清空
|
||||
if (selectedTemplateId.value) {
|
||||
const template = mappingTemplates.value.find(
|
||||
(t) => t.id === selectedTemplateId.value,
|
||||
);
|
||||
templateName.value = template?.name || '';
|
||||
} else {
|
||||
templateName.value = '';
|
||||
}
|
||||
saveTemplateModalApi.open();
|
||||
};
|
||||
|
||||
// 确认保存映射模板
|
||||
// 打开保存/更新订单状态映射模板模态框
|
||||
const handleSaveStatusTemplate = () => {
|
||||
// 验证是否有映射数据
|
||||
const mappingItems: StatusMappingItem[] = uniqueStatusValues.value
|
||||
.filter((status) => statusMappings.value[status] !== undefined)
|
||||
.map((status) => ({
|
||||
csvStatus: status,
|
||||
mappedStatusId: statusMappings.value[status]!,
|
||||
}));
|
||||
|
||||
if (mappingItems.length === 0) {
|
||||
message.warning('请先完成订单状态映射');
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果选择了模板,使用模板名称;否则清空
|
||||
if (selectedStatusTemplateId.value) {
|
||||
const template = statusMappingTemplates.value.find(
|
||||
(t) => t.id === selectedStatusTemplateId.value,
|
||||
);
|
||||
statusTemplateName.value = template?.name || '';
|
||||
} else {
|
||||
statusTemplateName.value = '';
|
||||
}
|
||||
saveStatusTemplateModalApi.open();
|
||||
};
|
||||
|
||||
// 确认保存/更新映射模板
|
||||
async function handleConfirmSaveTemplate() {
|
||||
if (!templateName.value.trim()) {
|
||||
message.warning('请输入模板名称');
|
||||
@@ -346,58 +522,209 @@ async function handleConfirmSaveTemplate() {
|
||||
required: m.fieldDef.required,
|
||||
}));
|
||||
|
||||
const createData: ImportMappingDTO.CreateImportMappingDTO = {
|
||||
type: 'order',
|
||||
name: templateName.value.trim(),
|
||||
mapping: JSON.stringify(mappingItems),
|
||||
};
|
||||
const mappingJson = JSON.stringify(mappingItems);
|
||||
|
||||
// 如果选择了模板,则更新;否则创建
|
||||
if (selectedTemplateId.value) {
|
||||
await updateImportMappingApi(selectedTemplateId.value, {
|
||||
name: templateName.value.trim(),
|
||||
mapping: mappingJson,
|
||||
});
|
||||
message.success('更新映射模板成功');
|
||||
} else {
|
||||
const createData: ImportMappingDTO.CreateImportMappingDTO = {
|
||||
type: ImportMappingType.ORDER,
|
||||
name: templateName.value.trim(),
|
||||
mapping: mappingJson,
|
||||
};
|
||||
await createImportMappingApi(createData);
|
||||
message.success('保存映射模板成功');
|
||||
}
|
||||
|
||||
await createImportMappingApi(createData);
|
||||
message.success('保存映射模板成功');
|
||||
templateName.value = '';
|
||||
saveTemplateModalApi.close();
|
||||
// 刷新模板列表
|
||||
await fetchMappingTemplates();
|
||||
// 清空选中的模板
|
||||
selectedTemplateId.value = undefined;
|
||||
// 如果是更新,保持选中状态;如果是创建,清空选中
|
||||
if (!selectedTemplateId.value) {
|
||||
selectedTemplateId.value = undefined;
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('保存映射模板失败:', error);
|
||||
message.error(error?.message || '保存映射模板失败');
|
||||
console.error('保存/更新映射模板失败:', error);
|
||||
message.error(error?.message || '保存/更新映射模板失败');
|
||||
} finally {
|
||||
savingTemplate.value = false;
|
||||
saveTemplateModalApi.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// 确认保存/更新订单状态映射模板
|
||||
async function handleConfirmSaveStatusTemplate() {
|
||||
if (!statusTemplateName.value.trim()) {
|
||||
message.warning('请输入模板名称');
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证所有订单状态是否都已映射
|
||||
const unMappedStatuses = uniqueStatusValues.value.filter(
|
||||
(status) => statusMappings.value[status] === undefined,
|
||||
);
|
||||
|
||||
if (unMappedStatuses.length > 0) {
|
||||
message.warning(`请先映射所有订单状态:${unMappedStatuses.join('、')}`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
savingStatusTemplate.value = true;
|
||||
saveStatusTemplateModalApi.lock();
|
||||
|
||||
// 构建映射数据(已验证所有状态都已映射,所以不会有 undefined)
|
||||
const mappingItems: StatusMappingItem[] = uniqueStatusValues.value.map(
|
||||
(status) => ({
|
||||
csvStatus: status,
|
||||
mappedStatusId: statusMappings.value[status]!,
|
||||
}),
|
||||
);
|
||||
|
||||
const mappingJson = JSON.stringify(mappingItems);
|
||||
|
||||
// 如果选择了模板,则更新;否则创建
|
||||
if (selectedStatusTemplateId.value) {
|
||||
await updateImportMappingApi(selectedStatusTemplateId.value, {
|
||||
name: statusTemplateName.value.trim(),
|
||||
mapping: mappingJson,
|
||||
});
|
||||
message.success('更新订单状态映射模板成功');
|
||||
} else {
|
||||
const createData: ImportMappingDTO.CreateImportMappingDTO = {
|
||||
type: ImportMappingType.ORDER_STATUS,
|
||||
name: statusTemplateName.value.trim(),
|
||||
mapping: mappingJson,
|
||||
};
|
||||
await createImportMappingApi(createData);
|
||||
message.success('保存订单状态映射模板成功');
|
||||
}
|
||||
|
||||
statusTemplateName.value = '';
|
||||
saveStatusTemplateModalApi.close();
|
||||
// 刷新模板列表
|
||||
await fetchStatusMappingTemplates();
|
||||
// 如果是更新,保持选中状态;如果是创建,清空选中
|
||||
if (!selectedStatusTemplateId.value) {
|
||||
selectedStatusTemplateId.value = undefined;
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('保存/更新订单状态映射模板失败:', error);
|
||||
message.error(error?.message || '保存/更新订单状态映射模板失败');
|
||||
} finally {
|
||||
savingStatusTemplate.value = false;
|
||||
saveStatusTemplateModalApi.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// 解析订单状态:从CSV数据中提取status字段映射列的所有唯一值
|
||||
const parseOrderStatuses = () => {
|
||||
// 查找status字段的映射
|
||||
const statusFieldDef = fieldDefs.value.find((f) => f.fieldName === 'status');
|
||||
if (!statusFieldDef) {
|
||||
uniqueStatusValues.value = [];
|
||||
statusMappings.value = {};
|
||||
return;
|
||||
}
|
||||
|
||||
const statusMapping = fieldMappings.value[statusFieldDef.id];
|
||||
if (!statusMapping || !statusMapping.mappedHeader) {
|
||||
uniqueStatusValues.value = [];
|
||||
statusMappings.value = {};
|
||||
return;
|
||||
}
|
||||
|
||||
// 从CSV数据中提取该列的所有唯一值
|
||||
const statusColumn = statusMapping.mappedHeader;
|
||||
const statusSet = new Set<string>();
|
||||
|
||||
csvData.value.forEach((row) => {
|
||||
const statusValue = row[statusColumn];
|
||||
if (
|
||||
statusValue !== null &&
|
||||
statusValue !== undefined &&
|
||||
statusValue !== ''
|
||||
) {
|
||||
statusSet.add(String(statusValue).trim());
|
||||
}
|
||||
});
|
||||
|
||||
uniqueStatusValues.value = [...statusSet].sort();
|
||||
|
||||
// 重置订单状态映射
|
||||
statusMappings.value = {};
|
||||
};
|
||||
|
||||
// 下一步
|
||||
const handleNext = () => {
|
||||
if (currentStep.value === 0) {
|
||||
if (!selectedShopId.value) {
|
||||
message.warning('请选择店铺');
|
||||
return;
|
||||
switch (currentStep.value) {
|
||||
case 0: {
|
||||
if (!selectedShopId.value) {
|
||||
message.warning('请选择店铺');
|
||||
return;
|
||||
}
|
||||
currentStep.value = 1;
|
||||
if (fieldDefs.value.length === 0) {
|
||||
fetchFieldDefs();
|
||||
}
|
||||
// 加载映射模板列表
|
||||
if (mappingTemplates.value.length === 0) {
|
||||
fetchMappingTemplates();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
currentStep.value = 1;
|
||||
if (fieldDefs.value.length === 0) {
|
||||
fetchFieldDefs();
|
||||
case 1: {
|
||||
// 验证必填字段
|
||||
const requiredFields = fieldDefs.value.filter((f) => f.required);
|
||||
const unMappedFields = requiredFields.filter((field) => {
|
||||
const mapping = fieldMappings.value[field.id];
|
||||
return !mapping || !mapping.mappedHeader;
|
||||
});
|
||||
if (unMappedFields.length > 0) {
|
||||
message.warning(
|
||||
`请先绑定必填字段:${unMappedFields.map((f) => f.fieldLabel).join('、')}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 在进入订单状态映射步骤前,解析所有订单状态
|
||||
parseOrderStatuses();
|
||||
|
||||
// 加载订单状态列表
|
||||
if (orderStatusList.value.length === 0) {
|
||||
fetchOrderStatusList();
|
||||
}
|
||||
|
||||
// 加载订单状态映射模板列表
|
||||
if (statusMappingTemplates.value.length === 0) {
|
||||
fetchStatusMappingTemplates();
|
||||
}
|
||||
|
||||
currentStep.value = 2;
|
||||
|
||||
break;
|
||||
}
|
||||
// 加载映射模板列表
|
||||
if (mappingTemplates.value.length === 0) {
|
||||
fetchMappingTemplates();
|
||||
}
|
||||
} else if (currentStep.value === 1) {
|
||||
// 验证必填字段
|
||||
const requiredFields = fieldDefs.value.filter((f) => f.required);
|
||||
const unMappedFields = requiredFields.filter((field) => {
|
||||
const mapping = fieldMappings.value[field.id];
|
||||
return !mapping || !mapping.mappedHeader;
|
||||
});
|
||||
if (unMappedFields.length > 0) {
|
||||
message.warning(
|
||||
`请先绑定必填字段:${unMappedFields.map((f) => f.fieldLabel).join('、')}`,
|
||||
case 2: {
|
||||
// 验证所有订单状态是否都已映射
|
||||
const unMappedStatuses = uniqueStatusValues.value.filter(
|
||||
(status) => statusMappings.value[status] === undefined,
|
||||
);
|
||||
return;
|
||||
if (unMappedStatuses.length > 0) {
|
||||
message.warning(`请先映射所有订单状态:${unMappedStatuses.join('、')}`);
|
||||
return;
|
||||
}
|
||||
currentStep.value = 3;
|
||||
|
||||
break;
|
||||
}
|
||||
currentStep.value = 2;
|
||||
// No default
|
||||
}
|
||||
};
|
||||
|
||||
@@ -454,12 +781,25 @@ const handleCreateTask = async () => {
|
||||
required: m.fieldDef.required,
|
||||
}));
|
||||
|
||||
// 构建订单状态映射 JSON(已验证所有状态都已映射,所以不会有 undefined)
|
||||
const statusMappingItems: StatusMappingItem[] =
|
||||
uniqueStatusValues.value.map((status) => ({
|
||||
csvStatus: status,
|
||||
mappedStatusId: statusMappings.value[status]!,
|
||||
}));
|
||||
|
||||
// 构建完整的映射JSON,包含字段映射和订单状态映射
|
||||
const fullMapping = {
|
||||
fieldMapping: mappingItems,
|
||||
statusMapping: statusMappingItems,
|
||||
};
|
||||
|
||||
const createData: ImportTaskDTO.CreateImportTaskDTO = {
|
||||
shopId: selectedShopId.value!,
|
||||
type: 'order',
|
||||
fileName: selectedFile.value.name,
|
||||
filePath: fileInfo.url,
|
||||
mapping: JSON.stringify(mappingItems),
|
||||
mapping: JSON.stringify(fullMapping),
|
||||
};
|
||||
|
||||
const task = await createImportTaskApi(createData);
|
||||
@@ -478,8 +818,13 @@ const handleCreateTask = async () => {
|
||||
currentStep.value = 0;
|
||||
selectedShopId.value = undefined;
|
||||
fieldMappings.value = {};
|
||||
statusMappings.value = {};
|
||||
uniqueStatusValues.value = [];
|
||||
csvHeaders.value = [];
|
||||
csvData.value = [];
|
||||
selectedFile.value = null;
|
||||
selectedTemplateId.value = undefined;
|
||||
selectedStatusTemplateId.value = undefined;
|
||||
modalApi.close();
|
||||
} catch (error: any) {
|
||||
message.destroy();
|
||||
@@ -491,17 +836,20 @@ const handleCreateTask = async () => {
|
||||
};
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(headers: string[], file?: File) {
|
||||
function open(headers: string[], file?: File, data?: any[]) {
|
||||
const headersChanged =
|
||||
JSON.stringify(csvHeaders.value) !== JSON.stringify(headers);
|
||||
|
||||
csvHeaders.value = headers;
|
||||
csvData.value = data || [];
|
||||
selectedFile.value = file || null;
|
||||
// 步骤保持不变,不清空
|
||||
|
||||
// 如果 CSV 表头变化了,需要重新初始化字段映射
|
||||
if (headersChanged) {
|
||||
fieldMappings.value = {};
|
||||
statusMappings.value = {};
|
||||
uniqueStatusValues.value = [];
|
||||
// 如果已有字段定义,重新初始化映射
|
||||
if (fieldDefs.value.length > 0) {
|
||||
initFieldMappings();
|
||||
@@ -543,16 +891,13 @@ const shopOptions = computed(() => {
|
||||
<Steps :current="currentStep">
|
||||
<Steps.Step title="选择店铺" />
|
||||
<Steps.Step title="字段映射" />
|
||||
<Steps.Step title="订单状态映射" />
|
||||
<Steps.Step title="确认信息" />
|
||||
</Steps>
|
||||
|
||||
<!-- 第一步:选择店铺 -->
|
||||
<div v-if="currentStep === 0" class="py-4">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
|
||||
<Form.Item label="选择店铺" required>
|
||||
<Select
|
||||
v-model:value="selectedShopId"
|
||||
@@ -620,7 +965,10 @@ const shopOptions = computed(() => {
|
||||
</span>
|
||||
</Select.Option>
|
||||
</Select>
|
||||
<Button @click="handleSaveTemplate">保存为模板</Button>
|
||||
<Button v-if="!selectedTemplateId" @click="handleSaveTemplate">
|
||||
保存为模板
|
||||
</Button>
|
||||
<Button v-else @click="handleSaveTemplate"> 更新模板 </Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="max-h-[400px] space-y-4 overflow-y-auto">
|
||||
@@ -662,8 +1010,89 @@ const shopOptions = computed(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第三步:确认信息 -->
|
||||
<!-- 第三步:订单状态映射 -->
|
||||
<div v-if="currentStep === 2" class="py-4">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<div class="text-sm text-gray-600">
|
||||
请为每个订单状态值映射到对应的系统订单状态,所有状态必须映射
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<Select
|
||||
v-model:value="selectedStatusTemplateId"
|
||||
placeholder="选择已有模板"
|
||||
class="w-[200px]"
|
||||
:loading="statusTemplateLoading"
|
||||
allow-clear
|
||||
@change="handleSelectStatusTemplate"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="statusTemplateLoading" class="py-4 text-center">
|
||||
<Spin size="small" />
|
||||
<div class="mt-2">加载中...</div>
|
||||
</div>
|
||||
<div v-else class="py-4 text-center text-gray-400">
|
||||
暂无模板
|
||||
</div>
|
||||
</template>
|
||||
<Select.Option
|
||||
v-for="template in statusMappingTemplates"
|
||||
:key="template.id"
|
||||
:value="template.id"
|
||||
>
|
||||
{{ template.name }}
|
||||
<span class="ml-2 text-xs text-gray-400">
|
||||
({{ new Date(template.createTime).toLocaleDateString() }})
|
||||
</span>
|
||||
</Select.Option>
|
||||
</Select>
|
||||
<Button
|
||||
v-if="!selectedStatusTemplateId"
|
||||
@click="handleSaveStatusTemplate"
|
||||
>
|
||||
保存为模板
|
||||
</Button>
|
||||
<Button v-else @click="handleSaveStatusTemplate"> 更新模板 </Button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="uniqueStatusValues.length === 0"
|
||||
class="py-8 text-center text-gray-400"
|
||||
>
|
||||
未找到订单状态字段映射,请先在字段映射步骤中绑定status字段
|
||||
</div>
|
||||
<div v-else class="max-h-[400px] space-y-4 overflow-y-auto">
|
||||
<div
|
||||
v-for="statusValue in uniqueStatusValues"
|
||||
:key="statusValue"
|
||||
class="flex items-center space-x-4 rounded border p-3"
|
||||
:class="{
|
||||
'border-red-300 bg-red-50':
|
||||
statusMappings[statusValue] === undefined,
|
||||
}"
|
||||
>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium">{{ statusValue }}</div>
|
||||
<div class="mt-1 text-xs text-gray-500">CSV中的订单状态值</div>
|
||||
</div>
|
||||
<Select
|
||||
v-model:value="statusMappings[statusValue]"
|
||||
placeholder="请选择订单状态"
|
||||
class="w-[200px]"
|
||||
show-search
|
||||
:loading="orderStatusLoading"
|
||||
:options="
|
||||
orderStatusList.map((status) => ({
|
||||
label: status.statusName,
|
||||
value: status.id,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第四步:确认信息 -->
|
||||
<div v-if="currentStep === 3" class="py-4">
|
||||
<div class="space-y-4">
|
||||
<div class="rounded bg-gray-50 p-4">
|
||||
<div class="mb-2 font-medium">店铺信息</div>
|
||||
@@ -691,6 +1120,25 @@ const shopOptions = computed(() => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded bg-gray-50 p-4">
|
||||
<div class="mb-2 font-medium">订单状态映射</div>
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="statusValue in uniqueStatusValues"
|
||||
:key="statusValue"
|
||||
class="flex justify-between text-sm"
|
||||
>
|
||||
<span class="text-gray-600">{{ statusValue }}:</span>
|
||||
<span class="font-medium">
|
||||
{{
|
||||
orderStatusList.find(
|
||||
(status) => status.id === statusMappings[statusValue],
|
||||
)?.statusName ?? '-'
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -700,7 +1148,7 @@ const shopOptions = computed(() => {
|
||||
<div class="space-x-2">
|
||||
<Button v-if="currentStep > 0" @click="handlePrev">上一步</Button>
|
||||
<Button
|
||||
v-if="currentStep < 2"
|
||||
v-if="currentStep < 3"
|
||||
type="primary"
|
||||
:disabled="!canGoToNextStep"
|
||||
@click="handleNext"
|
||||
@@ -708,7 +1156,7 @@ const shopOptions = computed(() => {
|
||||
下一步
|
||||
</Button>
|
||||
<Button
|
||||
v-if="currentStep === 2"
|
||||
v-if="currentStep === 3"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="handleCreateTask"
|
||||
@@ -733,6 +1181,21 @@ const shopOptions = computed(() => {
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</SaveTemplateModal>
|
||||
|
||||
<!-- 保存订单状态映射模板模态框 -->
|
||||
<SaveStatusTemplateModal :confirm-loading="savingStatusTemplate">
|
||||
<Form :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
|
||||
<Form.Item label="模板名称" required>
|
||||
<Input
|
||||
v-model:value="statusTemplateName"
|
||||
placeholder="请输入模板名称"
|
||||
:maxlength="50"
|
||||
show-count
|
||||
@press-enter="handleConfirmSaveStatusTemplate"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</SaveStatusTemplateModal>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -170,21 +170,40 @@ const handleCreateImportTask = () => {
|
||||
createImportTaskModalRef.value?.open(
|
||||
csvHeaders.value,
|
||||
currentFile.value ?? undefined,
|
||||
csvData.value,
|
||||
);
|
||||
};
|
||||
|
||||
// 清空数据
|
||||
const handleClearData = () => {
|
||||
csvData.value = [];
|
||||
csvHeaders.value = [];
|
||||
currentFile.value = null;
|
||||
// 更新表格
|
||||
updateTable();
|
||||
message.success('已清空数据');
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<!-- 顶部栏 -->
|
||||
<template #extra>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="csvHeaders.length === 0"
|
||||
@click="handleCreateImportTask"
|
||||
>
|
||||
创建导入任务
|
||||
</Button>
|
||||
<div class="flex items-center space-x-2">
|
||||
<Button
|
||||
:disabled="csvData.length === 0"
|
||||
@click="handleClearData"
|
||||
>
|
||||
清空数据
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="csvHeaders.length === 0"
|
||||
@click="handleCreateImportTask"
|
||||
>
|
||||
创建导入任务
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 主体内容区域 -->
|
||||
|
||||
Reference in New Issue
Block a user