From 51c7896fd8e45085dd5cdfff11e79a00ee0a7379 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期五, 05 九月 2025 15:16:54 +0800 Subject: [PATCH] 上料/下料、报工/打印机配置/产线选择 、排产工单 --- pages/user/location.vue | 749 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 644 insertions(+), 105 deletions(-) diff --git a/pages/user/location.vue b/pages/user/location.vue index 9128fff..ddb0f93 100644 --- a/pages/user/location.vue +++ b/pages/user/location.vue @@ -1,117 +1,656 @@ <template> - <view> - <cu-custom :bgColor="NavBarColor" :isBack="true"> + <view class="container"> + <cu-custom :bgColor="NavBarColor" :isBack="true" backRouterName="index"> <block slot="backText">杩斿洖</block> - <block slot="content">瀹氫綅</block> + <block slot="content">缃戠粶鎵撳嵃鏈洪厤缃�</block> </cu-custom> - <map - style="width: 100%; height:500px;" - :latitude="latitude" - :longitude="longitude" - :markers="marker" - :scale="scale" - > - </map> - </view> + + <!-- 鎵撳嵃鏈鸿缃尯鍩� --> + <view class="setting-area"> + <view class="input-item"> + <text>鎵撳嵃鏈篒P:</text> + <uni-data-select v-model="printerIP" :localdata="printerList" @change="changePrinterList" + placeholder="璇烽�夋嫨" /> + <!-- <uni-easyinput v-model="printerIP" placeholder="渚嬪: 192.168.1.100" /> --> + </view> + <view class="input-item"> + <text>绔彛鍙�:</text> + <uni-easyinput v-model="printerPort" type="number" placeholder="榛樿: 9100" value="9100" /> + </view> + <view class="input-item"> + <text>鎵撳嵃鏈哄瀷鍙�:</text> + <uni-data-select v-model="printerModel" :localdata="printerModels" placeholder="閫夋嫨鎵撳嵃鏈哄瀷鍙�" /> + </view> + <!-- 骞冲彴闄愬埗鎻愮ず --> + <view class="platform-tip" v-if="isMini || isH5"> + 鈿狅笍 灏忕▼搴�/H5 涓嶆敮鎸佺洿鎺CP杩炴帴锛岄渶閫氳繃鍚庣涓浆 + </view> + <button @click="connectPrinter" :disabled="isConnected || (isMini || isH5)" class="btn primary"> + 杩炴帴鎵撳嵃鏈猴紙浠匒PP鏀寔锛� + </button> + <button @click="connectViaBackend" :disabled="isConnected" class="btn primary-outline" + v-if="isMini || isH5"> + 閫氳繃鍚庣杩炴帴鎵撳嵃鏈� + </button> + <button @click="disconnectPrinter" :disabled="!isConnected" class="btn danger"> + 鏂紑杩炴帴 + </button> + <button @click="testPrint" :disabled="!isConnected" class="btn test"> + 娴嬭瘯鎵撳嵃锛圸PL鎸囦护锛� + </button> + </view> + + <!-- 鎵撳嵃鍐呭鍖哄煙 --> + <view class="print-area" v-if="isConnected"> + <text class="print-title">閫夋嫨鎵撳嵃妯℃澘:</text> + <button @click="printStockLabel" class="btn print">鎵撳嵃鎴愬搧鍏ュ簱鏍囩</button> + <button @click="printTransferOrder" class="btn print">鎵撳嵃绉诲簱鍗�</button> + <button @click="printInspectionForm(1)" class="btn print">鎵撳嵃妫�楠屽崟A</button> + <button @click="printInspectionForm(2)" class="btn print">鎵撳嵃妫�楠屽崟B</button> + </view> + + <!-- 鐘舵�佹樉绀� --> + <view class="status"> + 杩炴帴鐘舵��: {{ isConnected ? '宸茶繛鎺ワ紙TCP锛�' : '鏈繛鎺�' }} + </view> + <view class="log" v-if="logList.length > 0"> + <text class="log-title">鎿嶄綔鏃ュ織:</text> + <view v-for="(log, index) in logList" :key="index" class="log-item"> + {{ log }} + </view> + </view> + </view> </template> <script> + // 寮曞叆璁惧淇℃伅鍒ゆ柇骞冲彴锛圓PP/灏忕▼搴�/H5锛� + import { + getSystemInfo, + isApp, + isMini, + isH5 + } from 'common/util/system.js'; + import PrinterCommands from 'common/util/printer-commands.js'; + export default { - data() { - return { - NavBarColor:this.NavBarColor, - id:0, // 浣跨敤 marker鐐瑰嚮浜嬩欢 闇�瑕佸~鍐檌d - title: 'map', - 銆�latitude: 40.009704, //绾害 - 銆�銆� longitude: 116.374999, //缁忓害 - 銆�銆�銆�marker: [{ - 銆�銆�id:0, - 銆�銆�latitude: 40.009704,//绾害 - 銆�銆�longitude: 116.374999,//缁忓害 - 銆�銆�iconPath: '/static/location.png', //鏄剧ず鐨勫浘鏍� - 銆�銆�rotate:0, // 鏃嬭浆搴︽暟 - 銆�銆�width:20, //瀹� - 銆�銆�height:20, //楂� - 銆�銆� title:'浣犲湪鍝簡',//鏍囨敞鐐瑰悕 - 銆�銆� alpha:0.5, //閫忔槑搴� - 銆�銆� /* label:{//涓烘爣璁扮偣鏃佽竟澧炲姞鏍囩 //鍥犺儗鏅鑹睭5涓嶆敮鎸� - 銆�銆� content:'鍖椾含鍥界偓鍏徃',//鏂囨湰 - 銆�銆�銆� color:'red',//鏂囨湰棰滆壊 - 銆� fontSize:24,//鏂囧瓧澶у皬 - x:5,//label鐨勫潗鏍囷紝鍘熺偣鏄� marker 瀵瑰簲鐨勭粡绾害 - y:1,//label鐨勫潗鏍囷紝鍘熺偣鏄� marker 瀵瑰簲鐨勭粡绾害 - borderWidth:12,//杈规瀹藉害 - borderColor:'pink',//杈规棰滆壊 - 銆� borderRadius:20,//杈规鍦嗚 - 銆� bgColor:'black',//鑳屾櫙鑹� - 銆� padding:5,//鏂囨湰杈圭紭鐣欑櫧 - textAlign:'right'//鏂囨湰瀵归綈鏂瑰紡銆� - }, */ - callout:{//鑷畾涔夋爣璁扮偣涓婃柟鐨勬皵娉$獥鍙� 鐐瑰嚮鏈夋晥 - 銆�銆�content:'鍖椾含鍥界偓鍏徃',//鏂囨湰 - 銆�銆�color:'#ffffff',//鏂囧瓧棰滆壊 - 銆�銆�fontSize:14,//鏂囨湰澶у皬 - 銆�銆�borderRadius:2,//杈规鍦嗚 - 銆�銆� bgColor:'#00c16f',//鑳屾櫙棰滆壊 - 銆�銆�display:'ALWAYS'//甯告樉 - } - // anchor:{//缁忕含搴﹀湪鏍囨敞鍥炬爣鐨勯敋鐐癸紝榛樿搴曡竟涓偣 - // x:0, 鍘熺偣涓虹粰鍑虹殑缁忕含搴� - // y:0, - // } - - }], - scale:16,//鍦板浘缂╂斁绋嬪害 - 銆� 銆�controls:[{//鍦ㄥ湴鍥句笂鏄剧ず鎺т欢锛屾帶浠朵笉闅忕潃鍦板浘绉诲姩 - 銆�銆�id:1,//鎺т欢id - 銆�銆�iconPath:'/static/login3.png',//鏄剧ず鐨勫浘鏍� - clickable:true, - 銆�銆�position:{//鎺т欢鍦ㄥ湴鍥剧殑浣嶇疆 - 銆�銆�left:15, - 銆�銆�top:15, - 銆�銆�width:50, - 銆�銆�height:50 - 銆�銆� }, - 銆�銆�}], - 銆� 銆�circles:[{//鍦ㄥ湴鍥句笂鏄剧ず鍦� - 銆�銆�latitude: 40.009704, - 銆�銆�longitude: 116.374999, - 銆�銆�radius:50,//鍗婂緞 - fillColor:"#ffffffAA",//濉厖棰滆壊 - 銆�銆�color:"#55aaffAA",//鎻忚竟鐨勯鑹� - 銆�銆� strokeWidth:1//鎻忚竟鐨勫搴� - }], - 銆�/* 銆�polyline:[{//鎸囧畾涓�绯诲垪鍧愭爣鐐癸紝浠庢暟缁勭涓�椤硅繛绾胯嚦鏈�鍚庝竴椤� - 銆�銆�銆�銆�points:[ - 銆�銆�{latitude: 40.009153,longitude: 116.374935}, - 銆�銆� {latitude: 40.009704,longitude: 116.374999}, - 銆�銆�銆�銆�], - 銆�銆�銆�銆�color:"#0000AA",//绾跨殑棰滆壊 - 銆�銆�銆�銆�width:2,//绾跨殑瀹藉害 - 銆�銆�銆�銆�dottedLine:true,//鏄惁铏氱嚎 - 銆�銆�銆�銆�arrowLine:true, //甯︾澶寸殑绾� 寮�鍙戣�呭伐鍏锋殏涓嶆敮鎸佽灞炴�� - 銆�銆�}], */ - } - }, - onLoad() { - this.getLocation() + name: 'NetworkPrinter', + data() { + return { + printerList: [], + NavBarColor: this.NavBarColor, + printerIP: '', // 鏂戦┈鎵撳嵃鏈篒P锛堥渶鏇挎崲涓哄疄闄呭�硷級 + printerPort: '9100', // 鏂戦┈榛樿TCP绔彛 + printerModel: 'zebra', // 榛樿涓烘枒椹郴鍒� + printerModels: [{ + value: 'epson', + text: '鐖辨櫘鐢�(EPSON)绯诲垪' + }, + { + value: 'zebra', + text: '鏂戦┈(ZEBRA)绯诲垪' // 閫変腑鏂戦┈ + }, + { + value: 'citizen', + text: '瑗块搧鍩�(CITIZEN)绯诲垪' + }, + { + value: 'generic', + text: '閫氱敤ESC/POS鍏煎' + } + ], + isConnected: false, + socketTask: null, // 鍘熺敓TCP Socket瀹炰緥锛堟浛鎹ocket.io锛� + logList: [], + isMini: false, // 鏄惁涓哄皬绋嬪簭 + isH5: false, // 鏄惁涓篐5 + // 鍚庣涓浆鎺ュ彛鍦板潃锛堝皬绋嬪簭/H5浣跨敤锛� + url: { + list: 'base/printerConfig/queryUserPrinterConfigList' + }, + backendPrintUrl: '/api/printer/print' + }; }, - methods: { - getLocation(){ - uni.getLocation({ - type: 'gcj02', - success: function (res) { - console.log('褰撳墠浣嶇疆鐨勭粡搴︼細' + res.longitude); - console.log('褰撳墠浣嶇疆鐨勭含搴︼細' + res.latitude); - }, - fail: function (res) { - console.log('褰撳墠浣嶇疆鐨勭粡搴�'); - } + onLoad() { + // 鍒濆鍖栵細鍒ゆ柇褰撳墠骞冲彴 + this.initPlatform(); + // 鍔犺浇缂撳瓨閰嶇疆 + this.loadPrinterConfig(); + }, + onUnload() { + // 椤甸潰閿�姣佹椂鏂紑杩炴帴 + this.disconnectPrinter(); + // 淇濆瓨閰嶇疆 + this.savePrinterConfig(); + }, + created() { + this.getPrinterList() + }, + methods: { + changePrinterList(e) { + this.printerIP = e; + console.log(this.printerIP) + }, + getPrinterList() { + this.$http.get(this.url.list, { + params: {}, + + }).then(res => { + //璁剧疆鍒楄〃鏁版嵁 + if (res.data.success) { + this.printerList = res.data.result + } else { + uni.showToast({ + icon: "error", + title: res.data.message, + duration: 2000 + }); + + } + }).catch(() => { + this.$tip.error("鑱旂綉澶辫触") + }) + }, + + // 鍒濆鍖栧钩鍙帮紙鍒ゆ柇APP/灏忕▼搴�/H5锛� + initPlatform() { + // 鐩存帴璋冪敤瀵煎叆鐨勫懡鍚嶆柟娉曪紝涓嶄細鎶ラ敊 + const systemInfo = getSystemInfo(); // 姝g‘锛氳皟鐢ㄥ懡鍚嶅鍑虹殑 getSystemInfo 鍑芥暟 + this.isApp = isApp(); // 姝g‘锛氳皟鐢ㄥ懡鍚嶅鍑虹殑 isApp 鍑芥暟 + this.isMini = isMini(); // 姝g‘锛氳皟鐢ㄥ懡鍚嶅鍑虹殑 isMini 鍑芥暟 + this.isH5 = isH5(); // 姝g‘锛氳皟鐢ㄥ懡鍚嶅鍑虹殑 isH5 鍑芥暟 + this.isMini = systemInfo.platform === 'mp-weixin' || systemInfo.platform === 'mp-alipay'; + this.isH5 = systemInfo.platform === 'h5'; + if (this.isMini || this.isH5) { + this.addLog(`褰撳墠骞冲彴锛�${this.isMini ? '灏忕▼搴�' : 'H5'}锛岄渶閫氳繃鍚庣涓浆`); + } + }, + + // 鍔犺浇淇濆瓨鐨勬墦鍗版満閰嶇疆 + loadPrinterConfig() { + const config = uni.getStorageSync('printerConfig'); + if (config) { + this.printerIP = config.ip || this.printerIP; + this.printerPort = config.port || this.printerPort; + this.printerModel = config.model || this.printerModel; + } + }, + + // 淇濆瓨鎵撳嵃鏈洪厤缃� + savePrinterConfig() { + uni.setStorageSync('printerConfig', { + ip: this.printerIP, + port: this.printerPort, + model: this.printerModel }); + }, + + // 娣诲姞鏃ュ織 + addLog(message) { + const time = new Date().toLocaleTimeString(); + this.logList.unshift(`[${time}] ${message}`); + if (this.logList.length > 20) this.logList.pop(); + }, + + // 1. APP绔細鐩存帴TCP杩炴帴鏂戦┈鎵撳嵃鏈猴紙鏍稿績淇敼锛� + connectPrinter() { + if (!this.printerIP || !this.printerPort) { + uni.showToast({ + title: '璇疯緭鍏P鍜岀鍙�', + icon: 'none' + }); + return; + } + + // 鍏堝叧闂凡鏈夎繛鎺� + if (this.socketTask) this.disconnectPrinter(); + + this.addLog(`姝e湪TCP杩炴帴锛�${this.printerIP}:${this.printerPort}`); + // 鍘熺敓TCP Socket杩炴帴锛坱ype: 'tcp' 蹇呴』鎸囧畾锛� + this.socketTask = uni.createSocket({ + url: `tcp://${this.printerIP}:${this.printerPort}`, + type: 'tcp', // 鏄庣‘鎸囧畾涓篢CP杩炴帴锛堟枒椹墦鍗版満浠呮敮鎸乀CP锛� + success: () => { + this.addLog('Socket鍒涘缓鎴愬姛锛岀瓑寰呰繛鎺�...'); + // 鐩戝惉杩炴帴鎴愬姛 + this.socketTask.onOpen(() => { + this.isConnected = true; + this.addLog('鏂戦┈鎵撳嵃鏈鸿繛鎺ユ垚鍔燂紙TCP锛�'); + this.savePrinterConfig(); + uni.showToast({ + title: '杩炴帴鎴愬姛', + icon: 'success' + }); + }); + // 鐩戝惉杩炴帴閿欒 + this.socketTask.onError((err) => { + this.isConnected = false; + this.addLog(`杩炴帴澶辫触锛�${err.errMsg || '绔彛琚崰鐢ㄦ垨鎵撳嵃鏈虹绾�'}`); + uni.showToast({ + title: '杩炴帴澶辫触锛屾鏌P/绔彛', + icon: 'none' + }); + }); + // 鐩戝惉杩炴帴鏂紑 + this.socketTask.onClose((res) => { + this.isConnected = false; + this.addLog(`杩炴帴鏂紑锛�${res.reason || '鏈煡鍘熷洜'}`); + // 琚姩鏂紑鏃跺皾璇曢噸杩烇紙鍙�夛級 + if (res.code !== 1000) { + setTimeout(() => this.connectPrinter(), 3000); + } + }); + }, + fail: (err) => { + this.addLog(`鍒涘缓Socket澶辫触锛�${err.errMsg}`); + uni.showToast({ + title: '鍒涘缓杩炴帴澶辫触', + icon: 'none' + }); + } + }); + }, + + // 2. 灏忕▼搴�/H5锛氶�氳繃鍚庣涓浆杩炴帴锛堟柊澧烇級 + connectViaBackend() { + // 鍚庣涓浆鏃犻渶鍓嶇寤虹珛TCP锛屼粎闇�淇濆瓨閰嶇疆骞堕獙璇佸悗绔繛閫氭�� + if (!this.printerIP || !this.printerPort) { + uni.showToast({ + title: '璇疯緭鍏P鍜岀鍙�', + icon: 'none' + }); + return; + } + this.addLog(`閫氳繃鍚庣楠岃瘉鎵撳嵃鏈猴細${this.printerIP}:${this.printerPort}`); + // 璋冪敤鍚庣鎺ュ彛楠岃瘉鎵撳嵃鏈虹姸鎬� + uni.request({ + url: '/api/printer/checkStatus', + method: 'POST', + data: { + ip: this.printerIP, + port: this.printerPort + }, + success: (res) => { + if (res.data.success) { + this.isConnected = true; // 鏍囪涓衡�滃悗绔凡杩炴帴鈥� + this.addLog('鍚庣杩炴帴鎵撳嵃鏈烘垚鍔�'); + this.savePrinterConfig(); + uni.showToast({ + title: '鍚庣杩炴帴鎴愬姛', + icon: 'success' + }); + } else { + this.addLog(`鍚庣杩炴帴澶辫触锛�${res.data.message}`); + uni.showToast({ + title: res.data.message, + icon: 'none' + }); + } + }, + fail: (err) => { + this.addLog(`鍚庣鎺ュ彛寮傚父锛�${err.errMsg}`); + uni.showToast({ + title: '鍚庣鎺ュ彛涓嶅彲鐢�', + icon: 'none' + }); + } + }); + }, + + // 鏂紑杩炴帴 + disconnectPrinter() { + if (this.socketTask) { + this.socketTask.close({ + success: () => { + this.isConnected = false; + this.socketTask = null; + this.addLog('宸叉柇寮�TCP杩炴帴'); + uni.showToast({ + title: '宸叉柇寮�杩炴帴', + icon: 'none' + }); + } + }); + } else if (this.isConnected && (this.isMini || this.isH5)) { + // 鍚庣涓浆鍦烘櫙锛氶�氱煡鍚庣鏂紑 + uni.request({ + url: '/api/printer/disconnect' + }); + this.isConnected = false; + this.addLog('宸查�氱煡鍚庣鏂紑杩炴帴'); + uni.showToast({ + title: '宸叉柇寮�杩炴帴', + icon: 'none' + }); + } + }, + + // 3. 鍙戦�乑PL鎸囦护锛堟牳蹇冧慨鏀癸細鐩存帴鍙戦�佷簩杩涘埗鎸囦护锛屾浛鎹ocket.io emit锛� + sendZplCommand(zplCode, retry = 2) { + return new Promise((resolve, reject) => { + // 鍖哄垎APP鐩磋繛鍜屽悗绔腑杞� + if (this.isMini || this.isH5) { + // 灏忕▼搴�/H5锛氶�氳繃鍚庣鍙戦�乑PL + uni.request({ + url: this.backendPrintUrl, + method: 'POST', + data: { + ip: this.printerIP, + port: this.printerPort, + zplCode: zplCode + }, + success: (res) => { + if (res.data.success) resolve(res.data); + else if (retry > 0) { + this.addLog(`鍚庣鎵撳嵃澶辫触锛岄噸璇�(${retry}娆�)...`); + setTimeout(() => this.sendZplCommand(zplCode, retry - 1).then( + resolve).catch(reject), 1000); + } else reject(new Error(res.data.message || '鍚庣鎵撳嵃澶辫触')); + }, + fail: (err) => reject(new Error(`鍚庣璇锋眰澶辫触锛�${err.errMsg}`)) + }); + } else { + // APP绔細鐩存帴TCP鍙戦�乑PL锛堜簩杩涘埗鏍煎紡锛� + if (!this.socketTask || !this.isConnected) { + reject(new Error('鏈缓绔婽CP杩炴帴')); + return; + } + // ZPL鎸囦护杞负Uint8Array锛堥伩鍏嶇紪鐮侀棶棰橈級 + const buffer = new Uint8Array(Buffer.from(zplCode)); + this.socketTask.send({ + data: buffer, + success: () => { + this.addLog('ZPL鎸囦护鍙戦�佹垚鍔�'); + resolve({ + success: true + }); + }, + fail: (err) => { + if (retry > 0) { + this.addLog(`鎸囦护鍙戦�佸け璐ワ紝閲嶈瘯(${retry}娆�)...`); + setTimeout(() => this.sendZplCommand(zplCode, retry - 1).then( + resolve).catch(reject), 1000); + } else reject(new Error(`鍙戦�佸け璐ワ細${err.errMsg}`)); + } + }); + } + }); + }, + + // 4. 鏋勫缓鏂戦┈ZPL鎸囦护锛堟牳蹇冧慨鏀癸細閫傞厤涓枃銆佷簩缁寸爜锛� + buildZpl(data, templateType) { + const commands = new PrinterCommands(this.printerModel); + // 鏂戦┈涓撶敤ZPL鎸囦护鏋勫缓锛堣鐩朠rinterCommands涓搴旀柟娉曪級 + switch (templateType) { + case 'test': + // 娴嬭瘯椤碉細鍚腑鏂囧拰绠�鍗曟枃鏈紙瑙e喅涔辩爜锛� + return `^XA^CI28^CFSIMSUN,30^FO50,50^FD鏂戦┈鎵撳嵃鏈烘祴璇曢〉锛堜腑鏂囷級^FS^FO50,100^FD褰撳墠鏃堕棿锛�${new Date().toLocaleString()}^FS^XZ`; + case 'stockLabel': + // 鎴愬搧鍏ュ簱鏍囩锛氬惈浜岀淮鐮侊紙ZPL鍘熺敓^BQ鎸囦护锛� + return `^XA + ^CI28^CFSIMSUN,24 // UTF-8缂栫爜 + 涓枃瀛椾綋锛圫IMSUN闇�鎻愬墠涓婁紶鍒版墦鍗版満锛� + ^FO30,30^FD璁㈠崟鍙凤細${data.orderNo}^FS + ^FO30,70^FD瀹㈡埛锛�${data.customer}^FS + ^FO30,110^FD鐗╂枡鍙凤細${data.materialNo}^FS + ^FO30,150^FD鎵规鍙凤細${data.batchNo}^FS + ^FO30,190^FD瑙勬牸锛�${data.spec}^FS + ^FO30,230^FD鏁伴噺锛�${data.quantity}浠禴FS + ^FO220,30^BQN,2,10 // 浜岀淮鐮侊細QR Code锛岀籂閿欑瓑绾�2锛屽ぇ灏�10 + ^FDQA,鐗╂枡:${data.materialNo},鎵规:${data.batchNo}^FS // QA鍓嶇紑=QR Code锛屽唴瀹逛负鐗╂枡+鎵规 + ^XZ`.replace(/\s+/g, ''); // 鍘婚櫎澶氫綑绌烘牸锛岄伩鍏嶈В鏋愰敊璇� + case 'transferOrder': + // 绉诲簱鍗曪細绫讳技鍏ュ簱鏍囩锛岃皟鏁村瓧娈� + return `^XA + ^CI28^CFSIMSUN,24 + ^FO30,30^FD绉诲簱鍗曞彿锛�${data.orderNo}^FS + ^FO30,70^FD瀹㈡埛锛�${data.customer}^FS + ^FO30,110^FD鐗╂枡鍙凤細${data.materialNo}^FS + ^FO30,150^FD鎵规鍙凤細${data.batchNo}^FS + ^FO30,190^FD宸ュ巶锛�${data.factory}^FS + ^FO220,30^BQN,2,10 + ^FDQA,绉诲簱鍗�:${data.orderNo},鏁伴噺:${data.quantity}^FS + ^XZ`.replace(/\s+/g, ''); + case 'inspectionA': + case 'inspectionB': + // 妫�楠屽崟锛氬琛屾楠岄」 + let inspectionItems = ''; + data.items.forEach((item, idx) => { + inspectionItems += `^FO30,${110 + idx * 40}^FD${item.name}锛�${item.result}^FS`; + }); + return `^XA + ^CI28^CFSIMSUN,24 + ^FO30,30^FD妫�楠屽崟鍙凤細${data.formNo}^FS + ^FO30,70^FD妫�楠屽憳锛�${data.inspector}^FS + ${inspectionItems} + ^FO220,30^BQN,2,10 + ^FDQA,妫�楠屽崟:${data.formNo},鐗╂枡:${data.materialNo}^FS + ^XZ`.replace(/\s+/g, ''); + default: + throw new Error('鏈煡妯℃澘绫诲瀷'); + } + }, + + // 娴嬭瘯鎵撳嵃锛圸PL鎸囦护锛� + async testPrint() { + try { + const zplCode = this.buildZpl({}, 'test'); + await this.sendZplCommand(zplCode); + this.addLog('娴嬭瘯椤垫墦鍗版垚鍔燂紙ZPL鎸囦护锛�'); + uni.showToast({ + title: '娴嬭瘯鎵撳嵃鎴愬姛', + icon: 'success' + }); + } catch (error) { + this.addLog(`娴嬭瘯鎵撳嵃澶辫触锛�${error.message}`); + uni.showToast({ + title: '鎵撳嵃澶辫触', + icon: 'none' + }); + } + }, + + // 鎵撳嵃鎴愬搧鍏ュ簱鏍囩锛堜娇鐢╖PL锛� + async printStockLabel() { + try { + const data = { + orderNo: '11263797', + customer: '鍚夊埄', + model: '6608268440', + materialNo: '120026829', + batchNo: '25219773', + spec: 'G3-700A', + quantity: 100, + date: '2023/06/07' + }; + const zplCode = this.buildZpl(data, 'stockLabel'); + await this.sendZplCommand(zplCode); + this.addLog('鎴愬搧鍏ュ簱鏍囩鎵撳嵃鎴愬姛'); + uni.showToast({ + title: '鎵撳嵃鎴愬姛', + icon: 'success' + }); + } catch (error) { + this.addLog(`鎵撳嵃澶辫触锛�${error.message}`); + uni.showToast({ + title: '鎵撳嵃澶辫触', + icon: 'none' + }); + } + }, + + // 鎵撳嵃绉诲簱鍗曪紙浣跨敤ZPL锛� + async printTransferOrder() { + try { + const data = { + orderNo: '112379', + productModel: 'G-639', + customer: '涓滄柟鏃ヤ骇', + materialNo: '120047854', + customerModel: '4200-51354', + batchNo: '25159847', + factory: '鍙屾灄鏂扮伀鐐伐鍘�', + quantity: 73 + }; + const zplCode = this.buildZpl(data, 'transferOrder'); + await this.sendZplCommand(zplCode); + this.addLog('绉诲簱鍗曟墦鍗版垚鍔�'); + uni.showToast({ + title: '鎵撳嵃鎴愬姛', + icon: 'success' + }); + } catch (error) { + this.addLog(`鎵撳嵃澶辫触锛�${error.message}`); + uni.showToast({ + title: '鎵撳嵃澶辫触', + icon: 'none' + }); + } + }, + + // 鎵撳嵃妫�楠屽崟锛堜娇鐢╖PL锛� + async printInspectionForm(type) { + try { + const data = { + formNo: type === 1 ? 'JYD-20250801' : 'JYD-20250802', + materialNo: '120026829', + batchNo: '25219773', + inspector: '寮犱笁', + date: new Date().toLocaleDateString(), + items: [{ + name: '澶栬', + result: '鍚堟牸' + }, + { + name: '灏哄', + result: '鍚堟牸' + }, + { + name: '鎬ц兘', + result: type === 1 ? '鍚堟牸' : '寰呮' + } + ] + }; + const zplCode = this.buildZpl(data, `inspection${type === 1 ? 'A' : 'B'}`); + await this.sendZplCommand(zplCode); + this.addLog(`妫�楠屽崟${type}鎵撳嵃鎴愬姛`); + uni.showToast({ + title: '鎵撳嵃鎴愬姛', + icon: 'success' + }); + } catch (error) { + this.addLog(`鎵撳嵃澶辫触锛�${error.message}`); + uni.showToast({ + title: '鎵撳嵃澶辫触', + icon: 'none' + }); + } } - } - } + } + }; </script> -<style> -</style> + +<style scoped> + .platform-tip { + color: #FF3B30; + font-size: 24rpx; + margin-bottom: 15rpx; + padding: 10rpx; + background-color: #FFF8F8; + border-radius: 8rpx; + } + + .btn.primary-outline { + background-color: #fff; + color: #007AFF; + border: 1rpx solid #007AFF; + } + + .container { + padding-bottom: 20rpx; + } + + .setting-area, + .print-area { + padding: 20rpx; + background-color: #fff; + margin: 10rpx; + border-radius: 10rpx; + } + + .input-item { + display: flex; + align-items: center; + margin-bottom: 20rpx; + border-bottom: 1rpx solid #eee; + padding-bottom: 10rpx; + } + + .input-item text { + width: 140rpx; + font-size: 28rpx; + color: #333; + } + + .uni-easyinput { + flex: 1; + } + + .btn { + width: 100%; + padding: 20rpx; + margin-bottom: 15rpx; + border-radius: 8rpx; + color: #fff; + font-size: 28rpx; + } + + .primary { + background-color: #007AFF; + } + + .danger { + background-color: #FF3B30; + } + + .print { + background-color: #00C853; + } + + .test { + background-color: #FF9500; + } + + .print-title { + display: block; + font-size: 28rpx; + color: #666; + margin-bottom: 15rpx; + } + + .status { + padding: 20rpx; + font-size: 28rpx; + color: #666; + } + + .log { + margin: 10rpx; + padding: 20rpx; + background-color: #f5f5f5; + border-radius: 10rpx; + } + + .log-title { + font-weight: bold; + display: block; + margin-bottom: 10rpx; + color: #333; + } + + .log-item { + font-size: 26rpx; + color: #666; + margin-bottom: 5rpx; + word-break: break-all; + } +</style> \ No newline at end of file -- Gitblit v1.9.3