Commit d2434d19 by cen

fix: 更新详情

1 parent c4a3f09b
<!-- packageEquity/pages/carEquity/components/GLForm/GLForm.wxml -->
<wxs src="./GLForm.wxs" module="filterUtils" />
<view wx:for="{{formDataList}}" wx:key="index" class="custom-class gl-form">
<gl-cell
wx:if="{{filterUtils.isShowFn(formData, item) && item.type != 'otherSlot'}}"
border="{{!item.noBorder}}"
class="{{item.name}}"
haveArrow="{{item.haveArrow || false}}"
valueAlign="right"
label="{{item.label}}"
labelWidth="{{item.labelWidth || labelWidth}}"
placeholder="{{item.placeholder || ''}}"
bindclick="handleCellClick"
data-target="{{item}}"
data-idx="{{index}}"
background="{{background}}"
required="{{item.required}}"
requiredAfter="{{item.requiredAfter}}"
cellHeight="{{!item.noCellHeight}}"
cellStyle="{{item.cellStyle||''}}"
labelStyle="{{item.labelStyle}}"
cellBoxStyle="{{item.cellBoxStyle||''}}">
<!-- slot -->
<slot wx:if="{{item.type == 'slot'}}" name="{{item.name}}" />
<!-- input / textarea -->
<view wx:if="{{item.type == 'input'}}" class="input-box">
<!-- rows="1" -->
<van-field
class="textarea"
custom-style="padding: var(--fontSize30) 0; font-size: var(--fontSize28); background: {{background}};"
border="{{ false}}"
value="{{formData[item.name]}}"
input-align="{{itme.inputAlign || 'right'}}"
autosize
hold-keyboard
type="{{item.fieldType || 'text'}}"
placeholder="{{item.placeholder || '请输入'}}"
maxlength="{{item.maxlength || 140}}"
disabled="{{item.disabled||disable}}"
readonly="{{item.readonly}}"
data-attr="{{item.name}}"
data-item="{{item}}"
bindinput="handleInput" />
<text wx:if="{{item.suffix}}" class="input-suffix">{{item.suffix}}</text>
</view>
<!-- picker -->
<picker
wx:if="{{item.type == 'select'}}"
bindchange="handlePickerChange"
data-target="{{item}}"
value="{{index}}"
disabled="{{item.disabled||disable}}"
range="{{item.optionList}}"
range-key="{{item.optionLabel}}">
<view class="picker">
<image class="arrow" src="/components/images/arrow-x.png" />
<view class="text-hide" wx:if="{{formData[item.labelName]}}">
{{formData[item.labelName]}}
</view>
<text class="placeholder" wx:else>请选择</text>
</view>
</picker>
<!-- 省市区 -->
<block wx:if="{{item.type == 'region'}}">
<view class="picker" bindtap="showAreaFun">
<image class="arrow" src="/components/images/arrow-x.png" />
<view class="text-hide" wx:if="{{formData[item.labelName]}}">
{{formData[item.labelName]}}
</view>
<text class="placeholder" wx:else>请选择</text>
</view>
<van-popup
show="{{ showArea }}"
position="bottom"
bind:close="showAreaFun"
>
<van-area area-list="{{ areaList }}" columns-num="{{ item.columnsNum }}" title="{{item.label}}" bind:confirm="bindRegionChange" bind:cancel="showAreaFun" />
</van-popup>
</block>
<!-- <picker
<gl-cell wx:if="{{filterUtils.isShowFn(formData, item) && item.type != 'otherSlot'}}" border="{{!item.noBorder}}" class="{{item.name}}" haveArrow="{{item.haveArrow || false}}" valueAlign="right" label="{{item.label}}" labelWidth="{{item.labelWidth || labelWidth}}" placeholder="{{item.placeholder || ''}}" bindclick="handleCellClick" data-target="{{item}}" data-idx="{{index}}" background="{{background}}" required="{{item.required}}" requiredAfter="{{item.requiredAfter}}" cellHeight="{{!item.noCellHeight}}" cellStyle="{{item.cellStyle||''}}" labelStyle="{{item.labelStyle}}" cellBoxStyle="{{item.cellBoxStyle||''}}">
<!-- slot -->
<slot wx:if="{{item.type == 'slot'}}" name="{{item.name}}" />
<!-- input / textarea -->
<view wx:if="{{item.type == 'input'}}" class="input-box">
<!-- rows="1" -->
<van-field class="textarea" custom-style="padding: var(--fontSize30) 0; font-size: var(--fontSize28); background: {{background}};" border="{{ false}}" value="{{formData[item.name]}}" input-align="{{itme.inputAlign || 'right'}}" autosize hold-keyboard type="{{item.fieldType || 'text'}}" placeholder="{{item.placeholder || '请输入'}}" maxlength="{{item.maxlength || 140}}" disabled="{{item.disabled||disable}}" readonly="{{item.readonly}}" data-attr="{{item.name}}" data-item="{{item}}" bindinput="handleInput" />
<text wx:if="{{item.suffix}}" class="input-suffix">{{item.suffix}}</text>
</view>
<!-- picker -->
<picker wx:if="{{item.type == 'select'}}" bindchange="handlePickerChange" data-target="{{item}}" value="{{filterUtils.getPickerIndex(formData, item)}}" disabled="{{item.disabled||disable}}" range="{{item.optionList}}" range-key="{{item.optionLabel}}">
<view class="picker">
<image class="arrow" src="/components/images/arrow-x.png" />
<view class="text-hide" wx:if="{{formData[item.labelName]}}">
{{formData[item.labelName]}}
</view>
<text class="placeholder" wx:else>请选择</text>
</view>
</picker>
<!-- 省市区 -->
<block wx:if="{{item.type == 'region'}}">
<view class="picker" bindtap="showAreaFun">
<image class="arrow" src="/components/images/arrow-x.png" />
<view class="text-hide" wx:if="{{formData[item.labelName]}}">
{{formData[item.labelName]}}
</view>
<text class="placeholder" wx:else>请选择</text>
</view>
<van-popup show="{{ showArea }}" position="bottom" bind:close="showAreaFun">
<van-area area-list="{{ areaList }}" columns-num="{{ item.columnsNum }}" title="{{item.label}}" bind:confirm="bindRegionChange" bind:cancel="showAreaFun" />
</van-popup>
</block>
<!-- <picker
mode="region"
bindchange="bindRegionChange"
......@@ -93,28 +49,22 @@
<text class="placeholder" wx:else>请选择</text>
</view>
</picker> -->
<!-- 时间选择器 -->
<picker
wx:if="{{item.type == 'pickerTime'}}"
mode="date"
value="{{formData[name] || formData[item.name]}}"
start="{{item.start || ''}}"
end="{{item.end || ''}}"
bindchange="handleTimeChange"
data-target="{{item}}">
<view class="picker">
<view class="text-hide" wx:if="{{formData[item.name]}}">{{formData[item.name]}}</view>
<text class="placeholder" wx:else>请选择</text>
</view>
</picker>
<!-- 品牌车型 -->
<view wx:if="{{item.type == 'brand'}}" class="brand">
<view wx:if="{{formData.vehicleBrandId}}">
{{formData.vehicleBrandName || ''}}/{{formData.vehicleSubBrandName || ''}}/{{formData.vehicleSeriesName || ''}}/{{formData.vehicleShapeName || ''}}
</view>
<view wx:else class="placeholder-class">{{item.placeholder || '请选择'}}</view>
</view>
</gl-cell>
<slot wx:if="{{item.type == 'otherSlot'}}" name="{{item.name}}" />
</view>
<!-- 时间选择器 -->
<picker wx:if="{{item.type == 'pickerTime'}}" mode="date" value="{{formData[name] || formData[item.name]}}" start="{{item.start || ''}}" end="{{item.end || ''}}" bindchange="handleTimeChange" data-target="{{item}}">
<view class="picker">
<view class="text-hide" wx:if="{{formData[item.name]}}">
{{formData[item.name]}}
</view>
<text class="placeholder" wx:else>请选择</text>
</view>
</picker>
<!-- 品牌车型 -->
<view wx:if="{{item.type == 'brand'}}" class="brand">
<view wx:if="{{formData.vehicleBrandId}}">
{{formData.vehicleBrandName || ''}}/{{formData.vehicleSubBrandName || ''}}/{{formData.vehicleSeriesName || ''}}/{{formData.vehicleShapeName || ''}}
</view>
<view wx:else class="placeholder-class">{{item.placeholder || '请选择'}}</view>
</view>
</gl-cell>
<slot wx:if="{{item.type == 'otherSlot'}}" name="{{item.name}}" />
</view>
\ No newline at end of file
var isShowFn = function (formData, targetItem) {
var flag = false
var flag = false;
if (targetItem.isShowObj && formData) {
for (var i = 0; i <= targetItem.isShowObj.list.length; i++) {
var item = targetItem.isShowObj.list[i]
var item = targetItem.isShowObj.list[i];
if (item == formData[targetItem.isShowObj.attr]) {
flag = true
break
flag = true;
break;
}
}
} else {
flag = true
flag = true;
}
return flag
}
return flag;
};
// 根据 formData 的值和 optionList 计算 picker 的选中索引
var getPickerIndex = function (formData, item) {
if (!formData || !item || !item.optionList || !item.optionId || !item.name) {
return 0;
}
var currentValue = formData[item.name];
if (
currentValue === null ||
currentValue === undefined ||
currentValue === ""
) {
return 0;
}
var optionList = item.optionList;
var optionId = item.optionId;
for (var i = 0; i < optionList.length; i++) {
if (String(optionList[i][optionId]) === String(currentValue)) {
return i;
}
}
return 0;
};
module.exports = {
isShowFn: isShowFn
}
\ No newline at end of file
isShowFn: isShowFn,
getPickerIndex: getPickerIndex,
};
......@@ -17,11 +17,21 @@ Component({
this.setData({
formData: n,
});
// 当 formData 更新时,重新计算所有 picker 的索引
this.calculatePickerIndexes();
},
},
formDataList: {
type: Array,
value: () => [],
observer: function (n) {
// 当 formDataList 更新时,重新计算索引
if (n && n.length > 0 && this.data.formData) {
wx.nextTick(() => {
this.calculatePickerIndexes();
});
}
},
},
labelWidth: {
type: String,
......@@ -55,6 +65,7 @@ Component({
areaList: [],
currentRegionTarget: null, // 当前选择地区的字段配置
currentDate: "", // 当前日期,格式:YYYY-MM-DD
pickerIndexMap: {}, // 存储每个 picker 的选中索引
},
lifetimes: {
......@@ -68,6 +79,10 @@ Component({
this.setData({
currentDate: currentDate,
});
// 初始化时计算 picker 索引
wx.nextTick(() => {
this.calculatePickerIndexes();
});
let thisPage = wx.$router.getPageInstance();
wx.$eventbus.on("set_car_info", (n) => {
let { targetIdx, dataAttrName, formDataList } = this.data;
......@@ -266,6 +281,78 @@ Component({
attr,
});
},
// 计算所有 picker 的选中索引
calculatePickerIndexes() {
const { formData, formDataList } = this.data;
if (!formData || !formDataList) return;
const pickerIndexMap = {};
formDataList.forEach((item) => {
if (
item.type === "select" &&
item.optionList &&
item.optionId &&
item.name
) {
const currentValue = formData[item.name];
if (
currentValue !== null &&
currentValue !== undefined &&
currentValue !== ""
) {
const currentValueStr = String(currentValue);
const optionList = item.optionList;
const optionId = item.optionId;
for (let i = 0; i < optionList.length; i++) {
const option = optionList[i];
if (!option) continue;
let optionValue = null;
if (optionId === "value") {
optionValue = option.value;
} else if (optionId === "name") {
optionValue = option.name;
} else {
optionValue = option[optionId];
}
if (optionValue !== null && optionValue !== undefined) {
// 支持数字和字符串类型的比较
const optionValueStr = String(optionValue);
const currentValueNum = Number(currentValue);
const optionValueNum = Number(optionValue);
// 先尝试数字比较(适用于综合评价等数字类型字段)
if (
!isNaN(currentValueNum) &&
!isNaN(optionValueNum) &&
currentValueNum === optionValueNum
) {
pickerIndexMap[item.name] = i;
console.log(
`计算索引 - ${item.name}: 值=${currentValueNum}, 索引=${i}`
);
break;
}
// 再尝试字符串比较(适用于其他字符串类型字段)
if (optionValueStr === currentValueStr) {
pickerIndexMap[item.name] = i;
console.log(
`计算索引 - ${item.name}: 值=${currentValueStr}, 索引=${i}`
);
break;
}
}
}
}
}
});
this.setData({
pickerIndexMap: pickerIndexMap,
});
},
handlePickerChange(e) {
console.log(e, "handlePickerChange");
let idx = e.detail.value || 0;
......@@ -279,6 +366,8 @@ Component({
[dataAttrName + "." + target.labelName]:
target.optionList[idx][target.optionLabel],
});
// 更新后重新计算索引
this.calculatePickerIndexes();
console.log(thisPage);
this.triggerEvent("pickerChange", {
obj: target.optionList[idx],
......
......@@ -57,7 +57,7 @@
wx:if="{{ item.type == 'select' }}"
bindchange="handlePickerChange"
data-target="{{ item }}"
value="{{ index }}"
value="{{ pickerIndexMap[item.name] !== undefined ? pickerIndexMap[item.name] : filterUtils.getPickerIndex(formData, item) }}"
disabled="{{ item.disabled || disable }}"
range="{{ item.optionList }}"
range-key="{{ item.optionLabel }}"
......
var isShowFn = function (formData, targetItem) {
var flag = false
var flag = false;
if (targetItem.isShowObj && formData) {
for (var i = 0; i <= targetItem.isShowObj.list.length; i++) {
var item = targetItem.isShowObj.list[i]
var item = targetItem.isShowObj.list[i];
if (item == formData[targetItem.isShowObj.attr]) {
flag = true
break
flag = true;
break;
}
}
} else {
flag = true
flag = true;
}
return flag
}
return flag;
};
// 根据 formData 的值和 optionList 计算 picker 的选中索引
var getPickerIndex = function (formData, item) {
if (!formData || !item) {
return 0;
}
var optionList = item.optionList;
var optionId = item.optionId;
var fieldName = item.name;
if (!optionList || optionList.length === 0 || !optionId || !fieldName) {
return 0;
}
var currentValue = formData[fieldName];
if (
currentValue === null ||
currentValue === undefined ||
currentValue === ""
) {
return 0;
}
// WXS 不支持 String(),使用 "" + value 的方式转换为字符串
var currentValueStr = "" + currentValue;
for (var i = 0; i < optionList.length; i++) {
var option = optionList[i];
if (!option) continue;
// 在 WXS 中,需要使用字符串键名访问对象属性
var optionValue = null;
if (optionId === "value") {
optionValue = option.value;
} else if (optionId === "name") {
optionValue = option.name;
} else {
optionValue = option[optionId];
}
if (optionValue === null || optionValue === undefined) continue;
// WXS 不支持 String(),使用 "" + value 的方式转换为字符串
var optionValueStr = "" + optionValue;
// 比较字符串值(已确保数据类型一致,直接字符串比较即可)
if (optionValueStr === currentValueStr) {
return i;
}
}
return 0;
};
module.exports = {
isShowFn: isShowFn
}
\ No newline at end of file
isShowFn: isShowFn,
getPickerIndex: getPickerIndex,
};
<view class="popup" hidden="{{ !showPopup }}" catchtouchmove="noScroll">
<view class="popup-bg"></view>
<view class="popup-content" style="height:{{ height }}">
<block wx:if="{{ title }}">
<view class="popup-title text-center">{{title}}</view>
</block>
<view class="popup-slot popup-slot-class {{ isFullSucreen?title?'isFullSucreen':'isFullSucreen-notitle':'' }}" style="{{slotStyle}}">
<slot></slot>
</view>
<view class="popup-bg"></view>
<view class="popup-content" style="height:{{ height }}">
<block wx:if="{{ title }}">
<view class="popup-title text-center">{{title}}</view>
</block>
<view class="popup-slot popup-slot-class {{ isFullSucreen?title?'isFullSucreen':'isFullSucreen-notitle':'' }}" style="{{slotStyle}}">
<slot></slot>
</view>
<view class="popup-footer {{ isFullSucreen?'isFullSucreen':'' }} {{ singleButton ? 'single-button' : '' }}">
<view wx:if="{{singleButton !== true}}" class="cancel btn text-center" bindtap="hidePopup" style="{{cancelStyle}}">
{{cancelText || '取消'}}
......@@ -14,6 +14,6 @@
<view class="confirm btn text-center {{ singleButton ? 'single-btn' : '' }}" bindtap="confirm" style="{{confirmStyle}}">
{{confirmText || '确认'}}
</view>
</view>
</view>
</view>
</view>
</view>
\ No newline at end of file
......@@ -4,6 +4,14 @@ import { validateVin, formatVinInput } from "~/utils/vinVaildate";
import newApi from "~/packageUsedCar/api";
import Dialog from "@vant/weapp/dialog/dialog";
import { statusMap } from "../evaluationFormDetails/evaluationFormMap.js";
import {
usageTypeList,
ownerTypeList,
sunroofList,
vehicleCategory,
emissionStandard,
overallRating,
} from "../components/constant/constantList";
Page({
/**
......@@ -14,6 +22,7 @@ Page({
step: "first", // first | second | third
currentStep: 1, // 当前步骤:1-车辆信息 | 2-牌证信息 | 3-图像信息
fixedHeaderHeight: 120,
scrollTop: 0, // 滚动位置
isEdit: false, // 是否为编辑模式
detailsInfo: null, // 详情数据(编辑模式使用)
statusMap, // 状态映射
......@@ -184,6 +193,7 @@ Page({
{
step: "second",
currentStep: 2,
scrollTop: 0, // 重置滚动位置
},
() => {
// 切换步骤后重新计算固定头部高度
......@@ -248,6 +258,7 @@ Page({
{
step: "third",
currentStep: 3,
scrollTop: 0, // 重置滚动位置
},
() => {
// 切换步骤后重新计算固定头部高度
......@@ -297,6 +308,7 @@ Page({
{
step: "first",
currentStep: 1,
scrollTop: 0, // 重置滚动位置
},
() => {
// 切换步骤后重新计算固定头部高度
......@@ -309,6 +321,7 @@ Page({
{
step: "second",
currentStep: 2,
scrollTop: 0, // 重置滚动位置
},
() => {
// 切换步骤后重新计算固定头部高度
......@@ -843,6 +856,161 @@ Page({
carInfo.interiorColorName = carInfo.interiorColor;
}
// 处理枚举字段:根据值设置对应的名称字段,并确保值类型与选项列表一致
// 使用性质
if (
carInfo.usageType !== null &&
carInfo.usageType !== undefined &&
carInfo.usageType !== ""
) {
const usageTypeItem = usageTypeList.find(
(item) => item.value === String(carInfo.usageType)
);
if (usageTypeItem) {
carInfo.usageTypeName = usageTypeItem.name;
// 确保值类型为字符串,与选项列表一致
carInfo.usageType = String(carInfo.usageType);
console.log(
"使用性质 - 原始值:",
carInfo.usageType,
"转换后:",
String(carInfo.usageType),
"名称:",
usageTypeItem.name,
"选项列表:",
usageTypeList
);
}
}
// 所有人性质
if (
carInfo.ownerType !== null &&
carInfo.ownerType !== undefined &&
carInfo.ownerType !== ""
) {
const ownerTypeItem = ownerTypeList.find(
(item) => item.value === String(carInfo.ownerType)
);
if (ownerTypeItem) {
carInfo.ownerTypeName = ownerTypeItem.name;
carInfo.ownerType = String(carInfo.ownerType);
console.log(
"所有人性质 - 原始值:",
carInfo.ownerType,
"转换后:",
String(carInfo.ownerType),
"名称:",
ownerTypeItem.name,
"选项列表:",
ownerTypeList
);
}
}
// 天窗
if (
carInfo.sunroof !== null &&
carInfo.sunroof !== undefined &&
carInfo.sunroof !== ""
) {
const sunroofItem = sunroofList.find(
(item) => item.value === String(carInfo.sunroof)
);
if (sunroofItem) {
carInfo.sunroofName = sunroofItem.name;
carInfo.sunroof = String(carInfo.sunroof);
console.log(
"天窗 - 原始值:",
carInfo.sunroof,
"转换后:",
String(carInfo.sunroof),
"名称:",
sunroofItem.name,
"选项列表:",
sunroofList
);
}
}
// 车辆类别
if (
carInfo.vehicleCategory !== null &&
carInfo.vehicleCategory !== undefined &&
carInfo.vehicleCategory !== ""
) {
const vehicleCategoryItem = vehicleCategory.find(
(item) => item.value === String(carInfo.vehicleCategory)
);
if (vehicleCategoryItem) {
carInfo.vehicleCategoryName = vehicleCategoryItem.name;
carInfo.vehicleCategory = String(carInfo.vehicleCategory);
console.log(
"车辆类别 - 原始值:",
carInfo.vehicleCategory,
"转换后:",
String(carInfo.vehicleCategory),
"名称:",
vehicleCategoryItem.name,
"选项列表:",
vehicleCategory
);
}
}
// 排放标准
if (
carInfo.emissionStandard !== null &&
carInfo.emissionStandard !== undefined &&
carInfo.emissionStandard !== ""
) {
const emissionStandardItem = emissionStandard.find(
(item) => item.value === String(carInfo.emissionStandard)
);
if (emissionStandardItem) {
carInfo.emissionStandardName = emissionStandardItem.name;
carInfo.emissionStandard = String(carInfo.emissionStandard);
console.log(
"排放标准 - 原始值:",
carInfo.emissionStandard,
"转换后:",
String(carInfo.emissionStandard),
"名称:",
emissionStandardItem.name,
"选项列表:",
emissionStandard
);
}
}
// 综合评价(注意:value 是数字类型,不是字符串)
if (
carInfo.overallRating !== null &&
carInfo.overallRating !== undefined &&
carInfo.overallRating !== ""
) {
const overallRatingItem = overallRating.find(
(item) =>
item.value === Number(carInfo.overallRating) ||
item.value === carInfo.overallRating
);
if (overallRatingItem) {
carInfo.overallRatingName = overallRatingItem.name;
// 综合评价的 value 是数字类型,保持原样
carInfo.overallRating = Number(carInfo.overallRating);
console.log(
"综合评价 - 原始值:",
carInfo.overallRating,
"转换后:",
Number(carInfo.overallRating),
"名称:",
overallRatingItem.name,
"选项列表:",
overallRating
);
}
}
// 更新表单数据
// 确保 sellerMerchantId 和 sellerMerchantName 有值(如果 basic 中没有,则使用 userInfo)
const userInfo =
......@@ -930,7 +1098,53 @@ Page({
updateData["formData.imageList"] = imageList;
// 一次性更新所有数据
this.setData(updateData, () => {});
console.log(
"更新表单数据 - carBaseReqDTO:",
updateData["formData.carBaseReqDTO"]
);
// 输出排放标准的值和类型用于调试
console.log(
"排放标准 - 更新前的值:",
updateData["formData.carBaseReqDTO"].emissionStandard,
"类型:",
typeof updateData["formData.carBaseReqDTO"].emissionStandard
);
this.setData(updateData, () => {
// 数据更新后,输出最终的值用于调试
console.log(
"数据更新完成 - formData.carBaseReqDTO:",
this.data.formData.carBaseReqDTO
);
console.log(
"排放标准 - 更新后的值:",
this.data.formData.carBaseReqDTO.emissionStandard,
"类型:",
typeof this.data.formData.carBaseReqDTO.emissionStandard,
"名称:",
this.data.formData.carBaseReqDTO.emissionStandardName
);
// 手动计算排放标准的索引用于对比
const emissionStandardList = [
{ name: "国3", value: "3" },
{ name: "国4", value: "4" },
{ name: "国5", value: "5" },
{ name: "国6", value: "6" },
];
const currentEmissionValue = String(
this.data.formData.carBaseReqDTO.emissionStandard
);
const calculatedIndex = emissionStandardList.findIndex(
(item) => String(item.value) === currentEmissionValue
);
console.log(
"排放标准 - 手动计算的索引:",
calculatedIndex,
"当前值:",
currentEmissionValue,
"选项列表:",
emissionStandardList
);
});
},
// 根据 key 获取图片名称
......
......@@ -64,8 +64,10 @@
<!-- 可滚动的内容区域 -->
<scroll-view
id="scrollView"
class="scroll-content"
scroll-y
scroll-top="{{scrollTop}}"
>
<!-- 第一步:车辆信息 -->
<first-step
......
......@@ -93,6 +93,9 @@ Component({
report: true,
other: true,
},
// 视频播放弹窗
showVideoPopup: false,
videoUrl: "",
// 车辆图片
uploadFields: [
{
......@@ -223,12 +226,55 @@ Component({
const { key, label } = event.currentTarget.dataset;
const { file, files } = event.detail;
// 支持批量上传:如果 files 存在且长度大于 0,使用 files;否则使用单个 file
const filesToUpload =
files && files.length > 0 ? files : file ? [file] : [];
console.log("handleUpload - event.detail:", event.detail);
console.log("handleUpload - file:", file);
console.log("handleUpload - files:", files);
// 支持批量上传:优先使用 files,如果 files 为空则使用 file
let filesToUpload = [];
// 递归展平数组的辅助函数
const flattenArray = (arr) => {
let result = [];
for (let item of arr) {
if (Array.isArray(item)) {
result = result.concat(flattenArray(item));
} else if (item && typeof item === "object") {
result.push(item);
}
}
return result;
};
// 优先处理 files(multiple 模式)
if (files && files.length > 0) {
filesToUpload = flattenArray(files);
console.log("handleUpload - 展平后的 files:", filesToUpload);
}
// 如果 files 为空或无效,尝试使用 file(single 模式)
if (filesToUpload.length === 0 && file) {
// 如果 file 是数组,展平它
if (Array.isArray(file)) {
filesToUpload = flattenArray(file);
} else if (file && typeof file === "object") {
filesToUpload = [file];
}
console.log("handleUpload - 使用 file,filesToUpload:", filesToUpload);
}
// 过滤掉无效的文件对象
filesToUpload = filesToUpload.filter(
(f) => f && typeof f === "object" && (f.url || f.path || f.tempFilePath)
);
console.log("开始上传,key:", key, "files:", filesToUpload);
if (filesToUpload.length === 0) {
console.warn("没有有效的文件需要上传");
return;
}
// 批量上传文件(顺序上传,避免索引冲突)
filesToUpload.forEach((fileItem) => {
this.uploadSingleFile(fileItem, key, label);
......@@ -237,10 +283,41 @@ Component({
// 上传单个文件
uploadSingleFile(file, key, label) {
// 如果 file 是数组,取第一个元素
if (Array.isArray(file)) {
if (file.length === 0) {
console.error("文件数组为空");
return;
}
file = file[0];
}
// 检查 file 是否为有效对象
if (!file || typeof file !== "object") {
console.error("文件对象无效:", file);
return wx.showToast({
title: "文件对象错误",
icon: "none",
});
}
// 先将文件添加到列表(显示上传中状态)
const { imageList } = this.data;
const currentList = imageList[key] || [];
const ext = file.url.split(".").pop();
// 兼容 van-uploader 的文件对象:可能使用 url、path 或 tempFilePath
const filePath = file.url || file.path || file.tempFilePath;
if (!filePath) {
console.error("文件路径不存在:", file);
console.error("文件对象详情:", JSON.stringify(file, null, 2));
return wx.showToast({
title: "文件路径错误",
icon: "none",
});
}
// 获取文件扩展名
const ext = filePath.split(".").pop()?.toLowerCase() || "unknown";
const fileType = ["mp4", "mov", "avi", "m4v", "3gp"].includes(ext)
? "video"
: "image";
......@@ -265,6 +342,7 @@ Component({
// 添加上传中的文件到列表
const uploadingFile = {
...file,
url: filePath, // 确保 url 字段存在
status: "uploading",
message: "上传中...",
};
......@@ -279,7 +357,7 @@ Component({
const uploadType = ext === "unknown" ? "jpg" : ext;
// 读取文件为 base64
wx.getFileSystemManager().readFile({
filePath: file.url,
filePath: filePath,
encoding: "base64",
success: (res) => {
const base64Data = `${uploadType}@${res.data}`;
......@@ -620,28 +698,69 @@ Component({
if (doneFiles.length === 0) return;
// 构建预览数据源
const media = doneFiles.map((item) => {
if (item.isVideo) {
return {
url: item.url,
type: "video",
poster: item.coverUrl || item.thumb || "",
};
// 找到当前文件
const currentFile = doneFiles.find((item) => item.url === fileUrl);
if (!currentFile) return;
// 判断是否为视频文件
const isVideo = currentFile.isVideo || false;
if (isVideo) {
// 视频预览:判断是否是企业微信环境
const sysInfo = wx.getSystemInfoSync();
if (sysInfo.environment === "wxwork") {
// 企业微信环境,使用自定义弹窗播放视频
this.setData({
showVideoPopup: true,
videoUrl: currentFile.url,
});
} else {
return {
url: item.url,
type: "image",
};
}
});
// 微信环境,使用 wx.previewMedia
// 构建预览数据源
const media = doneFiles.map((item) => {
if (item.isVideo) {
return {
url: item.url,
type: "video",
poster: item.coverUrl || item.thumb || "",
};
} else {
return {
url: item.url,
type: "image",
};
}
});
// 找到当前文件在 doneFiles 中的索引
const currentIndex = doneFiles.findIndex((item) => item.url === fileUrl);
// 找到当前文件在 doneFiles 中的索引
const currentIndex = doneFiles.findIndex(
(item) => item.url === fileUrl
);
wx.previewMedia({
sources: media,
current: currentIndex >= 0 ? currentIndex : 0,
wx.previewMedia({
sources: media,
current: currentIndex >= 0 ? currentIndex : 0,
});
}
} else {
// 图片预览
const imageUrls = doneFiles
.filter((item) => !item.isVideo)
.map((item) => item.url);
const currentIndex = imageUrls.findIndex((url) => url === fileUrl);
wx.previewImage({
current: fileUrl,
urls: imageUrls,
});
}
},
// 关闭视频播放弹窗
onCloseVideoPopup() {
this.setData({
showVideoPopup: false,
videoUrl: "",
});
},
......@@ -657,44 +776,59 @@ Component({
const currentList = imageList[key] || [];
// 判断是否为视频文件
// 兼容 van-uploader 的文件对象:可能使用 url、path 或 tempFilePath
const filePath = file.url || file.path || file.tempFilePath;
const isVideo =
file.isVideo ||
(file.url &&
(filePath &&
["mp4", "mov", "avi", "m4v", "3gp"].includes(
file.url.split(".").pop()?.toLowerCase()
filePath.split(".").pop()?.toLowerCase()
));
if (isVideo) {
// 对于视频文件,使用 wx.previewMedia 预览
// 构建预览数据源(只包含已完成上传的文件)
const doneFiles = currentList.filter((item) => item.status === "done");
const sources = doneFiles.map((item) => {
if (item.isVideo) {
return {
url: item.url,
type: "video",
poster: item.coverUrl || item.thumb || "",
};
} else {
return {
url: item.url,
type: "image",
};
}
});
// 找到当前文件在已完成文件列表中的索引
const currentIndex = doneFiles.findIndex(
(item) =>
item.url === file.url ||
(item.isVideo && file.isVideo && item.url === file.url)
);
if (sources.length > 0) {
wx.previewMedia({
sources: sources,
current: currentIndex >= 0 ? currentIndex : index || 0,
// 判断是否是企业微信环境
const sysInfo = wx.getSystemInfoSync();
if (sysInfo.environment === "wxwork") {
// 企业微信环境,使用自定义弹窗播放视频
const videoUrl = file.url || file.path || file.tempFilePath;
this.setData({
showVideoPopup: true,
videoUrl: videoUrl,
});
} else {
// 微信环境,使用 wx.previewMedia 预览
// 构建预览数据源(只包含已完成上传的文件)
const doneFiles = currentList.filter(
(item) => item.status === "done"
);
const sources = doneFiles.map((item) => {
if (item.isVideo) {
return {
url: item.url,
type: "video",
poster: item.coverUrl || item.thumb || "",
};
} else {
return {
url: item.url,
type: "image",
};
}
});
// 找到当前文件在已完成文件列表中的索引
const currentIndex = doneFiles.findIndex(
(item) =>
item.url === file.url ||
(item.isVideo && file.isVideo && item.url === file.url)
);
if (sources.length > 0) {
wx.previewMedia({
sources: sources,
current: currentIndex >= 0 ? currentIndex : index || 0,
});
}
}
}
// 对于图片文件,让 van-uploader 自己处理预览
......
{
"component": true,
"usingComponents": {
"van-uploader": "@vant/weapp/uploader/index"
"van-uploader": "@vant/weapp/uploader/index",
"video-player-popup": "../VideoPlayerPopup/VideoPlayerPopup"
}
}
Component({
properties: {
show: {
type: Boolean,
value: false,
},
videoUrl: {
type: String,
value: '',
},
},
data: {},
methods: {
onClose() {
this.setData({
show: false,
});
this.triggerEvent('close');
},
preventMove() {
// 阻止滚动穿透
return false;
},
onPlay() {
// 视频开始播放
},
onError(e) {
console.error('视频播放错误:', e);
wx.showToast({
title: '视频播放失败',
icon: 'none',
});
},
},
});
<view class="video-player-popup" wx:if="{{show}}" catchtouchmove="preventMove">
<view class="popup-mask" bindtap="onClose"></view>
<view class="popup-content">
<view class="popup-header">
<view class="popup-title">视频播放</view>
<view class="close-btn" bindtap="onClose">
<text class="close-icon">×</text>
</view>
</view>
<view class="video-wrapper">
<video
src="{{videoUrl}}"
controls
show-center-play-btn="{{true}}"
class="video-player"
bindplay="onPlay"
binderror="onError"
></video>
</view>
</view>
</view>
.video-player-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
}
.popup-mask {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.7);
}
.popup-content {
position: relative;
width: 90%;
max-width: 750rpx;
background-color: #000;
border-radius: 16rpx;
overflow: hidden;
z-index: 10000;
}
.popup-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 32rpx;
background-color: #000;
}
.popup-title {
font-size: 32rpx;
font-weight: 500;
color: #fff;
}
.close-btn {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.close-icon {
font-size: 48rpx;
color: #fff;
line-height: 1;
}
.video-wrapper {
width: 100%;
padding-bottom: 56.25%; /* 16:9 比例 */
position: relative;
background-color: #000;
}
.video-player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
......@@ -345,6 +345,8 @@ Page({
hasAnyReportImage: false,
hasAnyOtherImage: false,
hasCarHandoverInfoImage: false,
showVideoPopup: false,
videoUrl: "",
imageDataMap: {},
videoProcess: "?x-oss-process=video/snapshot,t_1000,f_jpg,w_0,h_0,m_fast",
shouldShowTwoColumns: false,
......@@ -526,18 +528,37 @@ Page({
urls: [url],
});
} else if (type === 2 || type === "2") {
// 视频预览 - 可以使用wx内置的视频播放或自定义页面
wx.previewMedia({
sources: [
{
url: url,
type: "video",
},
],
});
// 视频预览
// 判断是否是企业微信环境
const sysInfo = wx.getSystemInfoSync();
if (sysInfo.environment) {
// 企业微信环境,使用自定义弹窗播放
this.setData({
showVideoPopup: true,
videoUrl: url,
});
} else {
// 微信环境,使用 wx.previewMedia
wx.previewMedia({
sources: [
{
url: url,
type: "video",
},
],
});
}
}
},
// 关闭视频播放弹窗
onCloseVideoPopup() {
this.setData({
showVideoPopup: false,
videoUrl: "",
});
},
// 构建图片数据映射表
buildImageDataMap() {
if (!this.data.detailsInfo || !this.data.detailsInfo.images) {
......
{
"usingComponents": {
"timeline": "../components/timeline/timeline",
"changePopup": "../components/changePopup/changePopup"
"changePopup": "../components/changePopup/changePopup",
"videoPlayerPopup": "../components/VideoPlayerPopup/VideoPlayerPopup"
},
"navigationStyle": "custom",
"navigationBarTitleText": "评估单详情"
......
......@@ -257,6 +257,9 @@
</view>
<view class="car-number mr-4 mb-8">{{ evalOrderDetails.mileageStr }}</view>
<view class="car-number mb-8">{{ evalOrderDetails.transferCountStr }}</view>
<view class="car-number mb-8">
{{ vehicleCategoryMap[evalOrderDetails.vehicleCategory] || evalOrderDetails.vehicleCategory }}
</view>
</view>
<view>
<view class="flex align-center">
......@@ -572,7 +575,7 @@
<view class="tab-panel-title">车辆图片</view>
<view class="upload-grid">
<block wx:for="{{uploadFieldsItems}}" wx:key="index" wx:for-item="item">
<view wx:if="{{ utils.getValueByPath(detailsInfo, item.key) }}" class="flex upload-item-container {{item.fullWidth ? 'full-width' : ''}}">
<view wx:if="{{ !utils.isValueEmpty(detailsInfo, item.key) }}" class="flex upload-item-container {{item.fullWidth ? 'full-width' : ''}}">
<view class="upload-label">{{ item.label }}</view>
<view class="upload-images-wrapper">
<!-- handoverPhotoMore可能有多张图片 -->
......@@ -599,7 +602,7 @@
<view class="tab-panel-title">证件资料</view>
<view class="upload-grid">
<block wx:for="{{documentationItems}}" wx:key="index" wx:for-item="item">
<view wx:if="{{ utils.getValueByPath(detailsInfo, item.key) }}" class="flex upload-item-container {{item.fullWidth ? 'full-width' : ''}}">
<view wx:if="{{ !utils.isValueEmpty(detailsInfo, item.key) }}" class="flex upload-item-container {{item.fullWidth ? 'full-width' : ''}}">
<view class="upload-label">
{{ item.label === '自定义字段名称' ? (detailsInfo.carHandoverInfo.otherText || '自定义字段名称') : item.label }}
</view>
......@@ -698,4 +701,6 @@
</scroll-view>
<!-- 变更项弹窗 -->
<changePopup show="{{showChangePopup}}" title="变更内容" changes="{{currentChangeList}}" bindconfirm="confirmChangePopup" singleButton="{{true}}" confirmText="关闭" height="70%"></changePopup>
<!-- 视频播放弹窗(企微环境使用) -->
<videoPlayerPopup show="{{showVideoPopup}}" videoUrl="{{videoUrl}}" bindclose="onCloseVideoPopup"></videoPlayerPopup>
</view>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!