From fc1a5059e586ab6d41fc3ec3bfacb727accc4765 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期一, 15 十二月 2025 14:52:02 +0800
Subject: [PATCH] 核磅录入打印装箱单

---
 pages/wareHouse/nuclearScale/nuclearscalerecord.vue |  278 +++++++++++++++++++------------------------------------
 1 files changed, 97 insertions(+), 181 deletions(-)

diff --git a/pages/wareHouse/nuclearScale/nuclearscalerecord.vue b/pages/wareHouse/nuclearScale/nuclearscalerecord.vue
index 7bb4188..c70221d 100644
--- a/pages/wareHouse/nuclearScale/nuclearscalerecord.vue
+++ b/pages/wareHouse/nuclearScale/nuclearscalerecord.vue
@@ -2,15 +2,18 @@
   <view class="page">
     <view class="finishProductIn-locno-bg" />
     <u-navbar
-      title="鏍哥璁板綍"
+      title=""
       :background="background"
       :border-bottom="false"
       :title-bold="true"
       title-color="#000"
       back-icon-color="#000"
     >
-      <view class="navbar-right" slot="right" @click="goPrintAll">
-        鍏ㄩ儴鎵撳嵃
+      <view class="navbar-right" slot="right">
+        <text class="bluetooth-btn" @click="searchDevice">
+          {{ connectedDevice ? `宸茶繛鎺ワ細${connectedDevice.name}` : "杩炴帴钃濈墮" }}
+        </text>
+        <text class="print-all-btn" @click="goPrintAll">鍏ㄩ儴鎵撳嵃</text>
       </view>
     </u-navbar>
     <view class="wrap">
@@ -45,7 +48,9 @@
             @click="selectNo(item)"
           >
             <view class="content-header">
-              <view class="content-header-title">{{ index + 1 }}</view>
+              <view class="content-header-title">{{
+                list.length - index
+              }}</view>
             </view>
             <view class="content-body">
               <view class="row-list">
@@ -165,6 +170,8 @@
 </template>
 <script>
 import content_bg from "@/static/custom/finishProductIn/locNoBg.png";
+import bluetooth from "@/common/bluetoothPrinter.js";
+
 const jcapi = uni.requireNativePlugin("JCSDK-JCApiModule");
 
 // 浜岀淮鐮佺被鍨�
@@ -210,7 +217,7 @@
       listDevice: [], //钃濈墮璁惧鏁版嵁
       printQueue: [], // 鎵撳嵃闃熷垪
       printing: false, // 鏄惁姝e湪鎵撳嵃
-      printDensity: 3, // 榛樿鎵撳嵃娴撳害
+      printDensity: 10, // 榛樿鎵撳嵃娴撳害
       labelType: 1, // 榛樿鏍囩绫诲瀷
       // 1锛氶棿闅欑焊
       // 2锛氶粦鏍囩焊
@@ -220,8 +227,8 @@
       printMode: 2, // 榛樿鎵撳嵃妯″紡
       //	1锛氱儹鏁�
       // 	2锛氱儹杞嵃
-      connectedDevice: null, // 宸茶繛鎺ョ殑鎵撳嵃鏈�
-      connectionStatus: "disconnected", // 杩炴帴鐘舵��: disconnected, connecting, connected
+      connectedDevice: null,
+      connectionStatus: "disconnected",
       printStatus: "idle", // 鎵撳嵃鐘舵��: idle, printing, error
       errorMessage: "", // 閿欒淇℃伅
       verificationNo: "",
@@ -232,75 +239,43 @@
     this.verificationNo = JSON.parse(
       decodeURIComponent(options.verificationNo)
     );
+
+    bluetooth.init();
+
+    bluetooth.onChange(({ connectedDevice, connectionStatus }) => {
+      this.connectedDevice = connectedDevice;
+      this.connectionStatus = connectionStatus;
+    });
+
     this.getlist();
-    // 鍒濆鍖朣DK
-    jcapi.initSDK();
+  },
 
