From 7d2c28da41b3a272746d46716a7b28c2c5c30394 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期二, 11 三月 2025 11:07:02 +0800
Subject: [PATCH] gx

---
 src/views/home/components/fangAn/editDietary.vue |   61 ++++++++++++++++++++++++++----
 1 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/src/views/home/components/fangAn/editDietary.vue b/src/views/home/components/fangAn/editDietary.vue
index a7c9e77..ab47e6a 100644
--- a/src/views/home/components/fangAn/editDietary.vue
+++ b/src/views/home/components/fangAn/editDietary.vue
@@ -1,8 +1,8 @@
 <template>
     <div class="dietarySurvey-item">
         <el-dialog v-model="state.dialogTableVisible" title="营养饮食指导方案" :fullscreen="true" width="100%">
-            <div class="container" style="width: 100%; height: 100%;overflow: auto;" >
-                <div id="fanganprintFrom1" class="print-section">
+            <div  style="width: 100%; height: 100%;overflow: auto;" >
+                <div ref="printRef" id="fanganprintFrom1" class="print-section">
                     <div>
                         <el-form size="small">
                             <div style="width: 100%">
@@ -609,18 +609,18 @@
                     <el-button type="primary" @click="onSubmit">
                         保存
                     </el-button>
-                    <el-button v-if="state.viewInfo.id" type="primary" v-print="'#fanganprintFrom1'">
+                    <el-button v-if="state.viewInfo.id" type="primary" @click="onPrint">
                         <el-icon>
                             <Printer />
                         </el-icon>
                         打印
                     </el-button>
-                    <el-button type="primary" v-if="state.viewInfo.id" @click="generatePDF">
+                    <!-- <el-button type="primary" v-if="state.viewInfo.id" @click="generatePDF">
                         <el-icon>
                             <Position />
                         </el-icon>
                         导出
-                    </el-button>
+                    </el-button> -->
 
                 </div>
             </template>
@@ -656,6 +656,7 @@
 import html2pdf from 'html2pdf.js';
 import html2canvas from 'html2canvas';
 import { jsPDF } from 'jspdf';
+import printJs from 'print-js';
 import { reactive, onMounted, onUnmounted, ref,computed} from 'vue';
 import { formatDate } from '/@/utils/formatTime';
 import { NextLoading } from '/@/utils/loading';
@@ -671,6 +672,8 @@
 const { patientsInfo } = storeToRefs(storesPat);
 const { userInfos } = storeToRefs(stores);
 const router = useRouter()
+// 定义变量内容
+const printRef = ref();
 const emit = defineEmits(["shuaxin"]);
 const state = reactive({
     centerDialogVisibleYZDBZ:false,
@@ -824,6 +827,50 @@
     }
 
 })
+// 打印
+const onPrint=()=>{
+    printJs({
+		printable: printRef.value,
+		type: 'html',
+		css: ['@/assets/css/printcss.css','//at.alicdn.com/t/c/font_2298093_rnp72ifj3ba.css', '//unpkg.com/element-plus/dist/index.css'],
+		scanStyles: false,
+		style: `@media print{.gridtable {
+    font-family: verdana, arial, sans-serif;
+
+    color: #333333;
+    border-width: 1px;
+    border-color: #666666;
+    border-collapse: collapse;
+    
+}
+
+.gridtable th {
+    border-width: 1px;
+    padding: 8px;
+    border-style: solid;
+    border-color: #666666;
+    background-color: #a4b0e2;
+}
+
+.gridtable td {
+    border-width: 1px;
+    padding: 8px;
+    border-style: solid;
+    border-color: #666666;
+    text-align: center;
+}
+
+.htr {
+    background-color: rgb(250, 236, 216);
+    font-weight: 800;
+
+}
+
+.lvse {
+    background-color: rgb(239.8, 248.9, 235.3);
+}}}`,
+	});
+}
 const numberPart=(str:any)=>{
     if(str){
          // 使用正则表达式匹配数字
@@ -933,10 +980,6 @@
 }
 const funhui = () => {
     state.dialogTableVisible = false
-}
-// 打印
-const onPrint = () => {
-
 }
 const generatePDF = () => {
     const element = document.getElementById('fanganprintFrom1');

--
Gitblit v1.8.0