介绍:
以我的曾经做过代码为例子
图例

html
/*在html需要有一块区域用来放打印内容的*/
js进行动态填充
/*对应动态的数据填充,各位可以自己删掉然后写死数据进行查看*/ $("#printBtn").click(function(){ goodsPrint(mainData); }); //干线运输商品明细打印 function goodsPrint(mainData){ mutils.post({ url: '/trunklinesch/getGoodsPrint', data: { tranDeliverBillId:mainData.TRAN_DELIVER_BILL_ID, }, success: function(result) { if (result.success) { var data = result.data; var content =printGoodsTemplate(data.topData,data.bodyData,mainData); $("#printContet").append(content); print("printContet");//调用打印 } } }); } //打印运输商品明细模板 function printGoodsTemplate(topData,bodyData,mainData){ var dataContet =""+ "
" + "
" + "
"+$("#distDeptCode").next().find("input").val()+"物流中心 本单视同
"+ "
干线运输单(商品明细)准运证
"+ /*"
1/1
" + */ "
" + "
" + "
" + "
" + "
" + "
" + "
干线运输单号:
"+isNullOrUndef(mainData.TRAN_DELIVER_BILL_ID)+"
" + "
目的站点:
"+isNullOrUndef(topData.DELIVER_DATE)+"
" + "
送货日期:
"+isNullOrUndef(topData.DIST_STATION_NAME)+"
" + "
" + "
" + "
封签号:
"+isNullOrUndef(topData.SEAL_OFF_NO)+"
" + "
车辆牌号:
"+isNullOrUndef(topData.VEHICLE_TRADEMARK)+"
" + "
车辆型号:
"+isNullOrUndef(topData.VEHICLE_MODEL_NAME)+"
" + "
驾驶员:
"+isNullOrUndef(topData.DELIVER_NAME)+"
" + "
" + "
" + " " + "
" + "
" + "
货主 " + "
业务类型 " + "
商品代码 " + "
商品名称 " + "
订单数 " + "
单位 " + "
单价 " + "
数量 " + "
"; for(i in bodyData){ dataContet+= "
"+ "
"+isNullOrUndef(bodyData[i].SUPPLY_NAME)+" "+ "
"+isNullOrUndef(bodyData[i].OPER_TYPE_NAME)+" "+ "
"+isNullOrUndef(bodyData[i].BRAND_ID)+" "+ "
"+isNullOrUndef(bodyData[i].BRAND_NAME)+" "+ "
"+isNullOrUndef(bodyData[i].QTY_ORDER_COUNT)+" "+ "
"+isNullOrUndef(bodyData[i].UNIT_NAME)+" "+ "
"+isNullOrUndef(bodyData[i].TRADE_PRICE)+" "+ "
"+isNullOrUndef(bodyData[i].QTY_ORDER)+" "+ "
"; } dataContet+="
" + "
" + "
" + "
总运输计划数:
"+isNullOrUndef(topData.QTY_TRAN_PLAN_BILL_COUNT)+"" + "
" + "
" + "
总送货单数:
"+isNullOrUndef(topData.QTY_DELIVER_COUNT)+"" + "
" + "
" + "
总卷烟数量(件):
"+isNullOrUndef(topData.QTY_ORDER_SUM_JY)+"" + "
" + "
" + "
总非烟数量:
"+isNullOrUndef(topData.QTY_ORDER_SUM_FY)+"" + "
" + "
" + "
总广宣品数量:
"+isNullOrUndef(topData.QTY_ORDER_SUM_GXP)+"" + "
" + "
" + "
" + "
" + "
出发确认日期:
"+isNullOrUndef(topData.START_DATE)+"" + "
" + "
" + "
出发确认人员:
"+isNullOrUndef(topData.START_PERSON_NAME)+"" + "
" + "
" + "
" + "
" + "
到达确认日期:
"+isNullOrUndef(topData.ARRIVE_DATE)+"" + "
" + "
" + "
到达确认人员:
"+isNullOrUndef(topData.ARRIVE_PERSON_NAME)+"" + "
" + "
" + "
" + "
" + "
运输时长(小时):
"+isNullOrUndef(topData.TRAN_DELIVER_TIME)+"" + "
" + "
" + "
操作人:
"+isNullOrUndef(topData.OPER_PERSON_NAME)+"" + "
" + "
" + "
打印日期:
"+getTime()+"" + "
" + "
" + "
"; return dataContet; } //jqPrnt 打印 function print(elemId){ $('#'+elemId).show(); $('#'+elemId).print({ debug: true, globalStyles: true, mediaPrint: false, stylesheet: null, noPrintSelector: ".no-print", iframe: true, append: null, prepend: null, manuallyCopyFormValues: true, deferred: $.Deferred().done(function(){ $('#'+elemId).hide(); }), timeout: 10000, title: null, doctype: '' }); $('#'+elemId).hide(); } //去空 function isNullOrUndef(str){ if((str == null || str == undefined || str == "") && str!=0){ return ""; } return str; } //获取当前时间 function getTime(){ var date = new Date(); var d = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " +date.getHours()+ ":" + date.getMinutes()+":"+date.getSeconds(); return d; }
基础参数介绍
动态分页
在需要分页的地方加入
去掉页眉页脚
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/204395.html原文链接:https://javaforall.net
