yuyu
2023-08-30 867849a70abe49517a648343f8f8a684a12f73bd
src/views/experiment/checkTheReport/index.vue
@@ -30,7 +30,7 @@
        </el-form-item>
      </el-form>
      <el-form>
        <el-button class="rightBtn" type="primary" icon="el-icon-document"
        <el-button @click="exportToPDF" class="rightBtn" type="primary" icon="el-icon-document"
          >导出报告</el-button
        >
      </el-form>
@@ -61,7 +61,7 @@
        </span>
        <div class="printStyle">
          <Preview id="printRaw" :reportData="reportData" v-if="reportType===0"></Preview>
          <TestReport id="printFinished" :reportData="reportData" v-else></TestReport>
          <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-else></TestReport>
        </div>
      </el-dialog>
      <div class="table-box">
@@ -77,6 +77,7 @@
            textAlign: 'center',
          }"
          :data="reportTable"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <el-table-column type="selection" label="" min-width="5%" />
@@ -176,6 +177,19 @@
        </div>
      </div>
    </div>
    <Preview ref="preview" id="printRaw" :reportData="reportData" v-show="false"></Preview>
    <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-show="false"></TestReport>
    <el-dialog
      title="导出pdf"
      :visible.sync="dialogPdfVisible"
      width="30%"
      :before-close="handleClose">
      <span>确定开始导出吗?</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogPdfVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmExport">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
@@ -184,6 +198,8 @@
import Preview from "@/components/experiment/checkTheReport/index.vue";
import TestReport from "@/components/experiment/template_testReport/index.vue"
import PrintJS from 'print-js'
import html2pdf from 'html2pdf.js'
export default {
  data() {
    return {
@@ -220,6 +236,8 @@
      pageSize: 10,
      checked: true,
      dialogVisible: false,
      dialogPdfVisible: false,
      selectedRows: []
    };
  },
  created() {
@@ -244,6 +262,28 @@
      this.reportType = row.type;
      this.queryReportByRCode(row.reportCode);
    },
    handleSelectionChange(selection){
      this.selectedRows = selection;
    },
    // 批量导出报告
    exportToPDF() {
      this.dialogPdfVisible = true;
    },
    // 确认导出模态框
    confirmExport(){
      this.selectedRows.forEach(async row => {
        const element = document.getElementById('printFinished');
        console.log(element)
        // 设置TestReport组件的reportData属性为当前行的报告数据
        const resp = await getReportData({code:row.reportCode});
        this.$nextTick(() => {
          this.$refs.testreport.reportData = resp.data;
          html2pdf().from(element).save(`exported_${row.reportCode}.pdf`);
        });
      });
      this.dialogPdfVisible = false;
      this.selectedRows = [];
    },
    //打印按钮
    printFun(){
      this.dialogVisible = false;