tplus-pos
Version:
pos module
246 lines (187 loc) • 10.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.HangUpPrintProcessor = 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 _PrintApi = require('../../../api/PrintApi');
var _PrintApi2 = _interopRequireDefault(_PrintApi);
var _tplusPoslogin = require('tplus-poslogin');
var _mutantsMicrofx = require('mutants-microfx');
require('../../../commom/Base64');
require('../../../commom/Challenger');
var _tplusComponentsTouch = require('tplus-components-touch');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* 打印
*/
var HangUpPrintProcessor = exports.HangUpPrintProcessor = function () {
function HangUpPrintProcessor() {
(0, _classCallCheck3.default)(this, HangUpPrintProcessor);
}
(0, _createClass3.default)(HangUpPrintProcessor, null, [{
key: 'execute',
/**
* 打印
* @param {*} dto
* @param {*} PrintDetailEntity
*/
value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(dto, PrintDetailEntity) {
var ot, printerName, printTemplateID, bizCode, voucherName, printCount, printClass, IsEnablePrinter, isAutoCut, printFileName, printStorageOld, curtemplate, _ref2, _ref2$loginInfo, loginInfo, rjson, taskdata, printcfgjson, printcfgjsonObj, template, printStorage, index;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
console.log("挂单打印模板ID:" + PrintDetailEntity.printTemplateID);
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 = 12;
break;
}
return _context.abrupt('return');
case 12:
if (printTemplateID && Number.isNumber(printTemplateID)) {
_context.next = 15;
break;
}
_tplusComponentsTouch.Message.warn("打印模板没有设置,请设置!");
return _context.abrupt('return');
case 15:
$T.debugger();
// 打印模板ID
ot.CurTemplateID = printTemplateID; //this.refs.ctlTemplates.props.selid;
// 单据名称
ot.VoucherName = voucherName;
ot.PrintClass = printClass;
ot.Action = "print";
// 预览
ot.FastPreView = false;
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 = "";
}
if (dto) dto.deserializationway = 'ajaxpro';
if (!dto.Store) dto.Store = {};
_ref2 = _mutantsMicrofx.localStore.get('user') || {}, _ref2$loginInfo = _ref2.loginInfo, loginInfo = _ref2$loginInfo === undefined ? {} : _ref2$loginInfo;
dto.Store.Name = _tplusPoslogin.TStore.restore().storeName;
dto.Store.Telephone = loginInfo.StoreTelephone;
if (dto.RetailDetails && dto.RetailDetails instanceof Array) {
dto.TotalCount = dto.RetailDetails.Sum("Quantity");
}
ot.DraftDto = (0, _stringify2.default)(dto);
console.log("GetBillOneTaskAll参数:" + (0, _stringify2.default)(ot));
_context.next = 37;
return _PrintApi2.default.GetBillOneTaskAll((0, _stringify2.default)(ot));
case 37:
rjson = _context.sent;
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);
}
console.log(printFileName);
case 51:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function execute(_x, _x2) {
return _ref.apply(this, arguments);
}
return execute;
}()
}, {
key: 'print',
value: function print(curtemplate, printcfgjson, taskdata, isAutoCut, printerName) {
$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) {});
// 切纸
if (isAutoCut) {
_mutantsMicrofx.nativeMs.setIpcRendererMethod('PrinterRunJob', { printer: printerName, code: '' }, function (ret) {
console.log('打印切纸:' + ret);
});
}
}
}]);
return HangUpPrintProcessor;
}();
//# sourceMappingURL=HangUpPrintProcessor.js.map