|
|
@@ -13,6 +13,8 @@ import {OrderReportApi} from "@/api/pressure2/orderreport";
|
|
|
import {DynamicTbColApi} from "@/api/pressure2/dynamictbcol";
|
|
|
import {SpreadViewer} from "@/components/DynamicReport";
|
|
|
import {InitParams} from "@/components/DynamicReport/SpreadInterface";
|
|
|
+import { Printer, Download } from '@element-plus/icons-vue';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
|
|
const spreadRef=ref();
|
|
|
const props = defineProps({
|
|
|
@@ -118,6 +120,87 @@ const handlePdfRendered = () => {
|
|
|
pdfLoading.value = false
|
|
|
}
|
|
|
|
|
|
+const handlePrint = () => {
|
|
|
+ const spreadInstance = spreadRef.value
|
|
|
+ if (spreadInstance && spreadInstance.reloadView) {
|
|
|
+ // 获取 SpreadViewer 内部的 workbook 实例
|
|
|
+ const workbook = spreadInstance.getWorkbook?.()
|
|
|
+ if (workbook) {
|
|
|
+ workbook.print()
|
|
|
+ } else {
|
|
|
+ ElMessage.warning('请先加载文档')
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage.warning('文档未就绪')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const handleDownload = async () => {
|
|
|
+ try {
|
|
|
+ const spreadInstance = spreadRef.value
|
|
|
+ if (!spreadInstance) {
|
|
|
+ ElMessage.warning('文档未就绪')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const workbook = spreadInstance.getWorkbook?.()
|
|
|
+ if (!workbook) {
|
|
|
+ ElMessage.warning('请先加载文档')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成 PDF blob
|
|
|
+ const formData = new FormData()
|
|
|
+ await new Promise((resolve, reject) => {
|
|
|
+ workbook.save(async (blob) => {
|
|
|
+ try {
|
|
|
+ formData.append('file', blob)
|
|
|
+ const response = await getPDF(formData)
|
|
|
+ if (response) {
|
|
|
+ // 创建下载链接
|
|
|
+ const pdfBlob = new Blob([response], { type: 'application/pdf' })
|
|
|
+ const url = window.URL.createObjectURL(pdfBlob)
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.href = url
|
|
|
+
|
|
|
+ // 生成文件名
|
|
|
+ const fileName = order?.acceptOrderId
|
|
|
+ ? `服务单_${order.acceptOrderId}_${new Date().getTime()}.pdf`
|
|
|
+ : `服务单_${new Date().getTime()}.pdf`
|
|
|
+
|
|
|
+ link.download = fileName
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+
|
|
|
+ // 清理
|
|
|
+ document.body.removeChild(link)
|
|
|
+ window.URL.revokeObjectURL(url)
|
|
|
+
|
|
|
+ ElMessage.success('下载成功')
|
|
|
+ resolve(true)
|
|
|
+ } else {
|
|
|
+ ElMessage.error('下载失败')
|
|
|
+ reject(new Error('生成PDF失败'))
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('下载失败:', error)
|
|
|
+ ElMessage.error('下载失败')
|
|
|
+ reject(error)
|
|
|
+ }
|
|
|
+ }, (error) => {
|
|
|
+ console.error('保存失败:', error)
|
|
|
+ ElMessage.error('生成文件失败')
|
|
|
+ reject(error)
|
|
|
+ }, {
|
|
|
+ includeBindingSource: true
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('下载异常:', error)
|
|
|
+ ElMessage.error('下载异常')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// watch(() => showOrder.value, async (newOrder) => {
|
|
|
// console.log(1)
|
|
|
// await initPreview()
|
|
|
@@ -151,6 +234,16 @@ defineExpose({
|
|
|
|
|
|
<template>
|
|
|
<el-dialog v-model="showOrder" title="服务单/受理单PDF">
|
|
|
+ <div class="dialog-header-actions">
|
|
|
+ <el-button type="primary" @click="handlePrint">
|
|
|
+ <el-icon><Printer /></el-icon>
|
|
|
+ 打印
|
|
|
+ </el-button>
|
|
|
+ <el-button type="success" @click="handleDownload">
|
|
|
+ <el-icon><Download /></el-icon>
|
|
|
+ 下载
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
<div class="inline-pdf-viewer" ref="pdfViewer">
|
|
|
<!-- PDF查看区域 -->
|
|
|
<div class="pdf-viewer-container" v-loading="pdfLoading">
|
|
|
@@ -185,9 +278,14 @@ defineExpose({
|
|
|
position: relative;
|
|
|
border: 1px solid #CBD1DC;
|
|
|
flex: 1;
|
|
|
- height: 100%;
|
|
|
+ height: calc(100% - 60px);
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
+.dialog-header-actions {
|
|
|
+ padding: 10px 0;
|
|
|
+ border-bottom: 1px solid #e8e8e8;
|
|
|
+ margin-bottom: 10px;
|
|
|
+}
|
|
|
.pdf-header {
|
|
|
position: sticky;
|
|
|
left: 0;
|