add.html
15.4 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head>
<th:block th:include="include :: header" />
<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-receiptHeader-add">
<!-- <div class="form-group">-->
<!-- <label class="col-sm-3 control-label">入库类型:</label>-->
<!-- <div class="col-sm-8">-->
<!-- <select id="receiptType" name="receiptType" class="form-control">-->
<!-- <option th:text="CLXXRK" th:value="CLXXRK"></option>-->
<!-- </select>-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="col-sm-3 control-label">入库类型:</label>
<div class="col-sm-8">
<input id="receiptType" name="receiptType" class="form-control" type="text" th:value="CLXXRK" readonly>
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="col-sm-3 control-label">原料批号:</label>-->
<!-- <div class="col-sm-8">-->
<!-- <input id="materialBatch" name="materialBatch" class="form-control" type="text">-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="col-sm-3 control-label">供应商:</label>
<div class="col-sm-8">
<select id="supplier" name="supplier" class="form-control" type="text"></select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">司机姓名:</label>
<div class="col-sm-8">
<input id="vehicleName" name="vehicleName" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">身份证号:</label>
<div class="col-sm-8">
<input id="cardNumber" name="cardNumber" class="form-control" type="text">
</div>
</div>
<div class="form-group" style="margin-left: 190px">
<button type="button" class="btn btn-primary" onclick="getWeight()" >获取重量</button>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">车辆毛重:</label>
<div class="col-sm-8">
<input id="grossWeight" name="grossWeight" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">车辆皮重:</label>
<div class="col-sm-8">
<input id="tareWeight" name="tareWeight" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">车辆净重:</label>
<div class="col-sm-8">
<input id="netWeight" name="netWeight" class="form-control" type="text">
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="col-sm-3 control-label">物料编码:</label>-->
<!-- <div class="col-sm-8">-->
<!-- <select id="materialCode" name="materialCode" class="form-control" type="text"></select>-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="col-sm-3 control-label">物料:</label>
<div class="col-sm-8">
<select id="userDef2" name="userDef2" class="form-control" th:with="probablyMaterial=${@dict.getType('probablyMaterial')}">
<option th:each="dict : ${probablyMaterial}" th:text="${dict['dictLabel']}" th:value="${dict['dictValue']}"></option>
</select>
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="col-sm-3 control-label">物料单位:</label>-->
<!-- <div class="col-sm-8">-->
<!-- <select id="materialUnit" name="materialUnit" class="form-control" type="text"></select>-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="col-sm-3 control-label">车牌号:</label>
<div class="col-sm-8">
<input id="carNumber" name="carNumber" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">驾驶证:</label>
<div class="col-sm-8">
<input id="driverNumber" name="driverNumber" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">同行人数:</label>
<div class="col-sm-8">
<input id="userDef1" name="userDef1" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">入库单备注:</label>
<div class="col-sm-8">
<input id="remark" name="remark" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">预计到达时间:</label>
<div class="col-sm-8">
<input id="incomingTime" name="incomingTime" class="form-control" type="text">
</div>
</div>
<div class="form-group" style="margin-left: 350px">
<video id="video" hidden="hidden"></video>
<canvas id="canvas"></canvas>
<button id="plc" name="plc" class="btn btn-danger" type="button">拍摄图片</button>
</div>
<div class="form-group" style="margin-left: 350px">
<button onclick="ReadIDCard()" class="btn btn-danger" type="button">识别身份证</button>
</div>
<div style="border: 2px solid red;margin-top: 30px;" hidden="hidden">
<img id="res_img" src="" width="400px" height="300px" alt="">
</div>
<div class="form-group">
<div class="form-control-static col-sm-offset-9">
<button type="submit" class="btn btn-primary" >提交</button>
<button onclick="$.modal.close()" class="btn btn-danger" type="button" >关闭</button>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
const width = 480;
const height = 320;
const video = document.getElementById('video');
//访问摄像头
if (navigator.mediaDevices.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia) {
//调用用户媒体设备, 访问摄像头
getUserMedia({video: {width: width, height: height}}, success, error);
} else {
alert('不支持访问用户媒体');
}
//访问用户媒体设备的兼容方法
function getUserMedia(constraints, success, error) {
if (navigator.mediaDevices.getUserMedia) {
//最新的标准API
navigator.mediaDevices.getUserMedia(constraints).then(success).catch(error);
} else if (navigator.webkitGetUserMedia) {
//webkit核心浏览器
navigator.webkitGetUserMedia(constraints, success, error)
} else if (navigator.mozGetUserMedia) {
//firfox浏览器
navigator.mozGetUserMedia(constraints, success, error);
} else if (navigator.getUserMedia) {
//旧版API
navigator.getUserMedia(constraints, success, error);
}
}
//成功回调
function success(stream) {
console.log('成功');
//兼容webkit核心浏览器
// const CompatibleURL = window.URL || window.webkitURL;
//将视频流设置为video元素的源
// video.src = CompatibleURL.createObjectURL(stream);
video.srcObject = stream;
video.play();
setInterval(drawCanvasImage, 10)
}
//失败回调
function error(error) {
console.log('失败');
console.log("访问用户媒体设备失败", error);
}
document.getElementById("plc")
.addEventListener("click", function() {
const canvas = document.getElementById('canvas');
canvas.width = width;
canvas.height = height;
const context = canvas.getContext('2d');
context.drawImage(video, 0, 0, width, height, 0, 0, width, height);
//获取图片,数据格式为base64
let imgStr = canvas.toDataURL("image/png");
imgStr = imgStr.replaceAll("%2F", "/");
imgStr = imgStr.replaceAll("%3D", "=");
imgStr = imgStr.replaceAll("%3A", ":");
imgStr = imgStr.replaceAll("%3B", ";");
imgStr = imgStr.replaceAll("%2C", ",");
imgStr = imgStr.replaceAll("data:image/png;base64,","");
console.log(imgStr)
$.ajax({
cache : false,
type : "POST",
url : prefix + "/camera",
dataType: 'json',
data : {"imageData":imgStr},
async : false,
error : function(request) {
$.modal.alertError("请求失败!");
},
success : function(result) {
if (result.code == web_status.SUCCESS) {
$.modal.msgSuccess(result.msg);
}
}
});
});
function drawCanvasImage() {
const canvas = document.getElementById('canvas');
canvas.width = width;
canvas.height = height;
const context = canvas.getContext('2d');
context.drawImage(video, 0, 0, width, height, 0, 0, width, height);
// //获取图片,数据格式为base64
// const imageData = canvas.toDataURL("image/png");
}
var prefix = ctx + "vehicle/vehicleReceipt";
$("#form-receiptHeader-add").validate({
rules:{
receiptType:{
required:true,
},
companyCode:{
required:true,
},
},
submitHandler: function(form) {
$.ajax({
cache : true,
type : "POST",
url : prefix + "/add",
data : $("#form-receiptHeader-add").serializeArray(),
// data : {
// "receiptType": $("#receiptType option:selected").val(),
// "supplier": $("#supplier option:selected").val(),
// "vehicleName": $("input[name='vehicleName']").val(),
// "cardNumber": $("input[name='cardNumber']").val(),
// "grossWeight": $("input[name='grossWeight']").val(),
// "tareWeight": $("input[name='tareWeight']").val(),
// "carNumber": $("input[name='carNumber']").val(),
// "driverNumber": $("input[name='driverNumber']").val(),
// "remark": $("input[name='remark']").val(),
// "userDef1": $("input[name='userDef1']").val(),
// "materialCode": $("#materialCode option:selected").val(),
// "materialUnit": $("#materialUnit option:selected").val(),
// "materialSpec": $("input[name='materialSpec']").val(),
// "incomingTime": $("input[name='incomingTime']").val(),
// "probablyMaterial": $("#probablyMaterial option:selected").val(),
// "netWeight": $("input[name='netWeight']").val()
// },
async : false,
error : function(request) {
$.modal.alertError("请求失败!");
},
success : function(data) {
$.operate.saveSuccess(data);
}
});
}
});
$(function () {
layui.use('laydate', function() {
var laydate = layui.laydate;
laydate.render({ elem: '#incomingTime',min: 0, theme: 'molv', format: 'yyyy-MM-dd HH:mm:ss'});
});
$('#supplier').select2({
ajax: {
url: ctx+'config/supplier/getData',
dataType: 'json',
type: 'post',
data: function (params) {
let query = {
supplierName: params.term,
}
return query;
}
}
});
$('#materialCode').select2({
ajax: {
url: ctx+'config/material/getData',
dataType: 'json',
type: 'post',
data: function (params) {
let query = {
materialName: params.term,
}
return query;
}
}
});
$('#materialUnit').select2({
ajax: {
url: ctx+'config/materialUnit/getData',
dataType: 'json',
type: 'post',
data: function (params) {
let query = {
unit: params.term,
}
return query;
}
}
});
})
function getWeight(){
let url='http://10.34.101.77:8888/wms/API/WMS/v2/getWeightForSerial';
let type = "POST";
let dataType = "json";
let data = {};
let config = {
url: url,
type: type,
dataType: dataType,
data: data,
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
},
success: function (result) {
console.log(result.data)
$("#grossWeight").val(result.data)
$.operate.ajaxSuccess(result);
}
};
$.ajax(config)
}
function cameraPlc(){
$.ajax({
cache : false,
type : "POST",
url : prefix + "/camera",
data : {},
async : false,
error : function(request) {
$.modal.alertError("请求失败!");
},
success : function(result) {
if (result.code == web_status.SUCCESS) {
}
}
});
}
function ReadIDCard()
{
IdBase64 = "";
var params = "";
var url = "http://127.0.0.1:38088/card=idcard";
$.ajax({
type: "post",
url: url,
dataType: "json",
data: params,
success: function(data)
{
if(data.code != 0)
{
alert("请将证件放对位置!!!")
}
else
{
$("#cardNumber").val(data.IDCardInfo.cardID)
$("#vehicleName").val(data.IDCardInfo.name)
// document.getElementById("cardNumber").innerHTML = data.IDCardInfo.cardID
// $("input[name='cardNumber']").val() = data.IDCardInfo.cardID
// document.getElementById("result").innerHTML = "ReadIDCard <br />返回代码:" + data.code +
// "<br />返回信息:" + data.message +
// "<br />姓名:" + data.IDCardInfo.name +
// "<br />性别:" + data.IDCardInfo.sex +
// "<br />民族:" + data.IDCardInfo.nationCode +
// "<br />生日:" + data.IDCardInfo.birthday +
// "<br />地址:" + data.IDCardInfo.address +
// "<br />身份证号:" + data.IDCardInfo.cardID +
// "<br />发卡机构:" + data.IDCardInfo.issueOrgan +
// "<br />有效时间:" + data.IDCardInfo.validStart + "-" + data.IDCardInfo.validEnd;
// document.getElementById("photo").src= "data:image/gif;base64," + data.IDCardInfo.photoBase64;
// IdBase64 = data.IDCardInfo.photoBase64;
}
}
});
scan1cutpage();
}
// 主头纠偏拍照
function scan1cutpage(){
debugger;
var data = {
"filepath": "base64",
"rotate": "0",
"cutpage": "1",
"camidx": "0"
};
$.post("http://127.0.0.1:38088/video=grabimage", JSON.stringify(data),
function(res){
$('#res_img').attr('src', "data:image/jpg;base64," + res.photoBase64);
// 调用方式
// 参数一: 选择器,代表img标签
// 参数二: 图片名称,可选
downloadIamge('#res_img', res.photoBase64)
}
)
}
function downloadIamge(selector, name) {
var image = new Image()
// 解决跨域 Canvas 污染问题
image.setAttribute('crossOrigin', 'anonymous')
image.onload = function () {
var canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
var context = canvas.getContext('2d')
context.drawImage(image, 0, 0, image.width, image.height)
var url = canvas.toDataURL('image/png')
// 生成一个a元素
var a = document.createElement('a')
// 创建一个单击事件
var event = new MouseEvent('click')
// 将a的download属性设置为我们想要下载的图片名称,若name不存在则使用‘下载图片名称’作为默认名称
a.download = name || '下载图片名称'
// 将生成的URL设置为a.href属性
a.href = url
// 触发a的单击事件
a.dispatchEvent(event)
}
image.src = document.querySelector(selector).src
}
</script>
</body>
</html>