You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
7.8 KiB
JavaScript

export const pos80 = function () {
var newPrint = document.createElement('iframe');
newPrint.id = 'new-print-js';
newPrint.style.display = 'none';
if (_id('new-print-js') == undefined) {
document.body.appendChild(newPrint);
}
return {
data: {
printD: function (content) {
if (_App.qzStatus() === true) {
var config = qz.configs.create(_App.posprintget());
var data = [{
type: 'pixel',
format: 'html',
flavor: 'plain', // or 'plain' if the data is raw HTML
data: content
}];
qz.print(config, data).catch(function (e) { console.error(e); });
throw 'stop actrion';
}else{
if (content != undefined && typeof content === 'string') {
var w = _id('new-print-js').contentWindow || _id('new-print-js').contentDocument;
console.log(w);
w.document.open()
w.document.write(content);
w.document.close()
w.print();
;
}
};
return this;
},
container: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>POS58</title>
<style>
@media print {
*{
font-family: Arial;
}
@page {
size: 64mm 202mm; /* auto is the initial value */
margin: 0;
}
body {
-webkit-print-color-adjust: exact !important;
print-color-adjust: exact !important;
margin: 0;
}
td{
font-size: 10px;
}
.sheet{
padding-top: 5mm;
padding-right: 5mm;
padding-left: 3mm;
}
}
</style>
</head>
<body class="receipt">
<section class="sheet">
{content}
</section>
</body>
</html>
`,
content: ''
},
content: function (a) {
if (a != undefined && Array.isArray(a)) {
this.data.content = a.map(function (d) {
if (d != null && typeof d === 'object') {
if (d.type != undefined && d.type == 'text') {
var e = el('p')
if (d.css != undefined && typeof d.css === 'object') {
e.css(d.css);
}
if (d.text != undefined && typeof d.text === 'string') {
e.html(d.text);
}
if (d.text != undefined && typeof d.text === 'function') {
e.html(d.text());
}
return e.get().outerHTML;
}
if (d.type != undefined && d.type == 'image') {
var e = el('img')
if (d.css != undefined && typeof d.css === 'object') {
e.css(d.css);
}
if (d.src != undefined && typeof d.src === 'string') {
e.src(d.src);
}
if (d.width != undefined && typeof d.width === 'number') {
e.width(d.width);
}
return div().css('text-align', 'center').child(e).get().outerHTML;
}
if (d.type != undefined && d.type == 'table') {
var e = el('table')
if (d.css != undefined && typeof d.css === 'object') {
e.css('margin-bottom', '5px');
e.css(d.css);
}
if (d.data != undefined && Array.isArray(d.data)) {
d.data.forEach(function (x) {
if (Array.isArray(x)) {
var ax = el('tr');
x.forEach(function (ex) {
if (typeof ex === 'object') {
var h = el('td');
h.css('padding', '3px 0');
h.css('vertical-align', 'top');
if (d.line === true) {
h.css('border-top', '1.5px dashed #333');
}
if (ex.text != undefined && typeof ex.text === 'string') {
h.html(ex.text);
}
if (ex.text != undefined && typeof ex.text === 'function') {
h.html(ex.text());
}
if (ex.colspan != undefined && typeof ex.colspan === 'number') {
h.attr('colspan', ex.colspan);
}
if (ex.rowspan != undefined && typeof ex.rowspan === 'number') {
h.attr('rowspan', ex.rowspan);
}
if (ex.css != undefined && typeof ex.css === 'object') {
h.css(ex.css);
}
h.css('font-size', '14px');
ax.child(h)
}
});
e.child(ax);
}
})
}
return e.get().outerHTML;
}
return '';
}
}).join("");
}
return this;
},
print: function () {
var c = this.data.container;
var x = this.data.content;
var prd = this.data.printD;
var cx = c.replace(/\{content\}/g, x);
prd(cx);
return this;
}
}
};