Commit 2fb695a7 by cen

fix: 二手车提单优化

1 parent 9e518ed5
......@@ -484,6 +484,12 @@ Page({
// 转换每个图片/视频
images.forEach((image) => {
// 跳过没有 URL 或状态不是 done 的文件
if (!image.url || (image.status && image.status !== "done")) {
console.warn("跳过无效或未完成的文件:", image);
return;
}
const fileItem = {
fileType,
fileSubtype,
......@@ -494,6 +500,10 @@ Page({
if (fileType === 3) {
fileItem.fileFormat = "mp4";
fileItem.fileName = image.name || this.getImageNameByKey(keyNum);
// 如果有封面图,也添加到提交数据中
if (image.coverUrl) {
fileItem.coverUrl = image.coverUrl;
}
}
// 如果是检测报告,添加额外字段
......@@ -869,7 +879,11 @@ Page({
// 处理详情数据
handleDetailData(data, evalOrderNo) {
const { basic = {}, carInfo = {}, carLicense = {}, images = [] } = data;
const { basic = {}, carInfo = {}, carLicense = {}, images } = data;
// 确保 images 是数组,如果为 null 或 undefined,设置为空数组
const imageList = Array.isArray(images) ? images : [];
console.log("handleDetailData - 原始 images:", images, "处理后:", imageList);
// 处理地区显示格式:确保是 "省份 城市" 格式
// 车辆所在地
......@@ -1072,10 +1086,16 @@ Page({
};
// 处理图片数据
const imageList = {};
const processedImageList = {};
images.forEach((image) => {
const { fileType, fileSubtype, fileUrl } = image;
imageList.forEach((image) => {
const { fileType, fileSubtype, fileUrl, coverUrl } = image;
// 检查 fileUrl 是否为空
if (!fileUrl) {
console.warn("图片数据中 fileUrl 为空,跳过:", image);
return;
}
// 根据 fileType 和 fileSubtype 映射到对应的 key
// fileType: 1-车辆图片, 2-证件资料, 3-车辆视频, 4-其他图片, 5-车辆检测报告
......@@ -1103,18 +1123,36 @@ Page({
}
if (key) {
if (!imageList[key]) {
imageList[key] = [];
if (!processedImageList[key]) {
processedImageList[key] = [];
}
// 根据 fileType 构造不同的数据结构
if (fileType === 3) {
// 视频文件:需要 videoUrl、coverUrl 和 isVideo 标识
processedImageList[key].push({
url: fileUrl, // 视频 URL
thumb: coverUrl || "", // 封面图(van-uploader 使用 thumb 作为预览图)
coverUrl: coverUrl || "", // 保存封面图 URL,用于预览
isVideo: true,
name: this.getImageNameByKey(key),
key: key,
status: "done",
});
} else {
// 普通图片
processedImageList[key].push({
url: fileUrl,
isVideo: false,
name: this.getImageNameByKey(key),
key: key,
status: "done",
});
}
imageList[key].push({
url: fileUrl,
name: this.getImageNameByKey(key),
key: key,
});
}
});
updateData["formData.imageList"] = imageList;
updateData["formData.imageList"] = processedImageList;
// 一次性更新所有数据
console.log(
......
......@@ -29,19 +29,37 @@ Component({
imageData: function (newImageData) {
// 监听 imageData 变化,重新初始化图片列表
console.log("imageData 变化:", newImageData);
if (newImageData && Object.keys(newImageData).length > 0) {
// 处理回显数据:确保所有文件都有 status 字段和 isVideo 字段
const processedImageList = {};
const { uploadVideoFields } = this.data;
// 获取所有视频字段的 key 集合
const videoKeys = new Set(
uploadVideoFields.map((field) => String(field.key))
);
for (const key in newImageData) {
const fileList = newImageData[key];
if (Array.isArray(fileList)) {
processedImageList[key] = fileList.map((file) => {
// 如果 newImageData 为 null 或 undefined,设置为空对象
if (!newImageData) {
this.setData({
imageList: {},
});
return;
}
// 处理回显数据:确保所有文件都有 status 字段和 isVideo 字段
const processedImageList = {};
const { uploadVideoFields } = this.data;
// 获取所有视频字段的 key 集合
const videoKeys = new Set(
uploadVideoFields.map((field) => String(field.key))
);
for (const key in newImageData) {
const fileList = newImageData[key];
if (Array.isArray(fileList) && fileList.length > 0) {
// 过滤掉 url 为空的文件,并处理每个文件
processedImageList[key] = fileList
.filter((file) => {
// 过滤掉没有 url 的文件
if (!file || !file.url) {
console.warn("过滤掉无效文件(url 为空):", file);
return false;
}
return true;
})
.map((file) => {
const processedFile = { ...file };
// 如果文件没有 status 字段,说明是编辑回显的数据,设置为 'done'
if (!processedFile.status) {
......@@ -71,15 +89,18 @@ Component({
}
return processedFile;
});
} else {
processedImageList[key] = fileList;
// 如果过滤后数组为空,不添加到 processedImageList
if (processedImageList[key].length === 0) {
delete processedImageList[key];
}
}
this.setData({
imageList: processedImageList,
});
console.log("已更新 imageList:", this.data.imageList);
}
this.setData({
imageList: processedImageList,
});
console.log("已更新 imageList:", this.data.imageList);
},
},
......@@ -170,18 +191,36 @@ Component({
// 初始化图片列表
initImageList() {
const { imageData, uploadVideoFields } = this.data;
if (imageData && Object.keys(imageData).length > 0) {
// 处理回显数据:确保所有文件都有 status 字段和 isVideo 字段
const processedImageList = {};
// 获取所有视频字段的 key 集合
const videoKeys = new Set(
uploadVideoFields.map((field) => String(field.key))
);
for (const key in imageData) {
const fileList = imageData[key];
if (Array.isArray(fileList)) {
processedImageList[key] = fileList.map((file) => {
// 如果 imageData 为空,设置为空对象
if (!imageData || Object.keys(imageData).length === 0) {
this.setData({
imageList: {},
});
return;
}
// 处理回显数据:确保所有文件都有 status 字段和 isVideo 字段
const processedImageList = {};
// 获取所有视频字段的 key 集合
const videoKeys = new Set(
uploadVideoFields.map((field) => String(field.key))
);
for (const key in imageData) {
const fileList = imageData[key];
if (Array.isArray(fileList) && fileList.length > 0) {
// 过滤掉 url 为空的文件,并处理每个文件
processedImageList[key] = fileList
.filter((file) => {
// 过滤掉没有 url 的文件
if (!file || !file.url) {
console.warn("initImageList - 过滤掉无效文件(url 为空):", file);
return false;
}
return true;
})
.map((file) => {
const processedFile = { ...file };
// 如果文件没有 status 字段,说明是编辑回显的数据,设置为 'done'
if (!processedFile.status) {
......@@ -211,14 +250,17 @@ Component({
}
return processedFile;
});
} else {
processedImageList[key] = fileList;
// 如果过滤后数组为空,不添加到 processedImageList
if (processedImageList[key].length === 0) {
delete processedImageList[key];
}
}
this.setData({
imageList: processedImageList,
});
}
this.setData({
imageList: processedImageList,
});
},
// 处理上传
......@@ -836,13 +878,36 @@ Component({
// 校验必填项
validate() {
const { imageList, uploadFields } = this.data;
const { imageList, uploadFields, uploadCertificateFields, uploadVideoFields, uploadReportFields, uploadOtherFields } = this.data;
// 合并所有字段
const allFields = [
...uploadFields,
...uploadCertificateFields,
...uploadVideoFields,
...uploadReportFields,
...uploadOtherFields,
];
// 1. 检查是否有正在上传的文件
for (let field of allFields) {
const list = imageList[field.key] || [];
const uploadingFiles = list.filter(file => file.status === 'uploading');
if (uploadingFiles.length > 0) {
return {
message: `${field.label}正在上传中,请稍候...`,
};
}
}
// 检查必填的车辆图片
// 2. 检查必填的车辆图片(只检查状态为 done 的文件)
for (let field of uploadFields) {
if (field.required) {
console.log(imageList[field.key], 'imageList[field.key]');
const list = imageList[field.key] || [];
if (list.length === 0) {
// 只统计上传完成的文件
const doneFiles = list.filter(file => !file.status || file.status === 'done');
if (doneFiles.length === 0) {
return {
message: `请上传${field.label}`,
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!