// 布局代码
<
p
id
=
"print"
>
<
p
id
=
"print_content"
></
p
>
</
p
>
//js 部分代码var f = document.getElementById('printf');
if (f) {
document.getElementById("print_content").removeChild(f);
}
var printhtml = `
<
p
style
=
"font-size:12px;margin-left: -6px;"
>
<
p
style
=
"margin-left:40px;"
>${this.ticket.title}</
p
>
<
p
>--------------------------------------</
p
>
<
p
>提货点:${this.ticket.pickUpAddress}</
p
>
<
p
>商品名称:${this.ticket.commodityName}</
p
>
<
p
>下单时间:${this.ticket.paymentTime}</
p
>
<
p
>提货人:${this.ticket.receiver}</
p
>
<
p
>联系电话:${this.ticket.receiverPhone}</
p
>
<
p
>提货码:${this.ticket.pickUpCode}</
p
>
<
p
>提货时间:${this.ticket.submissionTime}</
p
>
<
p
style
=
"color:#FFFFFF"
>.</
p
>
</
p
>`
if (!!window.ActiveXObject || "ActiveXObject" in window) { // 针对IE进行适配
var HKEY_Root, HKEY_Path, HKEY_Key;
HKEY_Root = "HKEY_CURRENT_USER";
HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//设置网页打印的页眉页脚为空
function PageSetup_Null() {
var Wsh = new ActiveXObject("WScript.Shell");
HKEY_Key = "header";
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
HKEY_Key = "footer";
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
HKEY_Key = "margin_left"
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0"); //键值设定--左边边界
HKEY_Key = "margin_top"
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0"); //键值设定--上边边界
HKEY_Key = "margin_right"
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0"); //键值设定--右边边界
HKEY_Key = "margin_bottom"
Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "0"); //键值设定--下边边界
}
printhtml = `
<
p
style
=
"font-size:12px;font-weight: 800;height:150px;width:300px"
>
<
p
style
=
"margin-left:35px"
>${this.ticket.title}</
p
>
<
p
>------------------------------------------------</
p
>
<
p
>提货点:${this.ticket.pickUpAddress}</
p
>
<
p
>商品名称:${this.ticket.commodityName}</
p
>
<
p
>下单时间:${this.ticket.paymentTime}</
p
>
<
p
>提货人:${this.ticket.receiver}</
p
>
<
p
>联系电话:${this.ticket.receiverPhone}</
p
>
<
p
>提货码:${this.ticket.pickUpCode}</
p
>
<
p
>提货时间:${this.ticket.submissionTime}</
p
>
<
p
style
=
"color:#FFFFFF;font-weight: 100;"
>.</
p
>
</
p
>`
}
var iframe = document.createElement('iframe');
iframe.id = 'printf';
iframe.style.width = '0';
iframe.style.height = '0';
iframe.style.border = "none";
document.getElementById("print_content").appendChild(iframe);
setTimeout(() => {
iframe.contentDocument.write(printhtml);
iframe.contentDocument.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
}, 100)