ThirdStep.wxml 12.3 KB
<!-- 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>