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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/**
 * 作者:G98138 黎锋
 * 时间:2018-09-04
 * 描述:库位 绑定
 * 
 * 业务思路:
 * 1. 扫描条码
 *  1.1 非条码库存表的条码, 提示( OK) *
 *    1.2 非待入库条码, 提示( OK) *
 *    1.3 通过条码找到上一次该物料的库位, 作为推荐库位( OK)
 *    注意: 如果勾选了“默认库位”, 且在上一次绑定的库位和当前界面显示的库位一致 , 则直接绑定库位, 不需要再扫描库位 *
 
 * 2. 扫描库位条码 *
 *    2.1 非库位条码, 提示( OK) *
 *    2.2 非该仓库的库位, 提示( OK) *
 */
 
// 全局变量
var billNo = '';
var i = 0; //计算扫描条码数量
var WLBM = ""; //物料编码
var matterTable = null;
 
var pickerData = [{
        'value': 'v2',
        'text': '测试2'
    },
    {
        'value': 'v3',
        'text': '测试3'
    },
    {
        'value': 'v5',
        'text': '测试5'
    },
    {
        'value': 'v6',
        'text': '测试6'
    },
    {
        'value': 'v7',
        'text': '测试7'
    },
];
 
//初始化,默认焦点
mui.plusReady(function() {
    mui.init();
    app.init();
    GetGYS();
    GetDHNO();
    initBluetooth();
    //    app.init();
    mui("#MBA001")[0].focus();
 
    $('#info').height($(window).height() - $("#row001").height() - $("#div001").height() - $("#div002")
        .height() - 70);
 
 
 
    // document.getElementById('check').addEventListener('tap', function() {
    //     console.log(12);
    //     var url = 'getScanCode1.html';
    //     mui.openWindow({
 
    //         url: url,
    //         extras: {},
    //         waiting: {
    //             autoShow: true,
    //             title: '加载中'
    //         }
    //     });
    //     // createWithoutTitle('getScanCode.html', {
    //     //                    titleNView: {
    //     //                        type: 'float',
    //     //                        backgroundColor: '#009DE2',
    //     //                        titleText: '扫一扫',
    //     //                        titleColor: '#FFFFFF',
    //     //                        autoBackButton: true
    //     //                    }
    //     //                });
    // }, false)
 
})
 
function scaned(t, r, f) {
    console.log(r);
    $("#searchInput").val(r);
    // setSeanCode({keyCode:123},file71, str1, findId, file91, file101);
}
// function Sopennew() {
 
//         console.log(12);
//  createWithoutTitle('getScanCode.html', {
//                     titleNView: {
//                         type: 'float',
//                         backgroundColor: '#009DE2',
//                         titleText: '扫一扫',
//                         titleColor: '#FFFFFF',
//                         autoBackButton: true
//                     }
//                 });
//                 }
function SetBillNo() {
    $("#txtBillNo").click(function() {
        GetBillList();
        PopPicker.show(function(items) {
            var billNo = items[0].text;
            $("#txtBillNo").val(billNo);
        });
    });
}
 
document.getElementById('stype').addEventListener('change', function() {
    console.log(1);
    var selectedValue = this.value;
    var elementToHideId = '';
    var elementToHideId2 = '';
    if (selectedValue === '1') {
        document.getElementById('row002').style.display = 'none';
        // document.getElementById('row004').style.display = '';
        document.getElementById('row0022').style.display = '';
        document.getElementById('row003').style.display = '';
        document.getElementById('row0033').style.display = 'none';
 
    } else if (selectedValue === '2') {
        document.getElementById('row002').style.display = '';
        document.getElementById('row0022').style.display = 'none';
        // document.getElementById('row004').style.display = 'none';
        document.getElementById('row003').style.display = 'none';
        document.getElementById('row0033').style.display = '';
    }
    ///切换清除所有元素
    document.getElementById("searchInput").value = "";
    document.getElementById("DAB001B").value = "";
    document.getElementById("MBA002").value = "";
    document.getElementById("DAB002").value = "";
    document.getElementById("DAB003").value = "";
    document.getElementById("DAB004").value = "";
    document.getElementById('ulId').innerHTML = ""
});
 
 
///查询所有携客云未做的送货单
function GetDHNO() {
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_GETDHNO",
 
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            if (data.status == 0) {
                //console.log(response);
                /// console.log(JSON.stringify(response));
                var selectElementD = document.getElementById('MBA001');
                selectElementD.innerHTML = "";
                matterTable = data.data.matterTable;
 
                var option = document.createElement("option");
                option.value = "";
                option.text = "请选择送货单号";
                selectElementD.appendChild(option);
 
                for (var i = 0; i < matterTable.length; i++) {
                    var option = document.createElement("option");
                    option.value = matterTable[i]["送货单号"];
                    option.text = matterTable[i]["送货单号"];
                    selectElementD.appendChild(option);
                }
 
            } else {
 
                alert("获取数据异常:" + response.message);
            }
 
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
 
}
 
 
 
