reportmes2.html
8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<title>MES打印</title>
<script charset="utf-8" type="text/javascript" th:src="@{/js/barcode/JsBarcode.all.js} "></script>
<script charset="utf-8" type="text/javascript" th:src="@{/js/jquery-1.4.4.min.js}"></script>
<script charset="utf-8" type="text/javascript" th:src="@{/js/jquery.jqprint-0.3.js}"></script>
<style>
@media print {
.printbar{ display:none;}
.action{ display: none;}
/* svg:nth-child(even)
{
page-break-inside :always;
border:1px solid red;
}
*/
svg:nth-child(even)
{
/**分页chrome不起作用**/
page-break-inside :always;
/* border:1px solid red; */
}
}
@page{
margin:1cm;
}
body {
margin: 0px;
padding:0px;
margin-left:7mm; /**打印版面的左侧偏移量 7mm左右和打印机匹配**/
}
.preview {
position: relative;
width: 84.6mm;
display: grid;
height: 20mm;
grid-template-columns: 1fr 1fr;
border:0px solid blue;
box-sizing:border-box; /**把padding也算上宽度**/
grid-gap: 0px 0px; /*网格中间间距**/
margin:0 auto;
/* background-color: gray; */
}
.preview > div {
border: 1px solid gray; /**打印边框后,斑马打印机才会让svg容垂直居中打印,否则会忽略空白区域,让svg顶格打印**/
width:40mm;
height:20.64mm; /**高度要稍微>20mm一点,打印分页时才不会错位**/
display: flex;
vertical-align: middle;
box-sizing:border-box; /**把padding也算上宽度**/
}
.preview > div> svg {
/* border:1px solid red; */
width:38mm;
position: relative;
padding-left:1mm;
padding-right:1mm;
align-self:center;
box-sizing:border-box; /**把padding也算上宽度**/
}
/**奇数**/
svg:nth-child(odd)
{
margin-left:1.3mm;
margin-right:1mm;
/* margin-top:1mm;
margin-bottom: 1mm; */
}
/**偶数**/
svg:nth-child(even)
{
margin-left:1mm;
margin-right:1.3mm;
/* margin-top:1mm;
margin-bottom: 1mm; */
}
span{
line-height: 10mm;
color:black;
}
.printbar{
text-align: right;
background-color: #fafafa;
margin-right:80px;
padding-right:10px;
border-bottom: 1px solid #ccc;
padding-bottom: 15px;
}
.printbar > div{
font-size: 14px;
height: 28px;
/* margin-right: 60px; */
}
.svgItem{
display: none;
}
input[name='numItem']{
width:40px;
font-size: 14px;
}
.action{
position: fixed;
right: 0px;
width: 70px;
padding-right:10px;
height:100%;
padding-top:10px;
top:0px;
border-left: 1px solid #ccc;
background-color: #fafafa;
}
.action > div{
text-align: center;
width:60px;
color:blue;
font-size: 10px;
}
.action > input{
width:60px;
height:30px;
margin-left:10px;
margin-bottom: 5px;
}
.spannum{
width:80px;
display: inline-block;
text-align: left;
/* background-color: #ccc; */
}
</style>
</head>
<body>
<div class="printbar">
<div th:each="row:${receiptDetailMaterialCodes}">
<svg class="svgItem" name="svgItem" th:attr="id=${row.materialCode}"></svg>
<span th:text="'' + ${row.materialName}"></span>
<span th:text="''+${row.materialCode}"></span>
<span class="spannum" th:text="'数量:'+${#numbers.formatDecimal(row.qty,1,0)}"></span>
打印 <input name="numItem" type="text" th:attr="value=${#numbers.formatDecimal(1,1,0)}"> 个
</div>
</div>
<div class="action">
<input type="button" value="预 览" onclick="preview()" id="pv"/><br/>
<input type="button" value="打 印" onclick="preview();window.print()"/><br/><br/>
<br/>
<input type="button" value="+边距" onclick="addMargin(1)"/><br/>
<div id="marginInfo">7mm</div>
<input type="button" value="-边距" onclick="addMargin(-1)"/><br/><br/>
<input type="button" value="重 置" onclick="window.location.reload(true)"/><br/>
<input type="button" value="清 零" onclick="clearNum()"/><br/><br/>
<div id="infoSum"></div>
</div>
<div class="preview" id="preview"></div>
<script type="text/javascript">
var barcodeStyle = {
format: "CODE128",//选择要使用的条形码类型
width:1,//设置条之间的宽度
height:40,//高度
displayValue:true,//是否在条形码下方显示文字
// text:"456",//覆盖显示的文本
// fontOptions:"bold italic",//使文字加粗体或变斜体
font:"monospace",//设置文本的字体fantasy
textAlign:"center",//设置文本的水平对齐方式
textPosition:"bottom",//设置文本的垂直位置
textMargin:0,//设置条形码和文本之间的间距
fontSize:16,//设置文本的大小
background:"#ffffff",//设置条形码的背景
lineColor:"#000000",//设置条和文本的颜色。
margin:1//设置条形码周围的空白边距
};
$(document).ready(function() {
$("svg[name='svgItem']").each(function () {
JsBarcode(this, this.id, barcodeStyle);
})
});
function clearNum(){
var inputList = $("input[name='numItem']")
$("svg[name='svgItem']").each(function (i, m, n) {
if(inputList[i] != undefined){
inputList[i].value = 0
}
})
preview()
}
function preview() {
$("#preview").empty()
var inputList = $("input[name='numItem']")
var sum = 0;
$("svg[name='svgItem']").each(function (i, m, n) {
var num = inputList[i].value
sum = sum + parseInt(num)
for(var i=0; i<num; i++) {
var bar = $(m).clone(true)
var preview = document.getElementById("preview")
var div = document.createElement("div")
$("#preview").append('<div></div>');
$("#preview").children("div:last-child").append(bar);
// alert(1)
bar.removeAttr("class")
}
})
$("#infoSum").html("条码数<br/>" + sum)
}
$("#pv").click()
var margin_src = 0
function addMargin(offset) {
offset = parseInt(offset)
margin_src = margin_src + offset
document.getElementsByTagName("body")[0].style.cssText = "margin-left: " +margin_src+ "mm"
setCookie('margin', margin_src)
$("#marginInfo").html(margin_src + "mm")
}
$(document).ready(function() {
addMargin(getCookie("margin"))
});
function setCookie(name,value)
{
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return 0;
}
</script>
</body></html>