吴羡
3 天以前 dc7c01777e52cb61c618f45c0da0cdca697ff166
src/views/CNAS/resourceDemand/device/component/equipmentVerificationPlan.vue
@@ -202,10 +202,15 @@
      </span></template>
    </el-dialog>
    <el-dialog v-model="downloadDialog" title="导出" width="600px">
      <span>
        <el-button :loading="outLoading" plain type="primary" @click="controlDown">核查记录</el-button>
        <el-button :loading="outLoading" plain type="primary" @click="processingDown">核查比对记录</el-button>
      </span>
      <div class="down-row">
        <span>1、仪器设备期间核查记录表(核查记录)</span>
        <el-button type="primary" :loading="outLoading" :disabled="!downRow.recordStatus" @click="controlDown">导 出</el-button>
      </div>
      <div class="down-row">
        <span>2、仪器设备期间核查比对记录表(比对记录)</span>
        <el-button type="primary" :loading="outLoading" :disabled="!downRow.recordContrastStatus" @click="processingDown">导 出</el-button>
      </div>
      <div class="down-tip">置灰表示对应记录尚未录入(状态为"未开始"),请先点"记录"/"对比"录入后再导出</div>
      <template #footer><span  class="dialog-footer">
        <el-button @click="downloadDialog = false">取 消</el-button>
      </span></template>
@@ -596,13 +601,32 @@
      this.downRow = row
      this.downloadDialog = true
    },
    // 导出结果拦截: 后端返回错误 JSON 时提示错误, 不存成坏文件
    saveDocx(res, filename) {
      const reader = new FileReader();
      reader.readAsText(res, 'utf-8');
      reader.onload = () => {
        const text = (reader.result || '').trim();
        if (text.startsWith('{') || text.startsWith('[')) {
          let msg = '导出失败';
          try { msg = JSON.parse(text).msg || msg; } catch (e) {}
          this.$message.error(msg);
        } else {
          this.$download.saveAs(new Blob([res], { type: 'application/msword' }), filename);
        }
      };
      reader.onerror = () => {
        this.$download.saveAs(new Blob([res], { type: 'application/msword' }), filename);
      };
    },
    // 核查记录导出
    controlDown() {
      this.outLoading = true
      exportReviewExamineRecordDetail({ planDetailsId: this.downRow.planDetailsId }).then(res => {
        this.outLoading = false
        const blob = new Blob([res], { type: 'application/octet-stream' });
        this.$download.saveAs(blob, '仪器设备期间核查记录表.doc')
        this.saveDocx(res, '仪器设备期间核查记录表.doc')
      }).catch(() => {
        this.outLoading = false
      })
    },
    // 核查对比导出
@@ -610,8 +634,9 @@
      this.outLoading = true
      exportReviewExamineRecordContrast({ planDetailsId: this.downRow.planDetailsId }).then(res => {
        this.outLoading = false
        const blob = new Blob([res], { type: 'application/octet-stream' });
        this.$download.saveAs(blob, '仪器设备期间核查比对记录表.doc')
        this.saveDocx(res, '仪器设备期间核查比对记录表.doc')
      }).catch(() => {
        this.outLoading = false
      })
    },
    // 导入流程
@@ -693,4 +718,18 @@
  background-color: var(--el-color-primary);
  border-radius: 2px;
}
.down-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid #ebeef5;
}
.down-tip {
  margin-top: 10px;
  color: #909399;
  font-size: 12px;
}
</style>