/** * Shopex OMS * * Copyright (c) 2025 Shopex (http://www.shopex.cn) * Licensed under Apache-2.0 with additional terms (See LICENSE file) */ (function() { this.initPrinter = function(type,options){ switch (type) { case 'shopex': return new ShopexPrinter(options); case 'cainiao': return new CaiNiaoPrinter(options); case 'pdd': return new PddPrinter(options); case 'jd': return new JdPrinter(options); case 'douyin': return new DouyinPrinter(options); case 'kuaishou': return new KuaishouPrinter(options); case 'wphvip': return new WphvipPrinter(options); case 'lodop': return new LodopPrinter(options); case 'sf': return new SfPrinter(options); case 'xhs': return new XhsPrinter(options); case 'wxshipin': return new WxshipinPrinter(options); case 'dewuppzf': // 得物品牌直发 return new DewuppzfPrinter(options); case 'dewuppzfzy': // 得物品牌直发自研 return new DewuppzfzyPrinter(options); case 'meituan4bulkpurchasing': return new Meituan4bulkpurchasingPrinter(options); case 'youzan': return new CaiNiaoPrinter(options); } return null; }; var Printer = new Class({ Implements: [Events, Options], options:{ data:{}, // 打印数据 template:'', // 打印模板 template_url:'', custom_template_url:'', custom_data:{}, activex:null,// 控件 type:0,// 纸张类型,0:快递单(套打),1:分页输出(标准), 2:卷筒输出, 3:卷筒自适应 brower:2, /* onPrintSuccess: function(responseText){}, onPreview: function(responseText){}, onGetPrinters: function(responseText){}, onPrintComplete: function(responseText){}, onPrinterConfig:function(){}, onOpen:function(){}, onClose:function(){}, onError:function(){}, onMoveto:function(){}*/ }, initialize: function(options){ this.setOptions(options); this.destatus = 'ready'; this.demsg = ''; }, print:function(printer){}, preview:function(printer){}, getPrinters:function(){}, setPrinterConfig:function(printer){}, moveto:function(page){}, isReady:function(){}, // loadReport:function(data,template){}, setPrinters:function(element,data){ var offsetx = element.getParent('#print-preview').getElement('#offsetx'); var offsety = element.getParent('#print-preview').getElement('#offsety'); var thermal = element.getParent('#print-preview').getElement('#thermal'); if (!data.printerlist) return 0; var select = new Element('select',{ id:'printerlist', name:'printerlist', class:'x-input-select inputstyle', styles:{ width:'width:130px;' }, events:{ change:function(){ var optionSelected = this.getElement('option:selected'); // 设置偏移量 if ($defined(offsetx)) offsetx.set('value',optionSelected.get('x')); if ($defined(offsety)) offsety.set('value',optionSelected.get('y')); // 设置热敏 if ($defined(thermal)) thermal.set('checked', optionSelected.get('isThermal')?true:false); } } }); var optionDefault = []; data.printerlist.each(function(printer){ var option = new Element('option',{ value:printer.printername, text:printer.printername, selected:data.default==printer.printername?true:false, x:printer.x, y:printer.y, isThermal:printer.isThermal }); select.adopt(option); // 自动匹配打印机 // if (printer.printername.contains("<{$express_company_no|default:0123456789}>")) { // optionDefault[2] = option; // } if (data.lastSelected.express == printer.printername) { optionDefault[1] = option; } if (data.default == printer.printername) { optionDefault[0] = option; } }); if (optionDefault.length) { var optionSelected = optionDefault.getLast(); optionSelected.selected=true; // 设置偏移量 if ($defined(offsetx)) offsetx.set('value',optionSelected.get('x')); if ($defined(offsety)) offsety.set('value',optionSelected.get('y')); // 设置热敏 if ($defined(thermal)) thermal.set('checked', 'true'==optionSelected.get('isThermal')?true:false); } element.adopt(select); return data.printerlist.length; }, decryptAsync:function(nums){ this.destatus = 'running'; this.demsg = '数据解密中'; var data = this.options.data; if (typeof this.options.data === 'string'){ data = JSON.decode(data); } this.iTotal = data.length; this.iSucc = 0; this.queueNum = nums || 1; this.finishQueueNum = 0; this.fireEvent('decryptStart',{t:this.iTotal,s:this.iSucc}); for(var i = 0; i < this.queueNum; i++) { this.decryptAsyncProcess(i,data); } }, decryptAsyncProcess:function(idx,data) { if(idx >= this.iTotal) { this.finishQueueNum++; if(this.finishQueueNum

正在获取打印数据,请稍等......

需处理 0 条,已处理 0 条,其中失败 0 条。
 
'}), { title:'获取打印数据', width:600, height:130, resizeable:false, }); $E('#total', this.encryptPrintDataDialog).setText(this.iTotal); for(var i = 0; i < this.queueNum; i++) { this.getEncryptPrintDataProcess(i,data); } }, getEncryptPrintDataProcess: function(idx,data) { var _this = this; if(idx >= this.iTotal) { this.finishQueueNum++; if(this.finishQueueNum

正在获取打印数据,请稍等......

需处理 0 条,已处理 0 条,其中失败 0 条。
 
'}), { title:'获取打印数据', width:600, height:130, resizeable:false, }); $E('#total', this.encryptPrintDataDialog).setText(this.iTotal); for(var i = 0; i < this.queueNum; i++) { this.getEncryptPrintDataProcess(i,data); } }, getEncryptPrintDataProcess: function(idx,data) { var _this = this; if(idx >= this.iTotal) { this.finishQueueNum++; if(this.finishQueueNum { if (result.code === 1) { _this.fireEvent('printSuccess', waybill); } else { _this.fireEvent('printFailure', waybill); } }; delete task.waybill; console.log(task); this.SCPPrint.print(JSON.decode(JSON.encode(task)), callback, {lodopFn: 'PRINT'}); }.bind(this)); return true; }, preview:function(printer){ if (!this.isReady()) { return false; } let _this = this; const callback = (result) => { }; this.formatData(this.options.data,printer.name,true).each(function(task){ delete task.waybill; console.log(task); this.SCPPrint.print(JSON.decode(JSON.encode(task)), callback, {lodopFn: 'PREVIEW'}); }.bind(this)); return true; }, getPrinters:function(){ if (!this.isReady()) { return false; } let _this = this; const callback = (result) => { if (result.code === 1) { _this.fireEvent('getPrinters', result); } }; this.SCPPrint.getPrinters(callback); return true; }, formatData:function(data,spooler,is_preview){ var documents = []; data.each(function(printData){ var documentID = printData.batch_logi_no ? printData.batch_logi_no : printData.logi_no; let content = { masterWaybillNo: printData.logi_no, isPrintLogo: true, waybillNoCheckType: 2, waybillNoCheckValue: printData.waybill_no_check, }; var jsonPacket = printData.json_packet ? JSON.decode(printData.json_packet.replace(/“/g, '"')) : {}; if(jsonPacket.mailno_md) { if(documents.length == 1) { documents[0][seq] = 1; documents[0][sum] = data.length; } content.masterWaybillNo = jsonPacket.mailno_md; content.branchWaybillNo = printData.logi_no; content.seq = documents.length + 1; content.sum = data.length; } if(this.options.custom_template_code) { content.customData = this.options.custom_data; } documents.push(content); }.bind(this)); return this.transPrintData(documents,spooler,is_preview); }, transPrintData:function(documents,spooler,is_preview){ this.SCPPrint.setPrinter(spooler); var tasks = []; var taskDocNum = 10; for (var i = 0,len=documents.length;i