<object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
<embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
</object>
createPrint()
LODOP.SET_PRINT_PAGESIZE(3,550,45,"");//这里3表示纵向打印且纸高“按内容的高度”;1385表示纸宽138.5mm;45表示页底空白4.5mm
//LODOP.PRINT_DESIGN();//打印设置
//LODOP.PREVIEW();//打印预览
LODOP.PRINT();//打印
<script>
//打印小票
function createPrint() {
console.log(ytobj);
var hPos=10,//小票上边距
pageWidth=550,//小票宽度
rowHeight=15,//小票行距
LODOP=getLodop();
biaoti = "标题"
LODOP.PRINT_INITA(0,0,100,100,"测试");
LODOP.ADD_PRINT_TEXT(hPos,20,pageWidth,rowHeight,biaoti);
LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
hPos+=10;
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"顾客姓名:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,ytobj[0].shname);
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"顾客手机:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,ytobj[0].shtel);
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
hPos+=20;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"收货地址:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
LODOP.ADD_PRINT_TEXT(70,60,120,hPos,ytobj[0].shaddr);
LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
hPos+=20;
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"订单日期:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,getDate24Hours());
LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"--------------------------------");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
hPos+=20;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"商品名称");
LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,"单价");
LODOP.ADD_PRINT_TEXT(hPos,110,pageWidth,rowHeight,"数量");
LODOP.ADD_PRINT_TEXT(hPos,140,pageWidth,rowHeight,"小计");
LODOP.ADD_PRINT_TEXT(hPos,110,pageWidth,rowHeight,"数量");
hPos+=20;
// 遍历json的商品数组
for(var i = 0; i<ytobj.length; i++){
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,ytobj[i].sptm);
LODOP.ADD_PRINT_TEXT(hPos,82,pageWidth,rowHeight,ytobj[i].sppm);
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,10,pageWidth,rowHeight,ytobj[i].spdj);
LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,"X");
LODOP.ADD_PRINT_TEXT(hPos,70,pageWidth,rowHeight,ytobj[i].spsl);
LODOP.ADD_PRINT_TEXT(hPos,120,pageWidth,rowHeight,ytobj[i].spdj * ytobj[i].spsl);
// LODOP.ADD_PRINT_TEXT(hPos,140,pageWidth,rowHeight,json.goodsList[i].total);
hPos+=20;
}
//商品遍历打印完毕,空一行
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"--------------------------------");
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"订单门店:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
LODOP.ADD_PRINT_TEXT(hPos,60,pageWidth,rowHeight,ytobj[0].umd + ytobj[0].tichengzhongjie);
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"订单总金额:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
LODOP.ADD_PRINT_TEXT(hPos,80,pageWidth,rowHeight,ytobj[0].dingdanze);
hPos+=rowHeight;
LODOP.ADD_PRINT_TEXT(hPos,1,pageWidth,rowHeight,"小票流水号:");
LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
LODOP.ADD_PRINT_TEXT(hPos,80,pageWidth,rowHeight,ytobj[0].liushuihao);
}
/当前yy-MM--dd HH:mm:ss格式时间代码
function getDate24Hours() {
let myDate = new Date();
let years = myDate.getFullYear();
let month = myDate.getMonth();
let day = myDate.getDate();
let hours = myDate.getHours();
let minutes = myDate.getMinutes();
let seconds = myDate.getSeconds();
month = month + 1;
if (month < 10) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
if (hours < 10) {
hours = "0" + hours;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
let time = years + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
// console.log("24-hours:" + time);
return time;
}
</script>