src/views/CNAS/systemManagement/customerSatisfaction/components/formDialog.vue
@@ -136,6 +136,17 @@
            </el-input>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>照片:</p>
          </td>
          <td class="td-info" colspan="5">
            <lims-attachment ref="photoAttachment" inline defer-upload accept=".jpg,.jpeg,.png,.gif"
              :main-id="form.clientSatisfactionId || ''" upload-url="/clientSatisfaction/uploadAttachment"
              select-url="/clientSatisfaction/selectAttachments" delete-url="/clientSatisfaction/deleteAttachment"
              id-param="clientSatisfactionId" tip="支持 jpg / png / gif 照片,可预览,提交时一并上传"></lims-attachment>
          </td>
        </tr>
      </table>
      <template #footer><span  class="dialog-footer">
        <el-button @click="closeFormDia">取 消</el-button>
@@ -151,10 +162,11 @@
  updateClientSatisfaction
} from '@/api/cnas/systemManagement/customerSatisfaction.js'
import { selectCompletedOrders } from '@/api/business/productOrder'
import limsAttachment from '@/components/Attachment/lims-attachment.vue'
export default {
  name: 'formDialog',
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  components: { limsAttachment },
  data() {
    // 这里存放数据
    return {
@@ -287,24 +299,45 @@
      }
      if (this.operationType === 'add') {
        addClientSatisfaction(payload).then(res => {
          this.editLoad = false
          this.$message.success('提交成功')
          this.closeFormDia()
          // 后端返回保存后的记录(含自增id),用于把新增时暂存的照片传上去
          const savedId = res.data && res.data.clientSatisfactionId
          this.finishSave(savedId)
        }).catch(err => {
          console.log('err---', err);
          this.editLoad = false
        })
      } else {
        updateClientSatisfaction(payload).then(res => {
          this.editLoad = false
          this.$message.success('提交成功')
          this.closeFormDia()
        updateClientSatisfaction(payload).then(() => {
          this.finishSave(this.form.clientSatisfactionId)
        }).catch(err => {
          console.log('err---', err);
          this.editLoad = false
        })
      }
    },
    // 记录保存成功后上传暂存照片;照片上传失败不影响记录本身
    finishSave(clientSatisfactionId) {
      this.uploadPendingPhotos(clientSatisfactionId).then(() => {
        this.editLoad = false
        this.$message.success('提交成功')
        this.closeFormDia()
      }).catch(err => {
        console.log('照片上传失败', err)
        this.editLoad = false
        this.$message.warning('记录已保存,但照片上传失败,请回到列表用“附件”补充上传')
        this.closeFormDia()
      })
    },
    uploadPendingPhotos(clientSatisfactionId) {
      const attachment = this.$refs.photoAttachment
      if (!attachment || !attachment.pendingFiles.length) {
        return Promise.resolve()
      }
      if (!clientSatisfactionId) {
        return Promise.reject(new Error('未获取到记录id,无法上传照片'))
      }
      return attachment.flushPending(clientSatisfactionId)
    },
    closeFormDia() {
      this.formDia = false;
      this.$emit('closeFormDia')