ThirdStep.wxml
12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!-- packageUsedCar/pages/evaluationForm/components/ThirdStep/ThirdStep.wxml -->
<wxs module="utils">
// 图片展示/回显时拼接 OSS 处理参数(视频不处理)
var getImageDisplayUrl = function(url, isVideo) {
if (!url) return url;
if (isVideo) return url;
if (url.indexOf('x-oss-process=') !== -1) return url;
var sep = url.indexOf('?') >= 0 ? '&' : '?';
return url + sep + 'x-oss-process=image/format,jpg/quality,q_100';
};
// 为 file-list 生成展示用 URL(图片带 OSS 参数,视频直链)
var getFileListForDisplay = function(list) {
if (!list || list.length === 0) return [];
var out = [];
for (var i = 0; i < list.length; i++) {
var item = list[i];
var url = item.isVideo ? item.url : getImageDisplayUrl(item.url);
out.push({
url: url,
thumb: item.thumb,
coverUrl: item.coverUrl,
isVideo: item.isVideo,
status: item.status,
name: item.name,
key: item.key,
message: item.message
});
}
return out;
};
// 获取视频封面图 URL:优先 coverUrl,其次 OSS 视频用 snapshot 生成,否则用默认图
var getVideoCoverUrl = function(videoUrl, coverUrl, defaultImg) {
if (coverUrl && coverUrl !== '' && coverUrl.indexOf('.mp4') === -1 && coverUrl.indexOf('.mov') === -1 && coverUrl.indexOf('.avi') === -1) {
return coverUrl;
}
if (videoUrl && videoUrl.indexOf('aliyuncs.com') !== -1) {
var sep = videoUrl.indexOf('?') >= 0 ? '&' : '?';
return videoUrl + sep + 'x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast';
}
return defaultImg || '';
};
// 判断 coverUrl 是否有效(不能是视频文件 URL)
var hasValidCoverUrl = function(coverUrl) {
if (!coverUrl || coverUrl === '' || coverUrl === 'undefined' || coverUrl === 'null') {
return false;
}
// 如果 coverUrl 是视频文件(.mp4, .mov, .avi 等),则认为是无效的封面图
var videoExtensions = ['.mp4', '.mov', '.avi', '.m4v', '.3gp', '.flv', '.wmv'];
var lowerUrl = coverUrl.toLowerCase();
for (var i = 0; i < videoExtensions.length; i++) {
if (lowerUrl.indexOf(videoExtensions[i]) !== -1) {
return false;
}
}
return true;
};
// 计算upload-text
var getUploadText = function(imageList, key, maxCount, defaultText) {
var currentCount = 0;
if (imageList && key != null) {
var fileList = null;
var keyStr = '' + key;
var keyNum = key - 0;
// 按优先级尝试:数字 -> 字符串 -> 原始值
if (imageList[keyNum] != null) {
fileList = imageList[keyNum];
} else if (imageList[keyStr] != null) {
fileList = imageList[keyStr];
} else if (imageList[key] != null) {
fileList = imageList[key];
}
// 获取已完成文件的数量(status === 'done' 或没有 status 字段,说明是编辑回显的数据)
if (fileList && fileList.length != null) {
for (var i = 0; i < fileList.length; i++) {
var file = fileList[i];
if (file) {
// 如果 status 是 'done' 或者没有 status 字段(编辑回显的数据),都计算在内
if (!file.status || file.status === 'done') {
currentCount = currentCount + 1;
}
}
}
}
}
var max = maxCount ? (maxCount - 0) : 1;
if (max > 1) {
return currentCount + '/' + max;
}
return defaultText || '上传照片';
};
// 获取已完成文件的数量
var getDoneCount = function(imageList, key) {
var count = 0;
if (imageList && key != null) {
var fileList = null;
var keyStr = '' + key;
var keyNum = key - 0;
// 按优先级尝试:数字 -> 字符串 -> 原始值
if (imageList[keyNum] != null) {
fileList = imageList[keyNum];
} else if (imageList[keyStr] != null) {
fileList = imageList[keyStr];
} else if (imageList[key] != null) {
fileList = imageList[key];
}
// 计算已完成文件的数量(status === 'done' 或没有 status 字段,说明是编辑回显的数据)
if (fileList && fileList.length != null) {
for (var i = 0; i < fileList.length; i++) {
var file = fileList[i];
if (file) {
// 如果 status 是 'done' 或者没有 status 字段(编辑回显的数据),都计算在内
if (!file.status || file.status === 'done') {
count = count + 1;
}
}
}
}
}
return count;
};
module.exports = {
getUploadText: getUploadText,
getDoneCount: getDoneCount,
hasValidCoverUrl: hasValidCoverUrl,
getVideoCoverUrl: getVideoCoverUrl,
getImageDisplayUrl: getImageDisplayUrl,
getFileListForDisplay: getFileListForDisplay
};
</wxs>
<view class="thirdStep">
<!-- 车辆图片 -->
<view class="box m-b-40">
<view class="title">
<view>车辆图片</view>
<!-- <view class="up-down-box" bindtap="handleUpDown" data-attr="vehicle">
<view class="up-down-arrow">
<view class="arrow-up {{ isShowObj.vehicle ? '' : 'arrow-down' }}"></view>
</view>
</view> -->
</view>
<view wx:if="{{ isShowObj.vehicle }}" class="upload-section">
<view wx:for="{{ uploadFields }}" wx:key="key" class="upload-item {{ item.fullwidth ? 'fullwidth' : '' }}">
<view class="label">
{{ item.label }}
<text wx:if="{{ item.required }}" class="required">*</text>
</view>
<van-uploader class="plus" sizeType="original" file-list="{{ utils.getFileListForDisplay(imageList[item.key] || []) }}" upload-text="{{ utils.getUploadText(imageList, item.key, item.maxCount || 1, '上传照片') }}" max-count="{{ item.maxCount || 1 }}" multiple="{{ (item.maxCount || 1) > 1 }}" deletable preview-size="var(--fontSize192)" bind:after-read="handleUpload" bind:delete="handleDelete" data-key="{{ item.key }}" data-label="{{ item.label }}" />
</view>
</view>
</view>
<!-- 证件图片 -->
<view class="box m-b-40">
<view class="title">
<view>证件资料</view>
<!-- <view class="up-down-box" bindtap="handleUpDown" data-attr="certificate">
<view class="up-down-arrow">
<view class="arrow-up {{ isShowObj.certificate ? '' : 'arrow-down' }}"></view>
</view>
</view> -->
</view>
<view wx:if="{{ isShowObj.certificate }}" class="upload-section">
<view wx:for="{{ uploadCertificateFields }}" wx:key="key" class="upload-item {{ item.fullwidth ? 'fullwidth' : '' }}">
<view class="label">
{{ item.label }}
<text wx:if="{{ item.required }}" class="required">*</text>
</view>
<van-uploader class="plus" sizeType="original" file-list="{{ utils.getFileListForDisplay(imageList[item.key] || []) }}" upload-text="{{ utils.getUploadText(imageList, item.key, item.maxCount || 1, '上传照片') }}" max-count="{{ item.maxCount || 1 }}" multiple="{{ (item.maxCount || 1) > 1 }}" deletable preview-size="var(--fontSize192)" bind:after-read="handleUpload" bind:delete="handleDelete" data-key="{{ item.key }}" data-label="{{ item.label }}" />
</view>
</view>
</view>
<!-- 视频资料 -->
<view class="box m-b-40">
<view class="title">
<view>视频资料</view>
<!-- <view class="up-down-box" bindtap="handleUpDown" data-attr="video">
<view class="up-down-arrow">
<view class="arrow-up {{ isShowObj.video ? '' : 'arrow-down' }}"></view>
</view>
</view> -->
</view>
<view wx:if="{{ isShowObj.video }}" class="upload-section">
<view wx:for="{{ uploadVideoFields }}" wx:key="key" class="upload-item fullwidth">
<view class="label">
{{ item.label }}
<text wx:if="{{ item.required }}" class="required">*</text>
</view>
<view class="upload-images-wrapper">
<!-- 已上传的图片/视频列表 -->
<block wx:for="{{ imageList[item.key] || [] }}" wx:for-item="subItem" wx:for-index="subIndex" wx:key="subIndex">
<view wx:if="{{ !subItem.status || subItem.status === 'done' }}" class="uploaded-image-container">
<!-- 视频 -->
<view wx:if="{{ subItem.isVideo }}" class="video-container" bindtap="previewVideoMedia" data-key="{{ item.key }}" data-file-url="{{ subItem.url }}">
<image src="{{ utils.getVideoCoverUrl(subItem.url, subItem.coverUrl, IMG_URL + 'usedCar/video_default.png') }}" mode="aspectFit"></image>
<view class="video-play-icon">
<image src="{{ IMG_URL }}usedCar/upload-play.png" class="icon-upload-play"></image>
</view>
</view>
<!-- 图片 -->
<image wx:else src="{{ utils.getImageDisplayUrl(subItem.url, subItem.isVideo) }}" mode="aspectFit" class="uploaded-image" bindtap="previewVideoMedia" data-key="{{ item.key }}" data-file-url="{{ subItem.url }}"></image>
<view class="delete-icon" bindtap="handleDelete" data-key="{{ item.key }}" data-index="{{ subIndex }}">
<image src="{{ IMG_URL }}zy_paf_del_icon.png" class="icon-icon-circle-error"></image>
</view>
</view>
</block>
<!-- 上传按钮 -->
<view wx:if="{{ utils.getDoneCount(imageList, item.key) < (item.maxCount || 1) }}" class="upload-item" bindtap="handleVideoUpload" data-field="{{ item }}">
<image src="{{ IMG_URL }}zy-upload_icon.png" class="icon-uploadAdd"></image>
<view class="upload-text">
{{ utils.getUploadText(imageList, item.key, item.maxCount || 1, '上传视频') }}
</view>
</view>
</view>
</view>
</view>
</view>
<!-- 车辆检测报告 -->
<view class="box m-b-40">
<view class="title">
<view>车辆检测报告</view>
<!-- <view class="up-down-box" bindtap="handleUpDown" data-attr="report">
<view class="up-down-arrow">
<view class="arrow-up {{ isShowObj.report ? '' : 'arrow-down' }}"></view>
</view>
</view> -->
</view>
<view wx:if="{{ isShowObj.report }}" class="upload-section">
<view wx:for="{{ uploadReportFields }}" wx:key="key" class="upload-item fullwidth">
<view class="label">
{{ item.label }}
<text wx:if="{{ item.required }}" class="required">*</text>
</view>
<van-uploader class="plus" sizeType="original" file-list="{{ utils.getFileListForDisplay(imageList[item.key] || []) }}" upload-text="{{ utils.getUploadText(imageList, item.key, item.maxCount || 3, '上传照片') }}" max-count="{{ item.maxCount || 3 }}" multiple="{{ (item.maxCount || 3) > 1 }}" deletable preview-size="var(--fontSize192)" bind:after-read="handleUpload" bind:delete="handleDelete" data-key="{{ item.key }}" data-label="{{ item.label }}" />
</view>
</view>
</view>
<!-- 其他图片 -->
<view class="box m-b-40">
<view class="title">
<view>其他图片</view>
<!-- <view class="up-down-box" bindtap="handleUpDown" data-attr="other">
<view class="up-down-arrow">
<view class="arrow-up {{ isShowObj.other ? '' : 'arrow-down' }}"></view>
</view>
</view> -->
</view>
<view wx:if="{{ isShowObj.other }}" class="upload-section">
<view wx:for="{{ uploadOtherFields }}" wx:key="key" class="upload-item fullwidth">
<view class="label">
{{ item.label }}
<text wx:if="{{ item.required }}" class="required">*</text>
</view>
<van-uploader class="plus" file-list="{{ utils.getFileListForDisplay(imageList[item.key] || []) }}" upload-text="{{ utils.getUploadText(imageList, item.key, item.maxCount || 30, '上传照片') }}" max-count="{{ item.maxCount || 30 }}" multiple="{{ (item.maxCount || 30) > 1 }}" deletable preview-size="var(--fontSize192)" bind:after-read="handleUpload" bind:delete="handleDelete" sizeType="original" data-key="{{ item.key }}" data-label="{{ item.label }}" />
</view>
</view>
</view>
<!-- 视频播放弹窗(用于企微环境) -->
<video-player-popup id="videoPlayerPopup" show="{{showVideoPopup}}" videoUrl="{{videoUrl}}" bindclose="onCloseVideoPopup"></video-player-popup>
</view>