UNPKG

tplus-pos

Version:

pos module

316 lines (249 loc) 14.4 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrintProcessor = undefined; var _regenerator = require('babel-runtime/regenerator'); var _regenerator2 = _interopRequireDefault(_regenerator); var _stringify = require('babel-runtime/core-js/json/stringify'); var _stringify2 = _interopRequireDefault(_stringify); var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _tplusPoslogin = require('tplus-poslogin'); var _mutantsMicrofx = require('mutants-microfx'); var _tplusComponentsTouch = require('tplus-components-touch'); var _tplusApi = require('tplus-api'); var _PrintApi = require('../../../api/PrintApi'); var _PrintApi2 = _interopRequireDefault(_PrintApi); require('../../../commom/Base64'); require('../../../commom/Challenger'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * 打印 */ var PrintProcessor = exports.PrintProcessor = function () { function PrintProcessor() { (0, _classCallCheck3.default)(this, PrintProcessor); } (0, _createClass3.default)(PrintProcessor, null, [{ key: 'execute', /** * 打印 * @param {*} dtoID * @param {*} PrintDetailEntity */ value: function () { var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(dtoID, PrintDetailEntity) { var userId, userName, userParams, ot, printerName, printTemplateID, bizCode, voucherName, printCount, printClass, IsEnablePrinter, isAutoCut, checkedPrintType, printFileName, printStorageOld, curtemplate, rjson, taskdata, printcfgjson, printcfgjsonObj, template, printStorage, index; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: //用户信息 userId = (0, _tplusPoslogin.PosInitData)('UserId'); userName = (0, _tplusPoslogin.PosInitData)('UserName'); userParams = (0, _stringify2.default)({ userId: userId, userName: userName }); _context.prev = 3; ot = {}; // 模板ID // let printTemplateID = '544'; // 打印机名称 printerName = PrintDetailEntity.printerName; // 打印模板名称 printTemplateID = PrintDetailEntity.printTemplateID; // 单据编码 bizCode = PrintDetailEntity.bizCode; // 单据名称 voucherName = PrintDetailEntity.voucherName; // 打印次数 printCount = PrintDetailEntity.printCount; // 打印分类 printClass = PrintDetailEntity.printClass; // 是否启用打印机 IsEnablePrinter = PrintDetailEntity.IsEnablePrinter; isAutoCut = PrintDetailEntity.isAutoCut; if (IsEnablePrinter) { _context.next = 15; break; } return _context.abrupt('return'); case 15: if (dtoID) { _context.next = 18; break; } // Message.warn("单据ID为空,不能打印!"); console.warn("单据ID为空,不能打印!"); return _context.abrupt('return'); case 18: if (printTemplateID && Number.isNumber(printTemplateID)) { _context.next = 21; break; } _tplusComponentsTouch.Message.warn("打印模板没有设置,请设置!"); return _context.abrupt('return'); case 21: // 映美打印机 checkedPrintType = _mutantsMicrofx.localStore && _mutantsMicrofx.localStore.get('checkedPrintType'); if (!(checkedPrintType === "2")) { _context.next = 24; break; } return _context.abrupt('return', this.yinMeiPrint(dtoID, PrintDetailEntity)); case 24: $T.debugger(); // 打印模板ID ot.CurTemplateID = printTemplateID; //this.refs.ctlTemplates.props.selid; // 单据名称 ot.VoucherName = voucherName; ot.PrintClass = printClass; ot.Action = "print"; // 预览 ot.FastPreView = false; // 单据ID ot.voucherID = dtoID; ot.bizCode = bizCode; ot.ExtendProperty = PrintDetailEntity.ExtendProperty; printFileName = Base64.decode((0, _tplusPoslogin.PosInitData)("PrintTemplate")) + "_PRINT_" + printTemplateID + "_bof"; printStorageOld = JSON.parse(localStorage.getItem(printFileName)); curtemplate = null; if (printStorageOld && printStorageOld.templateTS) { // 模板TS,检验并发 ot.templateTS = printStorageOld.templateTS; curtemplate = printStorageOld.template; } else { ot.templateTS = ""; } console.log("GetBillOneTaskAll参数:" + (0, _stringify2.default)(ot)); _context.next = 40; return _PrintApi2.default.GetBillOneTaskAll((0, _stringify2.default)(ot)); case 40: rjson = _context.sent; (0, _tplusApi.serverLog)('newretail', { eventId: 'SettleSuccessProcess_PrintProcessor_GetBillOneTaskAll_after', param: userParams }); console.log("GetBillOneTaskAll结果:" + rjson); taskdata = rjson.taskdata; console.log(taskdata); printcfgjson = rjson.printcfgjson; // 打印机设置 if (printerName) { printcfgjsonObj = JSON.parse(printcfgjson); if (printcfgjsonObj.FormPrint) { printcfgjsonObj.FormPrint.PrinterName = printerName; //标识为小票打印 printcfgjsonObj.FormPrint.PrintMode = 'ticket-voucher'; } if (printcfgjsonObj.LabelPrint) { printcfgjsonObj.LabelPrint.PrinterName = printerName; printcfgjsonObj.LabelPrint.LeftMargin = 0; } printcfgjson = (0, _stringify2.default)(printcfgjsonObj); } console.log(printcfgjson); template = rjson.template; console.log(template); if (rjson.ts) { console.log("GetBillOneTaskAll结果ts:" + rjson.ts); printStorage = {}; printStorage.template = template; printStorage.templateTS = rjson.ts; localStorage.setItem(printFileName, (0, _stringify2.default)(printStorage)); curtemplate = template; } if (!printCount && printCount !== 0) { printCount = 1; } printCount = Number(printCount); for (index = 0; index < printCount; index++) { this.print(curtemplate, printcfgjson, taskdata, isAutoCut, printerName, userParams); } console.log(printFileName); _context.next = 60; break; case 57: _context.prev = 57; _context.t0 = _context['catch'](3); (0, _tplusApi.serverLog)('newretail', { eventId: 'SettleSuccessProcess_PrintProcessor_error', param: userParams }); case 60: case 'end': return _context.stop(); } } }, _callee, this, [[3, 57]]); })); function execute(_x, _x2) { return _ref.apply(this, arguments); } return execute; }() }, { key: 'print', value: function print(curtemplate, printcfgjson, taskdata, isAutoCut, printerName, userParams) { try { $T.debugger(); var params = {}; var taskdataObj = JSON.parse(taskdata); var printinfo = taskdataObj.printinfo; if (printinfo && printinfo.cis == "0" || printinfo.cis <= 0 || printinfo.cis == "-1") { // 打印次数为0的场合 return; } params.curtemplate = curtemplate; params.printcfgjson = printcfgjson; params.taskdata = taskdata; // 打印 _mutantsMicrofx.nativeMs.setIpcRendererMethod('PrintBillone', params, function (arg) {}); (0, _tplusApi.serverLog)('newretail', { eventId: 'SettleSuccessProcess_PrintProcessor_PrintBillone_after_', param: userParams }); // 切纸 if (isAutoCut) { _mutantsMicrofx.nativeMs.setIpcRendererMethod('PrinterRunJob', { printer: printerName, code: '' }, function (ret) { console.log('打印切纸:' + ret); }); } } catch (error) { (0, _tplusApi.serverLog)('newretail', { eventId: 'SettleSuccessProcess_PrintProcessor_PrintBillone_error', param: userParams }); } } }, { key: 'yinMeiPrint', value: function () { var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(dtoID, PrintDetailEntity) { var printerName, printTemplateID, bizCode, printCount, printClass, ExtendProperty, printJobInfo; return _regenerator2.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: printerName = PrintDetailEntity.printerName, printTemplateID = PrintDetailEntity.printTemplateID, bizCode = PrintDetailEntity.bizCode, printCount = PrintDetailEntity.printCount, printClass = PrintDetailEntity.printClass, ExtendProperty = PrintDetailEntity.ExtendProperty; printJobInfo = { bizCode: bizCode, voucherID: dtoID, printClass: printClass, cloudPrinterId: printerName, printTemplateId: printTemplateID, clientDesc: "", copies: printCount, extendProperty: ExtendProperty }; _context2.next = 4; return _PrintApi2.default.PrintByYinMei({ printJobInfo: printJobInfo }); case 4: return _context2.abrupt('return', _context2.sent); case 5: case 'end': return _context2.stop(); } } }, _callee2, this); })); function yinMeiPrint(_x3, _x4) { return _ref2.apply(this, arguments); } return yinMeiPrint; }() }]); return PrintProcessor; }(); //# sourceMappingURL=PrintProcessor.js.map