function prints(){
var length=$('div input[type=checkbox]:checked').length;
if(length!=0){
var checked=$('div input[type=checkbox]:checked');
var array=[];
for(var i=0;i<length;i++){
var deskId=checked[i].value;
array.push(deskId);
}
//數組轉字符串
var str=array.join(",");
console.log(str)
}else{
var checked=$('div input[type=checkbox]');
var length=$('div input[type=checkbox]').length;
var array=[];
for(var i=0;i<length;i++){
var deskId=checked[i].value;
array.push(deskId);
}
//數組轉字符串
var str=array.join(",");
console.log(str)
}
$.ajax({
type:"post",
url:"admin/addqrcode",
data:{ids:str,shopid:shopid},
dataType:"json",
success: function(d){
var imgstr='';
var arr = str.split(',');
var j=0;
var z=0;
var x=0;
for(var i=0;i<arr.length;i++){
console.log(arr[i])
if(j<9){
if(arr[i]!=','){
imgstr+='<li class="mian" id="page1">'+
'<div class="codestyle">'+
'<img id="code_'+arr[i]+'">'+
'<p class="ziti">'+arr[i]+'</p>'+
'</div> </li>';
j++;
}
}else{
if(arr[i]!=','){
if(x%9==0){
z=0;
}
if(z<3){
imgstr+='<li class="mian" id="page1" style="margin-top: 178px;">'+
'<div class="codestyle">'+
'<img id="code_'+arr[i]+'">'+
'<p class="ziti">'+arr[i]+'</p>'+
'</div> </li>';
z++;
x++;
}/* else if(z==3){
z=0;
} */
else{
imgstr+='<li class="mian" id="page1">'+
'<div class="codestyle">'+
'<img id="code_'+arr[i]+'">'+
'<p class="ziti">'+arr[i]+'</p>'+
'</div> </li>';
z++;
x++;
}
}
}
}
$('#imgsrc2').html(imgstr)
var shopid='${admin.shopId}';
for(var j=0;j<arr.length;j++){
if(arr[j]!=','){
$.ajax({
type:"post",
url:"admin/addqrcode",
data:{ids:arr[j],shopid:shopid},
dataType:"json",
success: function(d){
console.log(d.data.serverFilePath)
$('#code_'+d.data.deskId+'').attr("src",""+d.data.serverFilePath+"")
/* console.log($('#code_'+arr[j]+'').attr('src')) */
}
});
}
}
}
});
}
jQuery.browser={};
(function(){
jQuery.browser.msie=false;
jQuery.browser.version=0;
if(navigator.userAgent.match(/MSIE ([0-9]+)./)){
jQuery.browser.msie=true;
jQuery.browser.version=RegExp.$1;
}
})();
function printdiv(printpage) {
var bdhtml = window.document.body.innerHTML;
var sprnstr = "<!--startprint-->"; //用於截斷字符串的內容,截取到指定的圖片內容了
var eprnstr = "<!--endprint-->";
var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
console.log(prnhtml)
window.document.body.innerHTML = prnhtml;
if (getExplorer() == "IE") {
pagesetup_null();
}
window.print();
location.reload()//重載頁面,本地刷新
}
//獲取瀏覽器類型
function getExplorer() {
var explorer = window.navigator.userAgent;
/* return "IE"; */
//ie
if (explorer.indexOf("MSIE") >= 0) {
return "IE";
}
//firefox
else if (explorer.indexOf("Firefox") >= 0) {
return "Firefox";
}
//Chrome
else if (explorer.indexOf("Chrome") >= 0) {
return "Chrome";
}
//Opera
else if (explorer.indexOf("Opera") >= 0) {
return "Opera";
}
//Safari
else if (explorer.indexOf("Safari") >= 0) {
return "Safari";
}
}
//IE設置去除頁眉頁腳
function pagesetup_null() {
var hkey_root, hkey_path, hkey_key;
hkey_root = "HKEY_CURRENT_USER";
hkey_path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
try {
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key = "header";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
hkey_key = "footer";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
} catch (e) { }
}
打印時須要在style中寫入
<style>
@media print {
.mian {
background: url(http://diancan.earlymr.com:8080/order_meal/images/A4.png) no-repeat 0px 0px !important;
-webkit-print-color-adjust: exact;
width: 33%;
height: 321px;
/* background-color:
page-break-after:always;
position: relative;
list-style: none;
}
.codestyle{
position: absolute;
justify-content: center;
left: 45px;
top: 96px;
}
.codestyle img {
width: 140px;
height: 140px;
}
.ziti{
text-align: center;
font-family: inherit;
font-size: 27px;
margin: -4px;
}
.zhuti{
/* display: -ms-flexbox;
width: 1000px;
margin-top: 45px; */
/* width: 312px; */
margin-top: 45px;
flex-wrap: wrap;
display: flex;
/* width: 650px;
height: 929px; */
/* display: -webkit-box; */
}
}
</style>
複製代碼