-    // 灏濊瘯鎭㈠涔嬪墠鐨勮摑鐗欒繛鎺ョ姸鎬�
-    this.restoreBluetoothConnection();
-
-    // 鐩戝惉椤电爜鍥炶皟
-    jcapi.didReadPrintCountInfo(function (r) {
-      console.log("椤电爜", r);
-    });
-
-    // 鐩戝惉閿欒鍥炶皟
-    jcapi.didReadPrintErrorInfo((r) => {
-      console.log("閿欒", r);
-      if (r.code == 23) {
-        // 鎵撳嵃鏈烘柇寮�杩炴帴
-        this.connectedDevice = null;
-        // 娓呴櫎鏈湴瀛樺偍鐨勮繛鎺ヤ俊鎭�
-        uni.removeStorageSync("bluetoothConnection");
-        uni.showToast({
-          icon: "none",
-          title: "鎵撳嵃鏈鸿繛鎺ュ凡鏂紑锛岃閲嶆柊杩炴帴",
-          duration: 2 * 1000,
-        });
-      } else {
-        uni.showToast({
-          icon: "none",
-          title: JSON.stringify(r),
-          duration: 2 * 1000,
-        });
-      }
-    });
+  // 椤甸潰鍗歌浇鏃朵笉涓诲姩鏂紑钃濈墮杩炴帴锛屼繚鎸佽繛鎺ョ姸鎬�
+  onUnload() {
+    // 涓嶆墽琛屾柇寮�杩炴帴鎿嶄綔锛屼繚鎸佽摑鐗欒繛鎺�
   },
   methods: {
-    restoreBluetoothConnection() {
-      try {
-        // 浠庢湰鍦板瓨鍌ㄨ幏鍙栦箣鍓嶄繚瀛樼殑杩炴帴淇℃伅
-        const savedConnection = uni.getStorageSync("bluetoothConnection");
-        if (savedConnection && savedConnection.address) {
-          console.log("灏濊瘯鎭㈠钃濈墮杩炴帴:", savedConnection);
-          // 璁剧疆涓鸿繛鎺ヤ腑鐘舵��
-          this.connectionStatus = "connecting";
+    // restoreBluetoothConnection() {
+    // 	try {
+    // 		// 浠庢湰鍦板瓨鍌ㄨ幏鍙栦箣鍓嶄繚瀛樼殑杩炴帴淇℃伅
+    // 		const savedConnection = uni.getStorageSync("bluetoothConnection");
+    // 		if (savedConnection && savedConnection.address) {
+    // 			console.log("灏濊瘯鎭㈠钃濈墮杩炴帴:", savedConnection);
+    // 			// 鐩存帴璁剧疆涓哄凡杩炴帴鐘舵�侊紝閬垮厤涓嶅繀瑕佺殑閲嶈繛
+    // 			// 瀹為檯杩炴帴鐘舵�佷細閫氳繃SDK鐨勫洖璋冭嚜鍔ㄦ洿鏂�
+    // 			this.connectedDevice = savedConnection;
+    // 			this.connectionStatus = "connected";
+    // 			console.log("钃濈墮杩炴帴鐘舵�佸凡鎭㈠");
 
-          // 灏濊瘯閲嶆柊杩炴帴
-          jcapi.openPrinterByDevice(
-            {
-              address: savedConnection.address,
-              name: savedConnection.name,
-              deviceType: 0, // 璁惧绫诲瀷锛�0-钃濈墮锛�1-缃戠粶
-            },
-            (r) => {
-              if (r.code == 0) {
-                this.connectedDevice = savedConnection;
-                this.connectionStatus = "connected";
-                console.log("钃濈墮杩炴帴宸叉仮澶�");
-              } else {
-                this.connectionStatus = "disconnected";
-                // 濡傛灉閲嶈繛澶辫触锛屾竻闄や繚瀛樼殑杩炴帴淇℃伅
-                uni.removeStorageSync("bluetoothConnection");
-                console.log("钃濈墮閲嶈繛澶辫触:", r);
-              }
-            }
-          );
-        }
-      } catch (e) {
-        console.error("鎭㈠钃濈墮杩炴帴澶辫触:", e);
-      }
-    },
+    // 			// 楠岃瘉杩炴帴鏄惁鐪熺殑鏈夋晥锛岄�氳繃鍙戦�佷竴涓畝鍗曠殑鍛戒护鎴栨鏌ョ姸鎬�
+    // 			// 杩欓噷涓嶆墽琛屽疄闄呯殑閲嶈繛鎿嶄綔锛岃�屾槸渚濊禆SDK鐨勮繛鎺ョ姸鎬佸洖璋�
+    // 			// 濡傛灉杩炴帴宸叉柇寮�锛孲DK浼氶�氳繃didReadPrintErrorInfo鍥炶皟閫氱煡鎴戜滑
+    // 		}
+    // 	} catch (e) {
+    // 		console.error("鎭㈠钃濈墮杩炴帴澶辫触:", e);
+    // 		this.connectionStatus = "disconnected";
+    // 	}
+    // },
     getmoreList() {
       if (this.pageSize >= this.total) {
         this.status = "nomore";
@@ -348,33 +323,15 @@
         this.getlist();
       }
     },
-    // 妫�鏌ヨ摑鐗欒繛鎺ョ姸鎬�
-    async checkBluetoothConnection() {
-      if (!this.connectedDevice) {
-        this.connectionStatus = "disconnected";
-        return false;
-      }
-
-      // 璁剧疆涓鸿繛鎺ヤ腑鐘舵��
-      this.connectionStatus = "connecting";
-
-      // 澧炲己杩炴帴鐘舵�佹娴�
-      return new Promise((resolve) => {
-        // 绠�鍖栬繛鎺ョ姸鎬佹娴嬶紝鐩存帴浣跨敤宸茶褰曠殑杩炴帴鐘舵��
-        if (this.connectedDevice) {
-          this.connectionStatus = "connected";
-          resolve(true);
-        } else {
-          this.connectionStatus = "disconnected";
-          uni.showToast({
-            icon: "none",
-            title: "鎵撳嵃鏈烘湭杩炴帴锛岃鍏堣繛鎺�",
-            duration: 2000,
-          });
-          resolve(false);
-        }
-      });
+    checkBluetoothConnection() {
+      return bluetooth.isConnected();
     },
+
+    // 	// 鐩存帴浣跨敤宸茶褰曠殑杩炴帴鐘舵�侊紝閬垮厤涓嶅繀瑕佺殑杩炴帴妫�鏌�
+    // 	// 瀹為檯杩炴帴鐘舵�佷細閫氳繃SDK鐨勫洖璋冭嚜鍔ㄦ洿鏂�
+    // 	this.connectionStatus = "connected";
+    // 	return true;
+    // },
 
     // 娣诲姞鍒版墦鍗伴槦鍒�
     addToPrintQueue(items) {
@@ -449,11 +406,13 @@
       uni.showModal({
         title: "鎻愮ず",
         content: "鏄惁鎵撳嵃瑁呯鍗曪紵",
-        showCancel: true,
-        success: async function (res) {
+        success(res) {
           if (res.confirm) {
-            // 娣诲姞鍒版墦鍗伴槦鍒�
-            that.addToPrintQueue(item);
+            // 鎸� batchNo 鍚堝苟
+            const sameBatchList = that.list.filter(
+              (i) => i.batchNo === item.batchNo
+            );
+            that.addToPrintQueue(sameBatchList);
           }
         },
       });
@@ -536,8 +495,8 @@
           this.getDrawLabelLine(1, 6, 42, 0.3, 0, LineType.Solid);
           this.getDrawLabelLine(1, 11, 42, 0.3, 0, LineType.Solid);
           this.getDrawLabelLine(1, 16, 42, 0.3, 0, LineType.Solid);
-          this.getDrawLabelLine(1, 21, 42, 0.3, 0, LineType.Solid);
-          this.getDrawLabelLine(1, 27, 67, 0.3, 0, LineType.Solid);
+          this.getDrawLabelLine(1, 23, 42, 0.3, 0, LineType.Solid);
+          this.getDrawLabelLine(1, 27.5, 67, 0.3, 0, LineType.Solid);
           this.getDrawLabelLine(1, 32, 67, 0.3, 0, LineType.Solid);
           this.getDrawLabelLine(1, 37, 67, 0.3, 0, LineType.Solid);
           this.getDrawLabelLine(1, 42, 67, 0.3, 0, LineType.Solid);
@@ -611,7 +570,7 @@
           );
           this.getDrawLabelText(
             2,
-            22.5,
+            23.5,
             25,
             8,
             "鍙戣揣/瑁呯鏁�:",
@@ -626,7 +585,7 @@
           );
           this.getDrawLabelText(
             2,
-            27.5,
+            28.5,
             25,
             8,
             "鐢熶骇鏃ユ湡:",
@@ -733,7 +692,7 @@
           );
           this.getDrawLabelText(
             17,
-            22.5,
+            23.5,
             27,
             8,
             fh,
@@ -748,7 +707,7 @@
           );
           this.getDrawLabelText(
             14,
-            27.5,
+            28.5,
             55,
             8,
             scdt,
@@ -867,86 +826,43 @@
         }
       });
     },
