From fb0d024283a24042e55c70019dffbcd104792135 Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期二, 21 四月 2026 16:53:50 +0800
Subject: [PATCH] Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev
---
pages/tiaomachaima/tiaomachaimaCopy_HK.vue | 389 ++++++++++++++++++++++++++---
pages/caigoutuiliaocheck/Kf_POStockInBackBill_Check.vue | 2
pages/ZLGL/QualityReportStep/QualityReportStepBill.vue | 345 +++++++++++++++++++++++++-
utils/Print_HK.js | 41 +++
4 files changed, 714 insertions(+), 63 deletions(-)
diff --git a/pages/ZLGL/QualityReportStep/QualityReportStepBill.vue b/pages/ZLGL/QualityReportStep/QualityReportStepBill.vue
index fceac15..98fd4bf 100644
--- a/pages/ZLGL/QualityReportStep/QualityReportStepBill.vue
+++ b/pages/ZLGL/QualityReportStep/QualityReportStepBill.vue
@@ -4,10 +4,16 @@
<view class="bill-main-area">
<!-- 涓昏〃椤电 -->
<view class="bill-main-tabs">
- <view :class="mainTabSelected == 1 ? 'selected' : ''" @tap="mainTabSelected = 1">鍩烘湰淇℃伅</view>
- <view :class="mainTabSelected == 2 ? 'selected' : ''" @tap="mainTabSelected = 2">鎵弿淇℃伅</view>
- <view :class="mainTabSelected == 3 ? 'selected' : ''" @tap="mainTabSelected = 3">鍒跺崟淇℃伅</view>
- <view :class="mainTabSelected == 4 ? 'selected' : ''" @tap="mainTabSelected = 4">鍏朵粬淇℃伅</view>
+ <view class="tabs-left">
+ <view :class="mainTabSelected == 1 ? 'selected' : ''" @tap="mainTabSelected = 1">鍩烘湰淇℃伅</view>
+ <view :class="mainTabSelected == 2 ? 'selected' : ''" @tap="mainTabSelected = 2">鎵弿淇℃伅</view>
+ <view :class="mainTabSelected == 3 ? 'selected' : ''" @tap="mainTabSelected = 3">鍒跺崟淇℃伅</view>
+ <view :class="mainTabSelected == 4 ? 'selected' : ''" @tap="mainTabSelected = 4">鍏朵粬淇℃伅</view>
+ </view>
+ <view class="mode-switch-right">
+ <text class="mode-text">{{ directInputMode ? '鐩存帴杈撳叆' : '鍙屽嚮绱姞' }}</text>
+ <switch :checked="directInputMode" @change="onModeSwitchChange" color="#3a78ff" style="transform: scale(0.7);" />
+ </view>
</view>
<!-- 涓昏〃鍐呭 -->
<view class="bill-main-contents">
@@ -292,6 +298,32 @@
<BillListPopupVue ref="billList" :HBillType="hform.HBillType" :HSourceBillType="hform.HSourceBillType"
:HStockOrgID="hform.HStockOrgID" @BillSelectComplete="HandleBillSelectComplete"></BillListPopupVue>
+
+ <!-- 鐩存帴杈撳叆鏁伴噺寮圭獥 -->
+ <uni-popup ref="inputQtyPopup" type="center">
+ <view class="input-qty-popup">
+ <view class="popup-title">杈撳叆涓嶈壇鏁伴噺</view>
+ <view class="popup-content">
+ <view class="popup-info">
+ <text class="popup-label">涓嶈壇鍘熷洜锛�</text>
+ <text class="popup-value">{{ currentItem && currentItem.涓嶈壇鍘熷洜鍚嶇О || '' }}</text>
+ </view>
+ <view class="popup-info">
+ <text class="popup-label">褰撳墠鏁伴噺锛�</text>
+ <text class="popup-value">{{ currentItem && currentItem.num || 0 }}</text>
+ </view>
+ <view class="popup-input-row">
+ <text class="popup-label">杈撳叆鏁伴噺锛�</text>
+ <input class="popup-input" type="number" v-model="inputQtyValue" placeholder="璇疯緭鍏ユ暟閲�" />
+ </view>
+ </view>
+ <view class="popup-buttons">
+ <button class="btn-c" size="mini" @tap="cancelInputQty">鍙栨秷</button>
+ <view style="flex: 1;"></view>
+ <button class="btn-a" size="mini" @tap="confirmInputQty">纭</button>
+ </view>
+ </view>
+ </uni-popup>
</view>
</template>
@@ -326,7 +358,12 @@
//涓婁竴娆$偣鍑绘椂闂�
lastClickTime: 0,
operationType: 1,
-
+ // 鐩存帴杈撳叆妯″紡寮�鍏�
+ directInputMode: true,
+ // 寮圭獥鐩稿叧
+ currentItem: null,
+ inputQtyValue: '',
+
mainTabSelected: 1,
subTabSelected: 0,
@@ -435,6 +472,11 @@
},
//涓嶈壇鍘熷洜鍗曞嚮
reasonClick(item) {
+ // 鐩存帴杈撳叆妯″紡涓嬶紝鍗曞嚮鐩存帴寮瑰嚭杈撳叆妗�
+ if (this.directInputMode) {
+ this.showDirectInputDialog(item);
+ return;
+ }
const now = Date.now();
if (now - this.lastClickTime < 300) {
// 鍙屽嚮閫昏緫
@@ -445,6 +487,37 @@
this.handleSingleClick(item);
this.lastClickTime = now;
}
+ },
+ // 妯″紡鍒囨崲
+ onModeSwitchChange(e) {
+ this.directInputMode = e.detail.value;
+ },
+ // 鏄剧ず鐩存帴杈撳叆鏁伴噺鐨勫脊绐�
+ showDirectInputDialog(item) {
+ this.currentItem = item;
+ this.inputQtyValue = String(item.num || 0);
+ this.$refs.inputQtyPopup.open();
+ },
+ // 鍙栨秷杈撳叆
+ cancelInputQty() {
+ this.$refs.inputQtyPopup.close();
+ this.currentItem = null;
+ this.inputQtyValue = '';
+ },
+ // 纭杈撳叆
+ confirmInputQty() {
+ const inputQty = parseInt(this.inputQtyValue);
+ if (isNaN(inputQty) || inputQty < 0) {
+ uni.showToast({
+ title: '璇疯緭鍏ユ湁鏁堟暟閲�',
+ icon: 'none'
+ });
+ return;
+ }
+ this.submitBarCodeWithQty(this.currentItem, inputQty);
+ this.$refs.inputQtyPopup.close();
+ this.currentItem = null;
+ this.inputQtyValue = '';
},
handleSingleClick(item) {
console.log('鍗曞嚮:', item.涓嶈壇鍘熷洜鍚嶇О);
@@ -532,7 +605,7 @@
}
})
this.HBadReasonList = data;
-
+ this.getHisReportList();//鑾峰彇鍘嗗彶璁板綍
} else {
CommonUtils.showTips({
title: '娓╅Θ鎻愮ず',
@@ -594,6 +667,7 @@
this.hform.HProcName= data[0].褰撳墠宸ュ簭
this.hform.HDeptID= data[0].HWorkShopID
this.getGy_BadReasonList();
+
} else {
CommonUtils.showTips({
title: '娓╅Θ鎻愮ず',
@@ -688,22 +762,25 @@
url: "/Sc_QualityReportBill/get_BarCodeDetail",
data: {
HInterID: this.hform.HInterID,
-
+
},
});
-
+
let {
data,
Message,
count
} = res.data;
-
+
if (count == 1) {
console.log("data: ", data);
this.HisReportList = data;
-
+ // 缁熻鍚勪笉鑹師鍥犵殑鏁伴噺骞舵洿鏂板埌 HBadReasonList
+ this.updateBadReasonNumFromHisReport();
+
} else {
this.HisReportList = [];
+ this.clearBadReasonNum();
CommonUtils.showTips({
title: "娓╅Θ鎻愮ず",
message: `鑾峰彇鍘嗗彶鎵爜璁板綍澶辫触: ${Message}`,
@@ -715,6 +792,33 @@
message: `鑾峰彇鍘嗗彶鎵爜璁板綍澶辫触: ${err}`,
});
}
+ },
+ // 浠� HisReportList 缁熻鏇存柊 HBadReasonList 鐨� num
+ updateBadReasonNumFromHisReport() {
+ // 鍏堟竻绌烘墍鏈� num
+ this.HBadReasonList.forEach(item => {
+ this.$set(item, 'num', 0);
+ });
+
+ // 缁熻 HisReportList 涓悇涓嶈壇鍘熷洜鐨勬暟閲�
+ if (this.HisReportList && this.HisReportList.length > 0) {
+ this.HisReportList.forEach(hisItem => {
+ // 鏍规嵁 HBadReasonID 鍖归厤
+ const matchedItem = this.HBadReasonList.find(
+ badItem => badItem.涓嶈壇鍘熷洜浠g爜 == hisItem.HBadReasonNumber
+ );
+ if (matchedItem) {
+ const currentNum = matchedItem.num || 0;
+ this.$set(matchedItem, 'num', currentNum + hisItem.HBadReasonHQty||1);
+ }
+ });
+ }
+ },
+ // 娓呯┖ HBadReasonList 鐨� num
+ clearBadReasonNum() {
+ this.HBadReasonList.forEach(item => {
+ this.$set(item, 'num', 0);
+ });
},
//鍒犻櫎鍘嗗彶璁板綍
delReason(item) {
@@ -948,15 +1052,85 @@
title: "淇濆瓨鎴愬姛",
message: `淇濆瓨鎴愬姛`,
});
- if(!item.num){
- this.$set(item, 'num', 1);
- }else{
- this.$set(item, 'num', item.num+1);
- }
- console.log(item.num)
- //this.$set(item, 'num', newValue);
+ // 鍒锋柊鍘嗗彶璁板綍锛宯um浼氳嚜鍔ㄤ粠HisReportList缁熻鏇存柊
this.getHisReportList();
this.hasCheckQty=true;
+ } else {
+ CommonUtils.showTips({
+ title: "娓╅Θ鎻愮ず",
+ message: `涓嶈壇鍘熷洜淇濆瓨閿欒: ${Message}`,
+ });
+ }
+ } catch (err) {
+ CommonUtils.showTips({
+ title: "娓╅Θ鎻愮ず",
+ message: `涓嶈壇鍘熷洜淇濆瓨閿欒: ${err}`,
+ });
+ }
+ },
+ //鎻愪氦涓嶈壇鍘熷洜鎵爜璁板綍缂撳瓨锛堢洿鎺ヨ緭鍏ユ暟閲忥級
+ async submitBarCodeWithQty(item, qty){
+ if(!this.checkSubmitValidate()){
+ return
+ }
+ try {
+ let oMainObject = {
+ HInterID:this.hform.HInterID
+ ,HBillNo:this.hform.HBillNo
+ ,HBillType:this.hform.HBillType
+ ,HDate:new Date()
+ ,HICMOBillNo:this.hform.HICMOBillNo
+ ,HICMOInterID:this.hform.HICMOInterID
+ ,HICMOEntryID:this.hform.HICMOEntryID
+ ,HProcExchBillNo:this.hform.HProcExchBillNo
+ ,HProcExchInterID:this.hform.HProcExchInterID
+ ,HProcExchEntryID:this.hform.HProcExchEntryID
+ ,HProcID:this.hform.HProcID
+ ,HMaterID:this.hform.HMaterID
+ ,HSourceID:this.hform.HSourceID
+ ,HGroupID:this.hform.HGroupID
+ ,HDeptID:this.hform.HDeptID
+ ,HCheckManID:this.hform.HEmpID
+ ,HBadReasonID:item.HItemID
+ ,HBarCode:item.涓嶈壇鍘熷洜浠g爜
+ ,HMaker:this.hform.HMaker
+ ,HMakeDate:this.hform.HMakeDate
+ ,HReportType:1
+ ,HSourceBillType:this.hform.HSourceBillType
+ ,HSourceBillNo:this.hform.HSourceBillNo
+ ,HSourceInterID:this.hform.HMainSourceInterID
+ ,HSourceEntryID:this.hform.HMainSourceEntryID
+ ,HBadReasonHQty:qty
+ ,HQty:this.hform.HCheckQty
+ }
+ var sMainStr = JSON.stringify(oMainObject);
+ var oMain = sMainStr + ';' + this.operationType;
+
+ let res = await CommonUtils.doRequest2Sync({
+ url: "/Sc_QualityReportBill/set_SaveBarCode",
+ data: {
+ oMain: oMain,
+ },
+ method: "POST",
+ });
+
+ if (!res) {
+ return;
+ }
+
+ let {
+ count,
+ Message,
+ data
+ } = res.data;
+ if (count == 1) {
+ CommonUtils.showTips({
+ title: "淇濆瓨鎴愬姛",
+ message: `淇濆瓨鎴愬姛锛屾暟閲�: ${qty}`,
+ });
+ // 鍒锋柊鍘嗗彶璁板綍锛宯um浼氳嚜鍔ㄤ粠HisReportList缁熻鏇存柊
+ this.getHisReportList();
+ this.hasCheckQty = true;
} else {
CommonUtils.showTips({
title: "娓╅Θ鎻愮ず",
@@ -1119,7 +1293,55 @@
padding: 0;
}
- .bill-main-tabs,
+ .bill-main-tabs {
+ box-sizing: border-box;
+ width: 100%;
+ display: flex;
+ flex-direction: row;
+ justify-content: space-between;
+ align-items: center;
+ border-bottom: 1px solid #ddd;
+ padding: 20rpx 10rpx;
+
+ .tabs-left {
+ display: flex;
+ flex-direction: row;
+ flex-wrap: nowrap;
+ gap: 20rpx;
+ flex-shrink: 0;
+ overflow-x: auto;
+ white-space: nowrap;
+
+ view {
+ width: auto;
+ font-size: 30rpx;
+ color: #555;
+ text-align: center;
+ padding: 16rpx 0;
+ }
+
+ .selected {
+ color: #3a78ff;
+ font-weight: bold;
+ border-bottom: 3px solid #3a78ff;
+ }
+ }
+
+ .mode-switch-right {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ gap: 10rpx;
+ flex-shrink: 0;
+ padding-right: 10rpx;
+
+ .mode-text {
+ font-size: 24rpx;
+ color: #666;
+ }
+ }
+ }
+
.bill-sub-tabs {
box-sizing: border-box;
width: 100%;
@@ -1148,6 +1370,93 @@
}
}
+ /* 鐩存帴杈撳叆鏁伴噺寮圭獥鏍峰紡 */
+ .input-qty-popup {
+ background-color: #fff;
+ border-radius: 20rpx;
+ padding: 30rpx;
+ width: 600rpx;
+ box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.15);
+
+ .popup-title {
+ font-size: 32rpx;
+ font-weight: bold;
+ color: #333;
+ text-align: center;
+ padding-bottom: 20rpx;
+ border-bottom: 1px solid #eee;
+ }
+
+ .popup-content {
+ padding: 20rpx 0;
+
+ .popup-info {
+ display: flex;
+ align-items: center;
+ padding: 10rpx 0;
+
+ .popup-label {
+ font-size: 28rpx;
+ color: #666;
+ width: 180rpx;
+ }
+
+ .popup-value {
+ font-size: 28rpx;
+ color: #333;
+ }
+ }
+
+ .popup-input-row {
+ display: flex;
+ align-items: center;
+ padding: 15rpx 0;
+ margin-top: 10rpx;
+
+ .popup-label {
+ font-size: 28rpx;
+ color: #666;
+ width: 180rpx;
+ }
+
+ .popup-input {
+ flex: 1;
+ height: 60rpx;
+ border: 1px solid #acacac;
+ border-radius: 10rpx;
+ padding: 0 15rpx;
+ font-size: 28rpx;
+ }
+ }
+ }
+
+ .popup-buttons {
+ display: flex;
+ flex-direction: row;
+ gap: 10rpx;
+ padding-top: 20rpx;
+ border-top: 1px solid #eee;
+
+ button {
+ border-radius: 50rpx;
+ width: 150rpx;
+ height: 60rpx;
+ line-height: 60rpx;
+ font-size: 28rpx;
+ }
+
+ .btn-a {
+ background-color: #3a78ff;
+ color: #fff;
+ }
+
+ .btn-c {
+ background-color: #acacac;
+ color: #fff;
+ }
+ }
+ }
+
.bill-main-content,
.bill-sub-content {
box-sizing: border-box;
diff --git a/pages/caigoutuiliaocheck/Kf_POStockInBackBill_Check.vue b/pages/caigoutuiliaocheck/Kf_POStockInBackBill_Check.vue
index d6037a2..23038a6 100644
--- a/pages/caigoutuiliaocheck/Kf_POStockInBackBill_Check.vue
+++ b/pages/caigoutuiliaocheck/Kf_POStockInBackBill_Check.vue
@@ -917,7 +917,7 @@
if (res.confirm) {
console.log('鐢ㄦ埛鐐瑰嚮纭畾');
uni.redirectTo({
- url: '/pages/shengchantuiliaoCheck/MateOutBackCheckBill?OperationType=1'
+ url: '/pages/caigoutuiliaocheck/Kf_POStockInBackBill_Check?OperationType=1'
})
} else if (res.cancel) {
console.log('鐢ㄦ埛鐐瑰嚮鍙栨秷');
diff --git a/pages/tiaomachaima/tiaomachaimaCopy_HK.vue b/pages/tiaomachaima/tiaomachaimaCopy_HK.vue
index 739ca38..2f6f891 100644
--- a/pages/tiaomachaima/tiaomachaimaCopy_HK.vue
+++ b/pages/tiaomachaima/tiaomachaimaCopy_HK.vue
@@ -140,13 +140,15 @@
// 鍦ㄥ叏灞�瀹氫箟涓�涓彉閲忔潵鏍囪瘑鏄惁宸茬粡鍒濆鍖�
var isPrinterInitialized = false;
-
import {
getUserInfo
} from "@/utils/auth.js";
import {
CommonUtils
} from "@/utils/common.js"
+ import {
+ PrinterWS
+ } from "@/utils/Print_HK.js"
export default {
data() {
return {
@@ -165,10 +167,15 @@
barCodeSplitInfo: [], //鎷嗙爜淇℃伅
cantGenerate: true, // 鐢熸垚鎸夐挳鍒濆绂佺敤
cantPrint: true, // 鎵撳嵃鎸夐挳鍒濆绂佺敤
+ cantPrint_HK: true, // 鎵撳嵃鎸夐挳鍒濆绂佺敤
cantSplit: false, // 鎷嗙爜鎸夐挳鍒濆鍙敤
HBarCodeFocus: false,
isPrinting: false,
- printInfo: "" //鎵撳嵃
+ printInfo: "" ,//鎵撳嵃,
+ socketTask: null, // 瀛樻斁 uni-app WebSocket 瀹炰緥
+ wsConnected: false,
+ wsReconnectTimer: null,
+ wsHeartbeatTimer: null,
};
},
methods: {
@@ -190,7 +197,6 @@
printer.setConcentration({ //璁剧疆鎵撳嵃娴撳害銆俧ont_level 鍙栧�艰寖鍥达細1~39銆�
level: 39
});
-
},
printerLabel() {
const formatDate = new Date().toISOString().split('T')[0];
@@ -437,33 +443,257 @@
printer.printGoToNextMark();
console.log('娴嬭瘯鎵撳嵃QR缁撴潫');
},
- printerLabel_HK() {
+ printerLabel_HK() {
//璁剧疆鎵撳嵃鍐呭
-
- var HPrintData = "SIZE 58 mm,40 mm" + '\r\n';//璁剧疆鏍囩绾稿紶澶у皬;
- HPrintData += "CLS" + '\r\n';//娓呴櫎鍥惧儚缂撳瓨鍖�
+ const formatDate = new Date().toISOString().split('T')[0];
+ var HPrintData = "SIZE 58 mm,40 mm" + '\r\n'+ '\r\n'; //璁剧疆鏍囩绾稿紶澶у皬;
+ HPrintData += "CLS" + '\r\n'+ '\r\n'; //娓呴櫎鍥惧儚缂撳瓨鍖�
//TEXT X, Y, 鈥渇ont鈥�, rotation, x-multiplication, y-multiplication, [alignment,]
//X:鏂囨湰X鍧愭爣; Y:鏂囨湰Y鍧愭爣; font:瀛椾綋鍚嶇О; rotation:鏂囧瓧鏃嬭浆瑙掑害(0锛氫笉鏃嬭浆,90锛�90 搴�,180锛�180 搴�,270:270 搴�); x-multiplication:姘村钩鏂瑰悜鏀惧ぇ; y-multiplication:鍨傜洿鏂瑰悜鏀惧ぇ; alignment:鎸囧畾鏂囨湰瀵归綈鏂瑰紡(0锛氶粯璁わ紙灞呭乏锛�,1锛氬眳宸�,2锛氬眳涓�,3锛氬眳鍙�); content:闇�瑕佹墦鍗扮殑鏂囨湰鍐呭銆�
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '渚涘簲鍟嗗悕绉帮細' + this.barCodeInfo['渚涘簲鍟�'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '鐗╂枡浠g爜锛�' + this.barCodeInfo['鐗╂枡浠g爜'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '鐗╂枡绠�绉帮細' + this.barCodeInfo['鐗╂枡绠�绉�'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '鏁伴噺锛�' + this.barCodeInfo['鍓╀綑鏁伴噺'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '宸ュ彿锛�' + this.barCodeInfo['宸ュ彿'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '鐢熶骇鏃ユ湡锛�' + this.barCodeInfo['鐢熶骇鏃ユ湡'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '娴佹按鍙凤細' + this.barCodeInfo['娴佹按鍙�'] + '\r\n';
- HPrintData += 'TEXT 50, 50, "4",0,1,1,1' + '鎵撳嵃鏃ユ湡锛�' + formatDate + '\r\n';
- HPrintData += this.barCodeInfo['鏉$爜缂栧彿'];
- printer.sendCommand_HK(HPrintData);
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"渚涘簲鍟嗗悕绉帮細' + this.barCodeInfo['渚涘簲鍟�'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"鐗╂枡浠g爜锛�' + this.barCodeInfo['鐗╂枡浠g爜'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"鐗╂枡绠�绉帮細' + this.barCodeInfo['鐗╂枡绠�绉�'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"鏁伴噺锛�' + this.barCodeInfo['鍓╀綑鏁伴噺'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"宸ュ彿锛�' + this.barCodeInfo['宸ュ彿'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"鐢熶骇鏃ユ湡锛�' + this.barCodeInfo['鐢熶骇鏃ユ湡'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"娴佹按鍙凤細' + this.barCodeInfo['娴佹按鍙�'] + '"' + '\r\n' + '\r\n';
+ HPrintData += 'TEXT 50, 50, "4",0,1,1,1,' + '"鎵撳嵃鏃ユ湡锛�' + formatDate + '"' + '\r\n' + '\r\n';
+ //HPrintData += this.barCodeInfo['鏉$爜缂栧彿'];
+ HPrintData += 'PRINT 1' + '\r\n' + '\r\n';
+
+
+ var HPrintData2 = "SIZE 58 mm,40 mm" + '\r\n'+ '\r\n'; //璁剧疆鏍囩绾稿紶澶у皬;
+ HPrintData2 += "CLS" + '\r\n'+ '\r\n'; //娓呴櫎鍥惧儚缂撳瓨鍖�
+ HPrintData2 += 'TEXT 50, 50, "4",0,1,1,1,"DEMO FOR TEXT"' + '\r\n'+ '\r\n';
+ HPrintData2 += 'QRCODE 0, 92, M, 4, A, 0, M1,S0,"ABCD1234"' + '\r\n'+ '\r\n';
+ HPrintData2 += 'PRINT 1' + '\r\n' + '\r\n';
+
+
+ this.sendCommand_HK(HPrintData2);
},
// 鍙戦�佹墦鍗板懡浠�
- sendCommand_HK(commandData) {
- if (this.ws.readyState === WebSocket.OPEN) {
- // this.ws.send(JSON.stringify(commandData));
- this.ws.send(commandData);
-
- } else {
- console.error('WebSocket 鏈繛鎺�');
+ async sendCommand_HK(commandData) {
+ // 妫�鏌� WebSocket 鏄惁宸茶繛鎺�
+ if (!this.socketTask) {
+ console.error('WebSocket 鏈垵濮嬪寲');
+ uni.showToast({
+ title: '鎵撳嵃鏈烘湭杩炴帴',
+ icon: 'none'
+ });
+ return false;
+ }
+
+ if (this.socketTask.readyState === 1) {
+ console.log("鎵撳嵃鍐呭锛�" + '\r\n' + commandData);
+ this.socketTask.send({
+ data: commandData,
+ success: () => {
+ console.log('鍛戒护鍙戦�佹垚鍔�');
+ },
+ fail: (err) => {
+ console.error('鍛戒护鍙戦�佸け璐�:', err);
+ }
+ });
+ return true;
+ } else {
+ console.error('WebSocket 鏈繛鎺ワ紝褰撳墠鐘舵��:', this.socketTask.readyState);
+ uni.showToast({
+ title: '鎵撳嵃鏈鸿繛鎺ヤ腑锛岃绋嶅悗閲嶈瘯',
+ icon: 'none'
+ });
+ return false;
+ }
+ },
+ // 鍒濆鍖栬繛鎺�
+ async connect() {
+ return new Promise((resolve, reject) => {
+ // 鍏抽棴鐜版湁杩炴帴
+ if (this.socketTask) {
+ try {
+ this.socketTask.close();
+ } catch(e) {}
+ this.socketTask = null;
+ }
+
+ // 鏍规嵁瀹為檯鐜閰嶇疆 - 娉ㄦ剰锛氬湪鐪熷疄PDA涓婂彲鑳介渶瑕佸叿浣揑P
+ // 鍏堝皾璇曚娇鐢� 127.0.0.1锛屽鏋滀笉琛屽啀灏濊瘯瀹為檯IP 'ws://localhost:40002'
+ const wsUrl = 'ws://192.168.2.141:40001';
+
+ console.log('鍑嗗杩炴帴 WebSocket:', wsUrl);
+
+ this.socketTask = uni.connectSocket({
+ url: wsUrl,
+ success: () => {
+ console.log('WebSocket 杩炴帴鍒涘缓鎴愬姛');
+ },
+ fail: (err) => {
+ console.error('WebSocket 杩炴帴澶辫触:', err);
+ reject(err);
+ }
+ });
+
+ // 璁剧疆瓒呮椂
+ const timeoutId = setTimeout(() => {
+ console.log('杩炴帴瓒呮椂');
+ if (this.socketTask && this.socketTask.close) {
+ this.socketTask.close();
+ }
+ reject(new Error('杩炴帴瓒呮椂(5绉�)'));
+ }, 5000);
+
+ console.log("this.socketTask鍐呭锛�" + JSON.stringify(this.socketTask));
+ // 鐩戝惉鎵撳紑浜嬩欢
+ this.socketTask.onOpen(() => {
+ clearTimeout(timeoutId);
+ console.log("WebSocket 杩炴帴鎴愬姛锛宺eadyState:", this.socketTask.readyState);
+ this.wsConnected = true;
+ resolve();
+ });
+
+ // 鐩戝惉閿欒浜嬩欢 - 杩欓噷浼氭敹鍒拌缁嗙殑閿欒淇℃伅
+ this.socketTask.onError((err) => {
+ clearTimeout(timeoutId);
+ console.error("WebSocket 閿欒璇︽儏:", JSON.stringify(err));
+ console.error("WebSocket readyState:", this.socketTask.readyState);
+ this.wsConnected = false;
+ reject(new Error('WebSocket 杩炴帴澶辫触: ' + JSON.stringify(err)));
+ });
+
+ // 鐩戝惉鍏抽棴浜嬩欢
+ this.socketTask.onClose((res) => {
+ clearTimeout(timeoutId);
+ console.log("WebSocket 杩炴帴鍏抽棴锛宑ode:", res.code, "reason:", res.reason);
+ console.log("鍏抽棴鏃剁殑 readyState:", this.socketTask.readyState);
+ this.wsConnected = false;
+
+ // 濡傛灉鏄潪姝e父鍏抽棴锛屾彁绀虹敤鎴�
+ if (res.code !== 1000) {
+ console.warn('闈炴甯稿叧闂紝閿欒鐮�:', res.code);
+ }
+ });
+
+ // 鐩戝惉娑堟伅
+ this.socketTask.onMessage((res) => {
+ console.log("鏀跺埌鎵撳嵃鏈烘秷鎭�:", res.data);
+ });
+ });
+ },
+ // 娣诲姞蹇冭烦妫�娴嬶紝淇濇寔杩炴帴
+ startHeartbeat() {
+ if (this.wsHeartbeatTimer) {
+ clearInterval(this.wsHeartbeatTimer);
}
+
+ this.wsHeartbeatTimer = setInterval(() => {
+ if (this.socketTask && this.socketTask.readyState === 1) {
+ // 鍙戦�佸績璺冲寘
+ this.socketTask.send({
+ data: 'ping',
+ fail: (err) => {
+ console.log('蹇冭烦鍙戦�佸け璐�:', err);
+ this.wsConnected = false;
+ }
+ });
+ } else if (this.socketTask && this.socketTask.readyState !== 1) {
+ console.log('WebSocket 鐘舵�佸紓甯革紝readyState:', this.socketTask?.readyState);
+ this.wsConnected = false;
+ }
+ }, 30000); // 姣�30绉掑彂閫佷竴娆″績璺�
+ },
+ // 娣诲姞杩炴帴鐘舵�佹鏌ユ柟娉�
+ checkConnection() {
+ return new Promise((resolve) => {
+ if (!this.socketTask) {
+ resolve(false);
+ return;
+ }
+
+ if (this.socketTask.readyState === 1) {
+ // 宸茶繛鎺ワ紝鍙戦�佹祴璇曟秷鎭‘璁�
+ this.socketTask.send({
+ data: 'test',
+ success: () => {
+ resolve(true);
+ },
+ fail: () => {
+ resolve(false);
+ }
+ });
+ } else {
+ console.log('杩炴帴鐘舵��:', this.socketTask.readyState);
+ resolve(false);
+ }
+ });
+ },
+ // 娴嬭瘯鎵撳嵃鏈烘湇鍔�
+ async testPrinterService() {
+ console.log('寮�濮嬫祴璇曟墦鍗版満鏈嶅姟...');
+
+ // 灏濊瘯涓嶅悓鐨勫湴鍧�
+ const testUrls = [
+ 'ws://127.0.0.1:40002',
+ 'ws://localhost:40002',
+ 'ws://192.168.2.141:40001',
+ 'ws://192.168.2.141:40002',
+ // 濡傛灉鏈夊叿浣揑P锛屽彲浠ユ坊鍔�
+ // 'ws://192.168.1.100:40002'
+ ];
+
+ for (const url of testUrls) {
+ console.log(`娴嬭瘯鍦板潃: ${url}`);
+ try {
+ const result = await this.testConnect(url);
+ if (result) {
+ console.log(`鎴愬姛杩炴帴鍒�: ${url}`);
+ uni.showToast({
+ title: `鎵惧埌鎵撳嵃鏈�: ${url}`,
+ icon: 'success'
+ });
+ return true;
+ }
+ } catch (e) {
+ console.log(`杩炴帴澶辫触: ${url}`, e);
+ }
+ }
+
+ console.log('鎵�鏈夊湴鍧�娴嬭瘯澶辫触');
+ uni.showToast({
+ title: '鏈壘鍒版墦鍗版満鏈嶅姟',
+ icon: 'none',
+ duration: 3000
+ });
+ return false;
+ },
+
+ // 娴嬭瘯鍗曚釜杩炴帴
+ testConnect(url) {
+ return new Promise((resolve) => {
+ const socket = uni.connectSocket({
+ url: url,
+ success: () => {
+ console.log(`娴嬭瘯杩炴帴鍒涘缓鎴愬姛: ${url}`);
+ }
+ });
+
+ const timeout = setTimeout(() => {
+ if (socket) {
+ socket.close();
+ }
+ resolve(false);
+ }, 2000);
+
+ socket.onOpen(() => {
+ clearTimeout(timeout);
+ socket.close();
+ resolve(true);
+ });
+
+ socket.onError((err) => {
+ clearTimeout(timeout);
+ console.log(`娴嬭瘯杩炴帴閿欒: ${url}`, err);
+ resolve(false);
+ });
+ });
},
doRequest(url, data, resFunction, errFunction, method) {
uni.showLoading({
@@ -555,6 +785,7 @@
async searchbarCodeInfoMeta() {
this.cantGenerate = true
this.cantPrint = true
+ this.cantPrint_HK = true
this.cantSplit = false // 鎷嗙爜鍓嶇‘淇濇媶鐮佹寜閽彲鐢�
if (CommonUtils.isEmpty(this.barCodeInfoMeta.barCodeNo) === true) {
return uni.showToast({
@@ -613,6 +844,7 @@
this.cantSplit = true;
this.cantGenerate = false;
this.cantPrint = true;
+ this.cantPrint_HK = true;
//鐢熸垚
this.SaveBarCodeCreate();
} else {
@@ -654,6 +886,7 @@
// 鐢熸垚鎴愬姛锛岀鐢ㄧ敓鎴愭寜閽紝鏀惧紑鎵撳嵃鎸夐挳
this.cantGenerate = true;
this.cantPrint = false;
+ this.cantPrint_HK = false;
this.cantSplit = true;
this.barCodeInfoMeta.barCodeNo = ""; //娓呯┖杈撳叆妗�
uni.showToast({
@@ -705,34 +938,75 @@
CommonUtils.playSound(0);
}
},
-
+
//娴峰悍鎵撳嵃鎸夐挳
- async PrintHBarCode() {
- // 闃叉閲嶅鐐瑰嚮
+ async PrintHBarCode_HK() {
if (this.isPrinting) {
- uni.showToast({
- title: '鎵撳嵃涓紝璇风◢鍊�...',
- icon: 'none'
- });
- return;
+ uni.showToast({
+ title: '鎵撳嵃涓紝璇风◢鍊�...',
+ icon: 'none'
+ });
+ return;
}
+
+ // 鍏堟鏌ユ墦鍗版満鏈嶅姟鏄惁鍙敤
+ uni.showLoading({
+ title: '妫�鏌ユ墦鍗版満...',
+ mask: true
+ });
+
this.isPrinting = true;
-
+
try {
- this.printerLabel_HK(); //鎵撳嵃
+ // 妫�鏌ュ綋鍓嶈繛鎺ョ姸鎬�
+ const isConnected = await this.checkConnection();
+
+ if (!isConnected) {
+ uni.showLoading({
+ title: '杩炴帴鎵撳嵃鏈�...',
+ mask: true
+ });
+ await this.connect();
+ this.startHeartbeat(); // 鍚姩蹇冭烦
+ }
+
+ uni.hideLoading();
+
+ // 纭杩炴帴鎴愬姛
+ if (this.socketTask && this.socketTask.readyState === 1) {
+ this.isPrinting = true;
+ this.printerLabel_HK();
+
+ // 寤惰繜閲嶇疆鎵撳嵃鐘舵��
+ setTimeout(() => {
+ this.isPrinting = false;
+ }, 3000);
+ } else {
+ throw new Error(`鎵撳嵃鏈烘湭杩炴帴锛岀姸鎬�: ${this.socketTask?.readyState}`);
+ }
+
} catch (error) {
+ uni.hideLoading();
console.error('鎵撳嵃澶辫触:', error);
this.isPrinting = false;
-
- uni.showToast({
- title: error.message || '鎵撳嵃澶辫触',
- icon: 'error',
- duration: 2000
+ this.wsConnected = false;
+
+ uni.showModal({
+ title: '鎵撳嵃澶辫触',
+ content: error.message || '璇锋鏌ワ細\n1. 鎵撳嵃鏈烘湇鍔℃槸鍚﹀惎鍔╘n2. 鎵撳嵃鏈哄湴鍧�鏄惁姝g‘\n3. 缃戠粶鏄惁閫氱晠',
+ confirmText: '閲嶈瘯',
+ cancelText: '鍙栨秷',
+ success: (res) => {
+ if (res.confirm) {
+ setTimeout(() => {
+ this.PrintHBarCode_HK();
+ }, 1000);
+ }
+ }
});
- CommonUtils.playSound(0);
}
},
-
+
toScanCode() {
var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
mpaasScanModule.mpaasScan({
@@ -754,6 +1028,7 @@
this.cantSplit = false; // 鎷嗙爜鎸夐挳鍙敤
this.cantGenerate = true; // 鐢熸垚鎸夐挳绂佺敤
this.cantPrint = true; // 鎵撳嵃鎸夐挳绂佺敤
+ this.cantPrint_HK = true; // 鎵撳嵃鎸夐挳绂佺敤
}
},
onLoad() {
@@ -794,14 +1069,40 @@
}
//鍒濆鍖栨墦鍗�
this.initPrinter();
-
+ // 棰勮繛鎺ユ捣搴锋墦鍗版満锛堝彲閫夛紝涓嶉樆濉為〉闈級
+ this.connect().catch(err => {
+ console.warn('娴峰悍鎵撳嵃鏈洪杩炴帴澶辫触:', err);
+ });
+ // 娴嬭瘯鎵撳嵃鏈烘湇鍔★紙鍙�夛級
+ setTimeout(() => {
+ this.testPrinterService();
+ }, 1000);
},
onReady() {
},
onUnload() {
- // 璋冪敤鍚屾鏂规硶
-
+ // 娓呯悊瀹氭椂鍣�
+ if (this.wsHeartbeatTimer) {
+ clearInterval(this.wsHeartbeatTimer);
+ this.wsHeartbeatTimer = null;
+ }
+
+ if (this.wsReconnectTimer) {
+ clearTimeout(this.wsReconnectTimer);
+ this.wsReconnectTimer = null;
+ }
+
+ // 鍏抽棴 WebSocket 杩炴帴
+ if (this.socketTask) {
+ this.socketTask.close({
+ code: 1000,
+ reason: '椤甸潰鍗歌浇'
+ });
+ this.socketTask = null;
+ }
+
+ this.wsConnected = false;
}
}
</script>
diff --git a/utils/Print_HK.js b/utils/Print_HK.js
new file mode 100644
index 0000000..12d564b
--- /dev/null
+++ b/utils/Print_HK.js
@@ -0,0 +1,41 @@
+class PrinterWS {
+ constructor(url) {
+ this.ws = uni.connectSocket({
+ url: 'ws://localhost:40002', // 鏀寔 wss(鍔犲瘑) / ws(闈炲姞瀵�)
+ success: () => {
+ console.log('WebSocket 杩炴帴鍒涘缓鎴愬姛');
+ }
+ });
+ this.url = url;
+ //this.connect();
+ }
+
+ // 鍒濆鍖栬繛鎺�
+ connect(url) {
+ this.url = url;
+ this.ws = new WebSocket(this.url);
+ this.ws.onopen = () => {
+ console.log('WebSocket 杩炴帴宸插缓绔�');
+ };
+ this.ws.onmessage = (event) => {
+ try {
+ const response = event.data;
+ var consoleInfo = document.getElementById("console").value;
+ consoleInfo = consoleInfo +"\n" + response;
+ document.getElementById("console").value = consoleInfo;
+ // alert(response);
+ } catch(error) {
+ console.error('娑堟伅瑙f瀽澶辫触:', error);
+ }
+ };
+ this.ws.onerror = (error) => {
+ alert('WebSocket 閿欒:', error);
+ };
+ this.ws.onclose = () => {
+ alert('WebSocket 杩炴帴宸插叧闂�');
+ };
+ }
+}
+
+// 瀵煎嚭鍗曚緥
+export default new PrinterWS();
\ No newline at end of file
--
Gitblit v1.9.1