//查询供应商
 
function GetGYS() {
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_GETGYS",
 
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            if (data.status == 0) {
                //console.log(response);
                /// console.log(JSON.stringify(response));
                var selectElementD = document.getElementById('DAB001');
                selectElementD.innerHTML = "";
                matterTable = data.data.matterTable;
 
                var option = document.createElement("option");
                option.value = "";
                option.text = "请选择供应商";
                selectElementD.appendChild(option);
 
                for (var i = 0; i < matterTable.length; i++) {
                    var option = document.createElement("option");
                    option.value = matterTable[i]["供应商名称"];
                    option.text = matterTable[i]["供应商名称"];
                    selectElementD.appendChild(option);
                }
 
            } else {
 
                alert("获取数据异常:" + response.message);
            }
 
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
}
//修改数量
function AlterNUM(itemid) {
    console.log(2);
    var userInput = prompt("请输入收货数量:", "");
    if (userInput != null) {
        $.ajax({
            url: app.API_URL_HEADER + "/XKYDHD/CG_UPDATENUM",
            data: {
                ID: itemid,
                userInput: userInput
            },
            DataType: "json",
            type: "post",
            async: false,
            //timeout: 15000,
            success: function(data) {
                if (data.status == 0) {
                    if (document.getElementById("stype").value === '1') {
                        GetInfoGYS()
                    }
                    if (document.getElementById("stype").value === '2') {
                        GetInfoXKYDHNO()
                    }
                    mui.toast("修改成功")
                } else {
 
                    alert("获取数据异常:" + data.message);
                }
 
            },
            error: function(xhr, type, errorThrown) {
                alert("获取数据异常:" + JSON.stringify(errorThrown));
            }
        });
    } else {
 
    }
    console.log(itemid);
 
 
 
}
 
