From 7114476c50f620866d81de90b96dbffb38d0d648 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期五, 06 二月 2026 13:24:50 +0800
Subject: [PATCH] 出库逻辑微调

---
 rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx |   57 +++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx b/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx
index f618577..4ae47d3 100644
--- a/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx
+++ b/rsf-admin/src/page/basicInfo/matnr/PrintModal.jsx
@@ -60,8 +60,24 @@
     const refresh = useRefresh();
     const translate = useTranslate();
     const notify = useNotify();
-    const contentRef = useRef(null);
-    const reactToPrintFn = useReactToPrint({ contentRef });
+    const contentRef = useRef();
+    const reactToPrintFn = useReactToPrint({
+        content: () => {
+            return contentRef.current
+        },
+        documentTitle: `鐗╂枡淇℃伅`,
+        pageStyle: `
+        @page {
+            
+            margin: 10mm;
+        }
+        @media print {
+             html, body {
+                width: 70mm;     // A4妯悜瀹藉害
+                height: 40mm;    // A4妯悜楂樺害
+            }
+        }`
+    });
 
     const handleClose = (event, reason) => {
         if (reason !== "backdropClick") {
@@ -210,14 +226,6 @@
                 }
             }))
             setData(val)
-            setTimeout(() => {
-                val.forEach((el) => {
-                    jsbarcode(`#barcode${el.code}`, el.code, { height: 30 });
-                });
-            }, 10);
-
-
-
         } else {
             notify(res.data.msg);
         }
@@ -227,8 +235,26 @@
         if (rows?.length > 0) {
             http();
         }
-
     }, [rows]);
+
+    // 鍦ㄦ暟鎹洿鏂板悗鐢熸垚鏉$爜
+    useEffect(() => {
+        if (data.length > 0) {
+            // 绛夊緟DOM鏇存柊鍚庡啀鐢熸垚鏉$爜
+            setTimeout(() => {
+                data.forEach((item) => {
+                    const barcodeElement = document.getElementById(`barcode${item.code}`);
+                    if (barcodeElement) {
+                        try {
+                            jsbarcode(`#barcode${item.code}`, item.code, { height: 30 });
+                        } catch (error) {
+                            console.error(`鐢熸垚鏉$爜澶辫触: ${item.code}`, error);
+                        }
+                    }
+                });
+            }, 100);
+        }
+    }, [data]);
 
 
     return (
@@ -241,7 +267,7 @@
                         overflow: 'hidden',
                         fontSize: 'small',
                         tableLayout: 'fixed',
-                        width: '280px',
+                        width: '520px',
                         borderCollapse: 'collapse',
                         borderSpacing: 0,
                         margin: '0 auto',
@@ -259,11 +285,10 @@
                                 colSpan={9}
                                 style={{ border: '1px solid black' }}
                             >
-                                <img id={"barcode" + item.code} style={{ width: '70%', verticalAlign: 'middle' }} />
-                                {/* <img className="template-code" src={item.barcode} style={{ width: '90%', verticalAlign: 'middle' }} alt="Barcode" /> */}
-                                {/* <div style={{ letterSpacing: '2px', marginTop: '1px', textAlign: 'center' }}>
+                                <img id={`barcode${item.code}`} style={{ width: '90%', verticalAlign: 'middle' }} alt="Barcode" />
+                                <div style={{ letterSpacing: '2px', marginTop: '1px', textAlign: 'center' }}>
                                     <span>{item.code}</span>
-                                </div> */}
+                                </div>
                             </td>
                         </tr>
                         <tr style={{ height: '74px' }}>

--
Gitblit v1.9.1