陈战涛
2023-03-14 c29ed2aa867b00eccfdc7c3a68f431008b13ea7d
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
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>出库值仓列表</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="./css/mui.min.css" rel="stylesheet" />
        <link href="./css/mui.picker.min.css" rel="stylesheet" />
        <style>
            .mui-bar-nav {
                background: #245ca7;
                -webkit-box-shadow: none;
                box-shadow: none;
            }
 
            .mui-title {
                color: #FFFFFF;
            }
 
            .mui-icon-back:before,
            .mui-icon-left-nav:before {
                color: #FFFFFF;
            }
            
            .mui-content-padded {
                margin:unset;
                padding: 6px;
            }
            input[type=search] {
                font-size: 16px;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                height: 35px;
                text-align: left;
                border: 0;
                border-radius: 50px;
                background-color: #efeff4;
                margin-bottom: 1px;
                width: 72%;
            }
            .duka{
                background:#ff6355;
                color: #fff;
                border-radius: 5px;
                line-height: 20px;
                margin-right: 8px;
                float: right;
                width: 18%;
            }
            /*出入库记录、值仓列表*/
            .inout_record {
                width: 96%;
                margin: auto;
                margin-bottom: 10px;
                border-top-left-radius: 5px;
                border-top-right-radius: 5px;
            }
            .inout_record_title {
                background: rgb(68, 189, 245);
                height: 10px;
                border-top-left-radius: 5px;
                border-top-right-radius: 5px;
                margin-top: 6px;
            }
            .inout_record_body {
                padding-left: 15px;
                background: #FFFFFF;
            }
            .inout_record_body table {
                width: 100%;
            }
            .inout_record_body tr {
                border-bottom: 1px #efefef solid;
                height: 32px;
                line-height: 32px;
            }
            .inout_record_button {
                background: #668dc1;
                color: #fff;
                border: 0px;
                border-radius: 5px;
                margin: 2px 5px;
                float: right
            }
            .inout_record_button_yc {
                background: #8363ef;
                color: #fff;
                border: 0px;
                border-radius: 5px;
                margin: 2px 5px;
                float: right
            }
            .inout_record_one {
                color: rgb(102, 102, 102);
                font-size: 15px;
                width: 35%;
            }
            .inout_record_two {
                color: black;
                font-size: 16px;
            }
            .heji{
                margin-top: 6px;
                border-radius: 6px;
                background: #9cc5f3;
            }
            .heji1{
                color: #222;
                font-weight: 700;
                font-size: 16px;
            }
        </style>
    </head>
    <body>
        <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">出库值仓列表</h1>
        </header>
        <div class="mui-content">
            <div class="mui-content-padded" style="background: #FFFFFF;">
                <input id="plateNum" type="search" placeholder="请输入车牌信息检索...">
                <button class="btn duka" onclick="readCard()">读卡</button>
            </div>
            <div class="inout_record" id="inoutHandle">
                <!-- <div class="inout_record_title"></div>
                <div class="inout_record_body">
                    <table>
                        <tr class="inout_record_tr">
                            <td class="inout_record_one">目标仓库:</td>
                            <td class="inout_record_two">1号仓</td>
                            <td>
                                <button class="inout_record_button" (click)="goPage(item.id)">现场值仓</button>
                            </td>
                        </tr>
                        <tr>
                            <td class="inout_record_one">车牌号:</td>
                            <td class="inout_record_two">豫A12345</td>
                            <td>
                                <button class="inout_record_button_yc" (click)="goPage(item.id)">远程值仓</button>
                            </td>
                        </tr>
                        <tr>
                            <td class="inout_record_one">粮食品种:</td>
                            <td class="inout_record_two">早籼稻</td>
                            <td></td>
                        </tr>
                        <tr>
                            <td class="inout_record_one">粮食等级:</td>
                            <td class="inout_record_two">1级</td>
                            <td></td>
                        </tr>
                    </table>
                </div> -->
            </div>
        </div>
        <script src="./js/mui.js"></script>
        <script src="./js/mui.picker.min.js"></script>
        <script src="./js/jquery.min.js"></script>
        <script src="./js/echarts.min.js"></script>
        <script type="text/javascript" charset="utf-8">
            mui.init();
            var url; //接口路径
            var handleInList; //出库值仓列表集合
            //获取出库待值仓列表请求参数
            var data1 = {
                "interfaceId": "5206",
                "sign": "10204",
                "outId": "10204",
                "reqDateTime": new Date(),
                "tokenAuth": "",
                "data": {
                    "plateNum": ""
                }
            };
            //查看值仓详情请求参数(NFC读卡时使用)
            var data2 = {
                "interfaceId": "5208",
                "sign": "10208",
                "outId": "10208",
                "reqDateTime": new Date(),
                "tokenAuth": "",
                "data": {
                    "id": "",
                    "intelCard": ""
                }
            };
            
            mui.plusReady(function() {
                var user = JSON.parse(localStorage.getItem('user'));
                data1.tokenAuth = user.tokenAuth;
                data2.tokenAuth = user.tokenAuth;
                url = user.url + "/api-phone/gateway";
                gethandleInList();
            })
 
            //监听输入框
            mui('.mui-content-padded').on('change', 'input[type="search"]', function() {
                //将输入框的值赋值给参数
                data1.data.plateNum = mui("#plateNum")[0].value;
                //发送请求查询
                gethandleInList();
            });
 
            //事件监听子页面的mui.back方法
            window.addEventListener('refresh', function(e) { //执行刷新
                location.reload();
            });
 
            //获取出库值仓信息
            function gethandleInList() {
                mui.ajax(url, {
                    type: "POST",
                    dataType: "json",
                    crossDomain: true,
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data1),
                    success: function(result) {
                        if (result.code == "0000") {
                            handleInList = result.data;
                            if (handleInList != null && handleInList.length > 0) {
                                renderhandleInList();
                            } else {
                                mui.toast("暂无出库值仓信息!");
                            }
                        } else {
                            mui.toast(result.msg);
                        }
                    },
                    error: function() {
                        mui.alert('系统繁忙,请重试!', '提示', ["确定"], function() {}, "div");
                    }
                })
            }
 
            //渲染
            function renderhandleInList() {
                var html = '';
                $.each(handleInList, function(index, item) {
                    html += '<div class="inout_record_title"></div><div class="inout_record_body"><table>';
                    html += '<tr class="inout_record_tr"><td class="inout_record_one">目标仓库:</td>' +
                        '<td class="inout_record_two">' + item.depotName + '</td><td><button class="inout_record_button"' +
                        ' onclick="toHandleView(\'' + item.id + '\',\'photo\')">现场值仓</button></td></tr>';
                    html += '<tr><td class="inout_record_one">车牌号:</td><td class="inout_record_two">' +
                        item.plateNum + '</td><td><button class="inout_record_button_yc"' +
                        ' onclick="toHandleView(\'' + item.id + '\',\'snap\')">远程值仓</button></td></tr>';
                    html += '<tr><td class="inout_record_one">粮食品种:</td><td class="inout_record_two">' +
                        item.foodVarietyName + '</td><td></td></tr>';
                    html += '<tr><td class="inout_record_one">粮食等级:</td><td class="inout_record_two">' +
                        item.foodLevelName + '</td><td></td></tr>';
                    html += '</table></div>';
                })
                $("#inoutHandle").html(html);
            }
 
            //跳转值仓页面
            function toHandleView(inoutId, tag) {
                
                
                if(tag == "snap"){
                    //远程值仓
                    mui.openWindow({
                        url: "inout-handle-out-snap.html",
                        id: "inout-handle-out-snap",
                        extras: {
                            recordId: inoutId
                        }
                    })
                }else{
                    //现场值仓
                    mui.openWindow({
                        url: "inout-handle-out.html",
                        id: "inout-handle-out",
                        extras: {
                            recordId: inoutId
                        }
                    })
                }
            }
 
            /*---------------NFC读卡功能-------------------*/
            var waiting;
            var readyRead = false;
            //读卡方法
            function readCard() {
                readyRead = true;
                listenNFCStatus();
            }
 
            var NfcAdapter;
            var NdefRecord;
            var NdefMessage;
            var count = 0;
 
            //监听NFC状态
            function listenNFCStatus() {
                try {
                    var main = plus.android.runtimeMainActivity();
                    var Intent = plus.android.importClass('android.content.Intent');
                    var Activity = plus.android.importClass('android.app.Activity');
                    var PendingIntent = plus.android.importClass('android.app.PendingIntent');
                    var IntentFilter = plus.android.importClass('android.content.IntentFilter');
                    NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');
                    var nfcAdapter = NfcAdapter.getDefaultAdapter(main);
                    //判断设备是否支持NFC功能
                    if (nfcAdapter == null) {
                        mui.alert("设备不支持NFC功能!", '提示', ["确定"], function() {}, "div");
                        return;
                    }
                    //判断设备是否开启NFC功能
                    if (!nfcAdapter.isEnabled()) {
                        mui.alert("请在系统设置中启用NFC功能!", '提示', ["确定"], function() {}, "div");
                        return;
                    }
                    waiting = plus.nativeUI.showWaiting("请将NFC标签靠近!");
 
                    //倒计时10秒,读取不到后提示是否重新读卡
                    var interval = setInterval(function() { //定义定时器
                        count++;
                        if (count == 10 && readyRead) {
                            readyRead = false;
                            count = 0;
                            waiting.close();
                            clearInterval(interval); //清除定时器
                            var btnArray = ["重试", "取消"];
                            mui.confirm("已超时,是否重新读卡!", "提示", btnArray, function(e) {
                                if (e.index == 0) {
                                    readCard();
                                }
                            }, "div")
                        }
                    }, 1000);
 
                    var intent = new Intent(main, main.getClass());
                    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    var pendingIntent = PendingIntent.getActivity(main, 0, intent, 0);
                    var ndef = new IntentFilter("android.nfc.action.TECH_DISCOVERED");
                    ndef.addDataType("*/*");
                    var intentFiltersArray = [ndef];
                    var techListsArray = [
                        ["android.nfc.tech.IsoDep"],
                        ["android.nfc.tech.NfcA"],
                        ["android.nfc.tech.NfcB"],
                        ["android.nfc.tech.NfcF"],
                        ["android.nfc.tech.Ndef"],
                        ["android.nfc.tech.NfcV"],
                        ["android.nfc.tech.NdefFormatable"],
                        ["android.nfc.tech.MifareClassic"],
                        ["android.nfc.tech.MifareUltralight"]
                    ];
                    document.addEventListener("newintent",
                        function() {
                            setTimeout(readData, 1000);
                        }, false);
                    document.addEventListener("pause", function(e) {
                        if (nfcAdapter) {
                            nfcAdapter.disableForegroundDispatch(main);
                        }
                    }, false);
                    document.addEventListener("resume", function(e) {
                        if (nfcAdapter) {
                            nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
                        }
                    }, false);
                    nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
                } catch (e) {
                    mui.toast("读卡失败,请重试!");
                    waiting.close();
                }
            }
 
            //读取数据
            function readData() {
                NdefRecord = plus.android.importClass("android.nfc.NdefRecord");
                NdefMessage = plus.android.importClass("android.nfc.NdefMessage");
                var main = plus.android.runtimeMainActivity();
                var intent = main.getIntent();
                // if ("android.nfc.action.TAG_DISCOVERED" == intent.getAction()) {  //真机调试
                if ("android.nfc.action.TECH_DISCOVERED" == intent.getAction()) { //打包
                    if (readyRead) {
                        readyRead = false;
 
                        waiting.setTitle('请勿移开标签\n正在读取数据...');
                        var Parcelable = plus.android.importClass("android.os.Parcelable");
                        //读取id
                        var byteId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
                        //将id转为16进制字符串
                        var id = ByteArrayToHexString(byteId);
                        //关闭等待圆圈
                        waiting.close();
 
                        //读取id成功,赋值并发送请求查询
                        data2.data.intelCard = id;
                        getInoutDetail();
                    }
                } else {
                    waiting.close();
                    mui.alert('读取失败,请重试!', '提示', ["确定"], function() {}, "div");
                }
            }
 
            //获取值仓单子详细信息
            function getInoutDetail() {
                mui.ajax(url, {
                    type: "POST",
                    dataType: "json",
                    crossDomain: true,
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data2),
                    success: function(result) {
                        if (result.code == "0000") {
                            //弹窗信息:单子车牌跟仓库,去值仓则进入值仓页面,传递单子id;
                            var btnArray = ["去值仓", "取消"];
                            var text = '值仓仓库:' + result.data.depotName + '<br/>车牌号:' + result.data.plateNum;
                            mui.confirm(text, "检测到待值仓信息如下", btnArray, function(e) {
                                if (e.index == 0) {
                                    //先判断单子是否在值仓状态
                                    if (result.data.progress == "HANDLE") {
                                        //去值仓时判断单子类型是否是入库,不是给出提醒;
                                        if (result.data.type == "OUT") {
                                            mui.openWindow({
                                                url: "inout-handle-out.html",
                                                id: "inout-handle-out",
                                                extras: {
                                                    recordId: result.data.id
                                                }
                                            })
                                        } else {
                                            mui.alert("该卡信息不是出库类型,请核对!", "提示", ["确定"], function() {}, "div")
                                        }
                                    } else {
                                        mui.alert("当前卡不在值仓状态,请核查!", "提示", ["确定"], function() {}, "div")
                                    }
                                }
                            }, "div")
                        } else {
                            mui.toast(result.msg);
                        }
                    },
                    error: function() {
                        mui.alert('系统繁忙,请重试!', '提示', ["确定"], function() {}, "div");
                    }
                })
            }
 
            //将字节数组转为16进制字符串
            function ByteArrayToHexString(inarray) {
                var i, j, inn;
                hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
                out = "";
                for (j = 0; j < inarray.length; ++j) {
                    inn = inarray[j] & 0xff;
                    i = (inn >>> 4) & 0x0f;
                    out += hex[i];
                    i = inn & 0x0f;
                    out += hex[i];
                }
                return out;
            }
        </script>
    </body>
</html>