//选供应商带出送货单
function GetInfoGYS() {
    console.log($("#DAB001").val());
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_GetInfoGYS",
        data: {
            DAB001: $("#DAB001").val(),
            STYPE: '1'
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            if (data.status == 0) {
                var lstb = data.data.matterTable;
                var cursor2 = data.data.matterTable2;
                $("#MBA002").val(lstb[0]["DHA001"]);
                $("#DAB002").val(lstb[0]["DHA005"]);
                $("#DAB003A").val(lstb[0]["DHA006B"]);
                $("#DAB003").val(lstb[0]["DHA006"]);
                $("#DAB004").val(lstb[0]["DHA030"]);
                matterTable = data.data.matterTable3;
                console.log(data.data.matterTable3);
                pickerData.length = 0;
                for (let item of matterTable) {
                    console.log('value:', item.物料编码, 'text:', item.物料编码 + " " + item.采购订单 + " " + item
                        .剩余数量);
                    pickerData.push({
                        value: item.ID,
                        text: item.物料编码 + " | " + item.采购订单 + " | " + item.剩余数量
                    });
                }
                console.log(pickerData);
 
 
                document.getElementById('ulId').innerHTML = template('ui-template', {
                    "record": cursor2
                });
            } else {
 
                alert("获取数据异常:" + data.message);
            }
 
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
}
 
//携客云带出信息
function GetInfoXKYDHNO() {
    console.log($("#MBA002").val());
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_GetInfoXKYDH",
        data: {
            DAB001: $("#MBA002").val(),
            STYPE: '1'
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            if (data.status == 0) {
                var lstb = data.data.matterTable;
                var cursor2 = data.data.matterTable2;
                $("#MBA002").val(lstb[0]["DHA001"]);
                $("#DAB002").val(lstb[0]["DHA005"]);
                $("#DAB003A").val(lstb[0]["DHA006B"]);
                $("#DAB003").val(lstb[0]["DHA006"]);
                $("#DAB004").val(lstb[0]["DHA030"]);
                //    matterTable = data.data.matterTable3;
                //    console.log(data.data.matterTable3);
                // pickerData.length = 0;
                // for (let item of matterTable) {
                //     console.log('value:', item.物料编码, 'text:', item.物料编码 + " " + item.采购订单 + " " + item
                //         .剩余数量);
                //     pickerData.push({
                //         value: item.ID,
                //         text: item.物料编码 + " | " + item.采购订单 + " | " + item.剩余数量
                //     });
                // }
                // console.log(pickerData);
 
 
                document.getElementById('ulId').innerHTML = template('ui-template', {
                    "record": cursor2
                });
            } else {
 
                alert("获取数据异常:" + data.message);
            }
 
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
}
 
var valstring;
 
function ADDCGLINE() {
    console.log(17);
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_ADDLINE",
        data: {
            DAB001: $("#MBA002").val(),
            VARSTRING: valstring
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            if (data.status == 0) {
                GetInfoXKYDHNO()
 
            } else {
 
                alert("获取数据异常:" + response.message);
            }
 
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
 
}
 
///新增明细按钮 调用重写的picker
document.getElementById('add').addEventListener('tap', function() {
    if ($("#DAB003A").val() == "未保存") {
 
        mui.alert("请先保存单据", "", "", function() {
 
        });
        return;
    }
    if ($("#DAB003A").val() == "已审核") {
 
        mui.alert("已审核单据无法修改", "", "", function() {
 
        });
        return;
    }
    if ($("#MBA002").val() == "") {
 
        mui.alert("到货单号不能为空", "", "", function() {
 
        });
        return;
    }
 
    var picker = new mui.PopPicker();
 
    picker.setData(pickerData)
 
    picker.show(function() {
 
        var vals = []
        // 获取复选框选中的值
        mui.each(document.querySelectorAll('input[name=pickerCheckbox]'), function(i, ele) {
            if (ele.checked) {
                vals[i] = ele.value
            }
        })
        if (!vals || vals.length <= 0) {
            mui.toast('请选择')
 
            return false; // return false  可阻止弹出层关闭
 
        }
        valstring = vals.join(",");
        ADDCGLINE();
 
        picker.dispose(); // 关闭并销毁picker实例
 
        GetInfoGYS()
 
 
        // valstring=vals.join(",");
        //     ADDCGLINE();
    })
}, false)
document.getElementById('check').addEventListener('tap', function() {
 
    if ($("#DAB003A").val() == "未保存") {
 
        mui.alert("请先保存再审核", "", "", function() {
 
        });
        return;
    }
    if ($("#DAB003A").val() == "已审核") {
 
        mui.alert("无法重复审核", "", "", function() {
 
        });
        return;
    }
    if ($("#MBA002").val() == "") {
 
        mui.alert("到货单号不能为空", "", "", function() {
 
        });
        return;
    }
    console.log(3333);
    var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
    var user_id = currentSession.user_id;
    console.log($("#MBA001").val());
    //        var user_id = "admin";
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_DHSH",
 
        data: {
            DAB001: $("#MBA002").val(),
            logID: user_id //user_id,//Admin //先写死,便于调试    
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            console.log(data);
            if (data.status != 0) {
                playerAudio("NG");
 
                console.log(data.message);
                mui.alert(data.message, "", "", function() {
 
                });
                return;
            } else {
 
 
                document.getElementById("DAB003A").value = "已审核";
 
                mui.toast("审核成功")
 
            }
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
}, false)
 
document.getElementById('save').addEventListener('tap', function() {
    if ($("#MBA002").val() == "") {
 
        mui.alert("到货单号不能为空", "", "", function() {
 
        });
        return;
    }
    if ($("#DAB003A").val() == "已审核") {
 
        mui.alert("已审核无法修改", "", "", function() {
 
        });
        return;
    }
 
    console.log(3333);
    var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
    var user_id = currentSession.user_id;
    console.log($("#MBA001").val());
    //        var user_id = "admin";
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_SAVEDH",
 
        data: {
            MBA002: $("#MBA002").val(),
            DAB001: $("#DAB001").val(),
            DAB004: $("#DAB004").val(),
            logID: user_id //user_id,//Admin //先写死,便于调试    
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            console.log(data);
            if (data.status != 0) {
                playerAudio("NG");
 
                console.log(data.message);
                mui.alert(data.message, "", "", function() {
 
                });
                return;
            } else {
 
                GetInfoXKYDHNO()
                mui.toast("保存成功")
 
            }
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
}, false)
 
 
document.getElementById('printbtnn').addEventListener('tap', function() {
 
    if ($("#DAB003A").val() != "已审核") {
 
        mui.alert("未审核无法打印", "", "", function() {
 
        });
        return;
    }
    if ($("#MBA002").val() == "") {
 
        mui.alert("到货单号不能为空", "", "", function() {
 
        });
        return;
    }
 
 
    console.log(33313);
    var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
    var user_id = currentSession.user_id;
 
    //        var user_id = "admin";
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_PRINTBAR",
 
        data: {
            MBA002: $("#MBA002").val(),
            logID: user_id //user_id,//Admin //先写死,便于调试    
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            console.log(data);
            if (data.status != '0') {
                playerAudio("NG");
 
                console.log(data.message);
                mui.alert(data.message, "", "", function() {
 
                });
                return;
            } else {
                console.log(11);
                var lstb = data.data.matterTable;
                console.log(data.data.matterTable);
                var str = lstb[0]["ID"].toString();
                mui.toast("开始打印");
                console.log(12);
                printByIds(str);
                console.log(13);
            }
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
}, false)
 
 
let startX = 0;
let endX = 0;
 
function touchStart(event, itemid) {
    startX = event.touches[0].clientX;
 
}
 
function touchMove(event, itemid) {
    endX = event.touches[0].clientX;
    if (endX - startX < -50) { // 设置滑动距离阈值,这里设置为80像素
        // alert('左滑事件触发');
        if (confirm("您确定要删除该条明细吗?")) {
            // 用户点击了“确定”按钮,执行相应操作
            DELETELINE(itemid)
        } else {
            // 用户点击了“取消”按钮,不执行操作
 
        }
        console.log(itemid);
    }
    if (endX - startX > 50) { // 设置滑动距离阈值,这里设置为80像素
        // alert('右滑事件触发');
        if (confirm("您确定要删除该条明细吗?")) {
            // 用户点击了“确定”按钮,执行相应操作
            DELETELINE(itemid)
        } else {
            // 用户点击了“取消”按钮,不执行操作
 
        }
        console.log(itemid);
    }
 
}
 
 
function DELETELINE(itemid) {
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/CG_DELETELINE",
        data: {
 
            ID: itemid
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            if (data.status == 0) {
                mui.toast("删除成功!");
                GetInfoXKYDHNO()
            } else {
 
                alert("删除失败!");
            }
 
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
}
 
 
window.addEventListener('refresh', function(e) { //监听页面返回事件    
    GetInfoXKYDHNO()
});
 
 
 
function GetInfoXKYDH() {
 
    //用户ID
    var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
 
    var user_id = currentSession.user_id;
    console.log($("#MBA001").val());
    //        var user_id = "admin";
    $.ajax({
        url: app.API_URL_HEADER + "/XKYDHD/GetBarInfo",
 
        data: {
            DAB001: $("#MBA001").val(),
            logID: user_id //user_id,//Admin //先写死,便于调试    
        },
        DataType: "json",
        type: "post",
        async: false,
        //timeout: 15000,
        success: function(data) {
            console.log(data);
            if (data.status != 0) {
                console.log(data);
                playerAudio("NG");
 
                mui.alert(data.message, "", "", function() {
                    mui("#DAB001")[0].focus();
                    $("#DAB001").val("");
                });
                return;
            } else {
                console.log(data);
                matterTable = data.data.matterTable;
                $("#DAB001B").val(matterTable[0]["DHA003"]);
                $("#MBA002").val(matterTable[0]["DHA001"]);
                // $("#MBA002").val(matterTable[0]["DHA001"]);
                GetInfoXKYDHNO()
 
            }
        },
        error: function(xhr, type, errorThrown) {
            alert("获取数据异常:" + JSON.stringify(errorThrown));
        }
    });
 
};
 
 
 
 
 
 
 
 
//扫描库位处理方法
 
/* 当页面的文本失去焦点时,让其再次获取焦点 */
 
 
/**
 *  @param {出发DOM控件:this} e
 */
//function SetInputFoucs(codeID) {
//    var itemTag = document.activeElement.tagName; //获取元素的标签名
//    var name = document.activeElement.name; //获取元素的名称    
//    //如果控件不是文本
//    //如果控件是文本,Name非空时(如checkbox)
//    //条码获取焦点
//    if ((itemTag != 'INPUT') ||
//        (itemTag == 'INPUT' && name != '')) {
//        $(codeID).focus();
//    }
//}