gaoluyang
2026-06-04 f0f22709fb7f9945e5bc246181e21fd0c282e694
src/pages/inspectionUpload/components/formDia.vue
@@ -50,52 +50,21 @@
        </view>
        
        <!-- 上传区域(仅在异常时显示) -->
        <template v-if="hasException === true">
          <view class="form-container">
            <view class="title">生产前</view>
        <view class="form-container" v-if="hasException === true">
          <view class="title">上传附件</view>
          <text class="upload-count">已上传: {{ fileList.length }}个文件</text>
            <u-upload
              :fileList="beforeModelValue"
            :fileList="fileList"
              @afterRead="afterRead"
              @delete="deleteFile"
              name="before"
            name="attachment"
              multiple
              :maxCount="10"
            :maxCount="30"
              :maxSize="5 * 1024 * 1024"
              accept="image/*"
              :previewFullImage="true"
            ></u-upload>
          </view>
          <view class="form-container">
            <view class="title">生产后</view>
            <u-upload
              :fileList="afterModelValue"
              @afterRead="afterRead"
              @delete="deleteFile"
              name="after"
              multiple
              :maxCount="10"
              :maxSize="5 * 1024 * 1024"
              accept="image/*"
              :previewFullImage="true"
            ></u-upload>
          </view>
          <view class="form-container">
            <view class="title">生产问题</view>
            <u-upload
              :fileList="issueModelValue"
              @afterRead="afterRead"
              @delete="deleteFile"
              name="issue"
              multiple
              :maxCount="10"
              :maxSize="5 * 1024 * 1024"
              accept="image/*"
              :previewFullImage="true"
            ></u-upload>
          </view>
        </template>
        <!-- 正常状态提示 -->
        <view class="form-container normal-tip" v-if="hasException === false">
@@ -121,9 +90,7 @@
const emit = defineEmits(['closeDia'])
const dialogVisitable = ref(false)
const beforeModelValue = ref([])
const afterModelValue = ref([])
const issueModelValue = ref([])
const fileList = ref([])
const infoData = ref(null)
// 异常状态:null=未选择, false=正常, true=异常
@@ -203,29 +170,12 @@
// 文件上传处理
const afterRead = (event) => {
  const { name, file } = event
  // 根据上传类型设置不同的type值
  let typeValue = 10 // 默认值
  if (name === 'before') {
    typeValue = 10 // 生产前
  } else if (name === 'after') {
    typeValue = 11 // 生产中
  } else if (name === 'issue') {
    typeValue = 12 // 生产后
  }
  const { file } = event
  const files = Array.isArray(file) ? file : [file]
  Promise.resolve().then(async () => {
    for (const f of files) {
      const uploaded = await uploadSingleFile(f, typeValue)
      if (name === 'before') {
        beforeModelValue.value.push(uploaded)
      } else if (name === 'after') {
        afterModelValue.value.push(uploaded)
      } else if (name === 'issue') {
        issueModelValue.value.push(uploaded)
      }
      const uploaded = await uploadSingleFile(f, 10)
      fileList.value.push(uploaded)
    }
    uni.showToast({ title: '上传成功', icon: 'success' })
  }).catch((err) => {
@@ -236,15 +186,8 @@
// 删除文件
const deleteFile = (event) => {
  const { name, index } = event
  if (name === 'before') {
    beforeModelValue.value.splice(index, 1)
  } else if (name === 'after') {
    afterModelValue.value.splice(index, 1)
  } else if (name === 'issue') {
    issueModelValue.value.splice(index, 1)
  }
  const { index } = event
  fileList.value.splice(index, 1)
}
// 设置异常状态
@@ -266,8 +209,7 @@
    // 如果是异常状态,检查是否有上传文件
    if (hasException.value === true) {
      const totalFiles = beforeModelValue.value.length + afterModelValue.value.length + issueModelValue.value.length
      if (totalFiles === 0) {
      if (fileList.value.length === 0) {
        uni.showToast({
          title: '请上传异常照片',
          icon: 'none'
@@ -284,19 +226,8 @@
      }
    }
    let arr = []
    if (beforeModelValue.value.length > 0) {
      arr.push(...beforeModelValue.value.map(item => ({ ...item, statusType: 0 })))
    }
    if (afterModelValue.value.length > 0) {
      arr.push(...afterModelValue.value.map(item => ({ ...item, statusType: 1 })))
    }
    if (issueModelValue.value.length > 0) {
      arr.push(...issueModelValue.value.map(item => ({ ...item, statusType: 2 })))
    }
    // 提交数据
    infoData.value.storageBlobDTO = arr
    infoData.value.commonFileListDTO = fileList.value
    infoData.value.hasException = hasException.value
    infoData.value.exceptionDescription = exceptionDescription.value
    await submitInspectionRecord({ ...infoData.value })
@@ -322,9 +253,7 @@
  dialogVisitable.value = true
  
  // 清空之前的数据
  beforeModelValue.value = []
  afterModelValue.value = []
  issueModelValue.value = []
  fileList.value = []
  hasException.value = null
  exceptionDescription.value = ''
}
@@ -373,6 +302,14 @@
  }
}
.upload-count {
  display: block;
  font-size: 12px;
  color: #999;
  margin-bottom: 8px;
  padding-left: 10px;
}
.title {
  font-size: 14px;
  color: #1890ff;