首先在页面上要有一个“打印按钮”,来触发这个打印操作:
调用choosePrint()方法:
// 打印操作
var timer, win, recCount, rownum;
function choosePrint() {
rownum = 0;
var records = grid.getSelectionModel().getSelections();// 获取多行
recCount = records.length;
var JSONString = "";
record = records[rownum];
showPrint(record);
timer = setInterval(printSave, "500");
}
function printSave() {
if (win.closed) {
if (rownum >= recCount) {
clearInterval(timer);
} else {
var records = grid.getSelectionModel().getSelections();
record = records[rownum];
showPrint(record)
}
}
}
function showPrint(record) {
var Customername = record.get('Customername');
var Curtype1 = record.get('Curtype1');
var Amount1 = record.get('Amount1');
var Curtype2 = record.get('Curtype2');
var Amount2 = record.get('Amount2');
var Businessnum = record.get('Businessnum');
var Acnt1 = record.get('Acnt1');
var Acnt2 = record.get('Acnt2');
var Biztype = record.get('Biztype');
var Pztype = record.get('Pztype');
var Exrate = record.get('Exrate');
var Bizid = record.get('Bizid');
var Pzid = record.get('Pzid');
var Id = record.get('Id');
var Feetype = record.get('Feetype');
var Curtype = record.get('Curtype');
var Amount = record.get('Amount');
JSONString = Customername + "," + Acnt1 + "," + Acnt2 + ","
+ Biztype + "," + Pztype + "," + Businessnum + ","
+ Curtype1 + "," + Amount1 + "," + Curtype2 + "," + Amount2
+ "," + Exrate + "," + Bizid + "," + Pzid + "," + Id + ","
+ Feetype + "," + Curtype + "," + Amount + ";";
win = showJSWindow(
'print.ered?reqCode=vorcharPrint&flag=Print&JSONString='
+ JSONString, 600, 400);
rownum++;
}
/** 弹出窗口 */
function showJSWindow(url, width, height) {
var pWidth = width ? width : document.body.clientWidth * 0.7;
var pHeight = height ? height : 470;
var str = 'width=' + pWidth
+ ',height=' + pHeight
+ ',toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no';
return window.open(url, '', str);
}
其中这段代码的意思为:
win = showJSWindow(
'print.ered?reqCode=vorcharPrint&flag=Print&JSONString='
+ JSONString, 600, 400);打开一个jsp页面vocharPrint.jsp
结算打印body {
margin: 0px;
}
.printStyle td {
BACKGROUND-COLOR: #FFFFFF;
COLOR: black;
FONT-FAMILY: 'Times New Roman';
FONT-SIZE: 12pt;
}
.Noprint {
DISPLAY: none;
}
border="0">
List printList2 = (List) request.getAttribute("printList2");
for (Iterator iterator = printList2.iterator(); iterator.hasNext();) {
HashMap printMap2 = (HashMap) iterator.next();
%>
日期:
.get("Printtype") : ""%>
LC编号:外汇金额: 合同号:.get("Contrno") : ""%>
if (printMap2.get("Feetype") != null
|| printMap2.get("Feetype") != "") {
if (printMap2.get("Feetype") == "F001") {
%>
手续费:}
if (printMap2.get("Feetype") == "F002") {
%>
电报费:}
} else {
%>
汇率:}
%>
备注:}
%>
记账: | 复核: |
window.onload = function() {
window.print();
window.close();
}