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>
@@ -51,6 +51,19 @@
          >
        </div>
      </div>
      <el-dialog
        top="10vh"
        title="报告预览"
        :visible.sync="dialogVisible"
        width="60%">
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="printFun()">打印</el-button>
        </span>
        <div class="printStyle">
          <Preview id="printRaw" :reportData="reportData" v-if="reportType===0"></Preview>
          <TestReport ref="testreport" id="printFinished" :reportData="reportData" v-else></TestReport>
        </div>
      </el-dialog>
      <div class="table-box">
        <el-table
          ref="reportTable"
@@ -64,6 +77,7 @@
            textAlign: 'center',
          }"
          :data="reportTable"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <el-table-column type="selection" label="" min-width="5%" />
@@ -81,14 +95,14 @@
            </template></el-table-column
          >
          <el-table-column
            prop="materialCode"
            prop="reportCode"
            label="报告单号"
            sortable
            min-width="10%"
          >
            <template slot-scope="scope">
              <span style="color: #409eff;">
                  {{ scope.row.materialCode }}
                  {{ scope.row.reportCode }}
              </span>
            </template></el-table-column
          >
@@ -143,10 +157,9 @@
              <el-button
                type="text"
                size="small"
                @click="handleClick(scope.row)"
                >预览</el-button
                @click="previewFun(scope.row)"
                >查看报告</el-button
              >
              <el-button type="text" size="small">打印</el-button>
            </template>
          </el-table-column>
        </el-table>
@@ -164,31 +177,124 @@
        </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>
<script>
import { selectAllReport } from "@/api/experiment/checkTheReport";
import { selectAllReport,getReportData } from "@/api/experiment/checkTheReport";
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 {
      reportData: [],
      reportType: 0,
      searchData:{
        sample_code:'',
        reportCode:'',
        application_code: ''
      },
      checkStatus: undefined,
      reportTable: [],
      reportTable: [
        {
          materialCode:'SN23-0517001',
          reportCode: 'SN23-0517001',
          inspectionCode: 'SN23-0517001',
          approver:'黄小明',
          status: '',
          conclusion: 1,
          name: '黄小明'
        },
        {
          materialCode:'SN23-0517001',
          reportCode: 'SN23-0517001',
          inspectionCode: 'SN23-0517001',
          approver:'黄小明',
          status: '',
          conclusion: 1,
          name: '黄小明'
        }
      ],
      page: 1,
      total: 0,
      pageSize: 10,
      checked: true,
      dialogVisible: false,
      dialogPdfVisible: false,
      selectedRows: []
    };
  },
  created() {
    this.getData();
    // this.getData();
  },
  mounted(){
  },
  components:{
    Preview,
    TestReport
  },
  methods: {
    async queryReportByRCode(code){
      const resp = await getReportData({code:code});
      this.reportData = resp.data;
      this.dialogVisible = true;
      console.log(this.reportData);
    },
    //查看报告按钮
    previewFun(row){
      console.log(row)
      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;
      PrintJS({
        printable: this.reportType===0 ? "printRaw" : "printFinished",
        type: "html",
        // header: "原材料检测报告",
        targetStyles: ["*"],
        ignoreElements: ["no-ignore"],
      });
    },
    // 状态按钮
    handleRadioChange() {
      this.getData();
@@ -227,6 +333,7 @@
      };
      const { data } = await selectAllReport(params);
      this.reportTable = data.row;
      console.log(data.row);
      this.total = data.total;
    },
  },
@@ -253,6 +360,8 @@
  }
}
.library-table {
  height: 80vh;
  overflow: scroll;
  background-color: #fff;
  flex: 1;
  margin: 0px -15px;
@@ -280,5 +389,14 @@
      margin: 10px 0;
    }
  }
  .printStyle{
    overflow: scroll;
    height:500px;
    .el-button{
      position: absolute;
      top: 10vh;
      left: 90%;
    }
  }
}
</style>