-    tapQuery(item) {
+    async tapQuery(item) {
       this.maskShow = false;
-      // 杩炴帴鎵撳嵃鏈�
-      let _this = this;
+      try {
+        await bluetooth.connect(item);
+        uni.showToast({ title: "杩炴帴鎴愬姛" });
 
-      // 璁剧疆涓鸿繛鎺ヤ腑鐘舵��
-      this.connectionStatus = "connecting";
-
-      jcapi.openPrinterByDevice(
-        {
-          address: item.address,
-          name: item.name,
-          deviceType: 0, // 璁惧绫诲瀷锛�0-钃濈墮锛�1-缃戠粶
-        },
-        function (r) {
-          // 鍦╰apQuery鏂规硶涓紝杩炴帴鎴愬姛鏃舵坊鍔犱繚瀛樿繛鎺ヤ俊鎭殑浠g爜
-          if (r.code == 0) {
-            _this.connectedDevice = item;
-            _this.connectionStatus = "connected";
-            // 淇濆瓨杩炴帴淇℃伅鍒版湰鍦板瓨鍌�
-            uni.setStorageSync("bluetoothConnection", item);
-            uni.showToast({
-              title: "杩炴帴鎴愬姛",
-              duration: 1500,
-            });
-            // 寮�濮嬪鐞嗘墦鍗伴槦鍒�
-            if (_this.printQueue.length > 0) {
-              _this.processPrintQueue();
-            }
-          } else {
-            _this.connectionStatus = "disconnected";
-            uni.showToast({
-              title: "杩炴帴澶辫触: " + (r.msg || "鏈煡閿欒"),
-              icon: "none",
-              duration: 2000,
-            });
-          }
+        // 濡傛灉鏈夋墦鍗颁换鍔★紝缁х画鎵撳嵃
+        if (this.printQueue.length) {
+          this.processPrintQueue();
         }
-      );
+      } catch (e) {
+        uni.showToast({
+          icon: "none",
+          title: "杩炴帴澶辫触",
+        });
+      }
     },
+
     //鎵撳嵃鐩稿叧
-    searchDevice() {
-      let _this = this;
-      uni.openBluetoothAdapter({
-        // 纭钃濈墮鏄惁鎵撳紑
-        success(r) {
-          uni.showLoading({
-            title: "鎼滅储涓�...",
-          });
-          // 鏈巿浜堣摑鐗欑浉鍏虫潈闄愬拰鏈墦寮�鎵嬫満瀹氫綅浼氭悳绱笉鍒拌澶�
-          jcapi.getBluetoothDevices(function (r) {
-            console.log("device:" + JSON.stringify(r));
-            // 鎼滅储鍒拌澶囧洖璋�
-            uni.hideLoading();
-            // 濡傛灉涔嬪墠鏈夎繛鎺ョ殑璁惧浣嗕笉鍦ㄦ悳绱㈢粨鏋滀腑锛岃鏄庤澶囧凡鏇存崲
-            if (
-              _this.connectedDevice &&
-              !r.some((dev) => dev.address === _this.connectedDevice.address)
-            ) {
-              _this.connectedDevice = null;
-              uni.showToast({
-                icon: "none",
-                title: "宸茶繛鎺ョ殑钃濈墮璁惧宸叉洿鎹紝璇烽噸鏂伴�夋嫨",
-                duration: 2000,
-              });
-            }
-            _this.listDevice = r;
-            _this.maskShow = true;
-          });
-        },
-        fail(e) {
-          uni.showModal({
-            title: "鎻愮ず",
-            content: "鎵撳紑钃濈墮澶辫触锛岃妫�鏌ヨ摑鐗欐槸鍚﹀紑鍚�",
-            showCancel: false,
-          });
-          console.log("寮�鍚摑鐗欒澶囧け璐�" + e);
-        },
-      });
+    async searchDevice() {
+      try {
+        uni.showLoading({ title: "鎼滅储涓�..." });
+        const devices = await bluetooth.searchDevices();
+        uni.hideLoading();
+
+        this.listDevice = devices;
+        this.maskShow = true;
+      } catch (e) {
+        uni.hideLoading();
+        uni.showModal({
+          title: "鎻愮ず",
+          content: "璇风‘璁よ摑鐗欏拰瀹氫綅宸插紑鍚�",
+          showCancel: false,
+        });
+      }
     },
+
     // 缁樺埗妯嚎
     getDrawLabelLine(x, y, width, height, rotate, lineType) {
       jcapi.drawLabelLine({

--
Gitblit v1.9.3