admin
2024-01-12 3cc468703cb525bfcb1d9a1089c8e8c335e66487
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
 
layui.use(['table', 'admin', 'ax', 'func'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
 
        /**
     * 看板配置管理
     */
    var KanbanConf = {
        tableId: "kanbanConfTable"
    };
 
    /**
     * bom信息管理
     */
    var BomInfo = {
        tableId: "bomInfoTable"
    };
 
    /**
     * bom信息管理
     */
    var MaterialShortage = {
        tableId: "materialShortageTable"
    };
 
    initPageInfo();
    async function initPageInfo() {
        await initKanBanConfInfo();//初始化配置信息
        await initOrderInfo();
       // initBomTable();
        initMaterialShortage();
     /*   xR();
        xa();*/
    }
 
 
 
 
 
    function initKanBanConfInfo() {
        // 根据ip查询配置信息
        var ajax = new $ax(Feng.ctxPath + "/materialRegistration/qryKBConflist?pageCode=" + 'KB_WLDJ_001');
        var result = ajax.start();
        if (result.data.length > 0) {
            let msg = result.data[0];
            $('#id').val(msg.id);
            $('#ipAddress').val(msg.ipAddress);
            $('#pageCode').val(msg.pageCode);
            $('#workshopCode').val(msg.workshopCode);
            $('#lineCode').val(msg.lineCode);
            $('#locationCode').val(msg.locationCode);
        }
    }
 
    var ip = "";
    $(document).ready(function () {
        console.log("111111111");
        console.log($('#locationCode').val());
        var ajax = new $ax(Feng.ctxPath + "/scannerConfig/getOneByLocationCode?locationCode=" + $('#locationCode').val());
        var result = ajax.start();
        console.log(result.data);
        ip = result.data.ipAddress;
    });
 
    function initOrderInfo() {
        // 根据ip查询配置信息
        var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/list?orderStatus=" + '3');
        var result = ajax.start();
        if (result.data.length > 0) {
            let msg = result.data[0];
            $('#orderId').val(msg.id);
            $('#workOrderNo').val(msg.workOrderNo);
            $('#materialCode').val(msg.materialCode);
            $('#materialName').val(msg.materialName);
            $('#planQty').val(msg.planQty);
 
            $('#custom').val(msg.custom);
            $('#createTime').val(msg.createTime);
            $('#actualQty').val(msg.actualQty);
            $('#planStartTime').val(msg.planStartTime);
            $('#planEndTime').val(msg.planEndTime);
        }
    }
 
    function initBomTable(){
        var queryData = {};
        // queryData['loadingCode'] = $("#locationCode").val();
        // queryData['workOrderNo'] = $("#workOrderNo").val();
 
        // 渲染表格
        var tableResult = table.render({
            elem: '#' + BomInfo.tableId,
            url: Feng.ctxPath + '/bomInfo/kbListTable',
            // page: true,
            // height: 475,
            height: 435,
            cellMinWidth: 100,
            where:queryData,
            cols: BomInfo.initColumn()
        });
    }
    /**
     * 物料Bom初始化表格的列
     */
    BomInfo.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            /*  {type:"numbers" ,title:'序号',width:40,fixed:'left'},*/
            {field: 'id', hide: true, title: 'ID'},
            {field: 'materialCode', sort: true, title: '物料编号'},
            {field: 'materialName', sort: true, title: '物料名称'},
            // {field: 'workorderNo', sort: true, title: '工单编号'},
            // {field: 'productCode', sort: true, title: '产品编号'},
            {field: 'locationCode', sort: true, title: '工位编号'},
           // {field: 'loadingCode', sort: true, title: '上料工位编号'},
            // {field: 'state', sort: true, title: '是否扫码'},
            // {field: 'batchCode', sort: true, title: '批次码'},
        ]];
    };
 
    /**
     * 缺料报警初始化表格的列
     */
    MaterialShortage.initColumn = function () {
        return [[
            {type: 'checkbox', fixed: 'left'},
 
            {field: 'id', hide: true, title: 'ID'},
          /*  {field: 'workOrderNo', sort: true, title: '工单号', width: 150},*/
            // {field: 'loadingCode', sort: true, title: '上料工位', width: 105},
            {field: 'locationCode', sort: true, title: '工位编号', width: 100},
            //{field: 'loadingCode', sort: true, title: '扫码工位编号', width: 105},
            {field: 'materialCode', sort: true, title: '物料编码', width: 170},
            {field: 'batch', sort: true, title: '物料批次',width: 120},
            {field: 'quantity', sort: true, title: '上料数量',width: 120},
            {field: 'residueQuantity', sort: true, title: '剩余数量',width: 120},
            {field: 'unit', sort: true, title: '单位'},
            {field: 'status', sort: true, title: '是否上料', width: 105,templet: '#stateTpl'},
            // {field: 'orderStatus', sort: true, title: '状态',align:'center',width:80,templet: '#orderStatusTpl'},
 
        ]];
    };
 
    function initMaterialShortage(){
        var queryData = {};
        queryData['workOrderNo'] = $("#workOrderNo").val();
        // queryData['loadingCode'] = $("#locationCode").val();
 
        // 渲染表格
        var tableResult = table.render({
            elem: '#' + MaterialShortage.tableId,
            url: Feng.ctxPath + '/productionOrderBatchInfo/boardList',
            // page: true,
            height: 345,
            toolbar: '#toolbarDemo',
            cellMinWidth: 80,
            where:queryData,
            cols: MaterialShortage.initColumn()
        });
    }
 
    // 工具栏事件
    table.on('toolbar(materialShortageTable)', function(obj){
        var id = obj.config.id;
        var checkStatus = table.checkStatus(id);
        switch(obj.event){
            case 'getCheckData':
                var data = checkStatus.data;
                console.log(data.length)
                console.log(data)
                if(data.length!==1){
                    Feng.error("请正确选择一条数据")
                    return
                }
                resetting(data[0].id)
                break;
        };
    });
 
    function resetting(data){
        var resetting = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/resetting?id=" + data);
        var resettingResult = resetting.start();
        initMaterialShortage()
        Feng.success("重置成功")
    }
 
    // 生产工单设置按钮点击事件
    $('#orderBtnSet').click(function () {
        KanbanConf.openOrderEditPage();
    });
 
    // 设置按钮点击事件
    $('#btnSet').click(function () {
        var id = $("#id").val();
        if(id == "" || id == undefined){
            KanbanConf.openAddDlg();
        }else{
            KanbanConf.openEditPage(id);
        }
 
    });
 
    /**
     * 弹出添加页面设置对话框
     */
    KanbanConf.openAddDlg = function () {
        layer.open({
            type: 2,
            area: ['1000px', '600px'],
            title: '添加看板配置',
            content: Feng.ctxPath + '/materialRegistration/add',
            success: function (layero, index) {
                let body = layer.getChildFrame('body', index);
                body.find('form').find('#testlineCode').val($('#lineCode').val());
                body.find('form').find('#testlocationCode').val($('#locationCode').val());
            },
            end: function () {
                console.log("end")
                let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
                let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
                $('#lineCode').val(lineCode);
                $('#locationCode').val(locationCode);
                initKanBanConfInfo()
            }
        });
    };
 
    /**
     * 弹出编辑页面设置对话框
     *
     * @param data 点击按钮时候的行数据
     */
    KanbanConf.openEditPage = function (data) {
        func.open({
            title: '添加看板配置',
            content: Feng.ctxPath + '/materialRegistration/edit?id=' + data,
            //tableId: KanbanConf.tableId
        });
 
    };
 
    $('#revert').click(function () {
        window.location.href = Feng.ctxPath + '/badBoard/boardHome'
    });
 
    KanbanConf.openOrderEditPage = function (data) {
        layer.open({
            type: 2,
            area: ['1000px', '600px'],
            title: '工单配置',
            content: Feng.ctxPath + '/materialRegistration/orderEdit',
            success: function () {
                console.log($('#lineCode').val());
                window.lineCode = $('#lineCode').val();
            },
            end: function () {
                let msg = JSON.parse(window.localStorage.getItem('message'));
                console.log("选择工单_id", msg.id)
                $('#orderId').val(msg.id);
                $('#workOrderNo').val(msg.workOrderNo);
                $('#materialCode').val(msg.materialCode);
                $('#materialName').val(msg.materialName);
                $('#planQty').val(msg.planQty);
                $('#createTime').val(msg.createTime);
                $('#actualQty').val(msg.actualQty);
                initMaterialShortage();
            }
        });
    };
 
    // $("#barCode").bind("keydown",function(e){
    //     // 兼容FF和IE和Opera
    //     var theEvent = e || window.event;
    //     var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    //     if (code === 13) {
    //         var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
    //         var result1 = ajax1.start();
    //         console.log(result1.data);
    //         if(result1.data!==0) {
    //             //回车执行查询
    //             var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
    //             var result = ajax.start();
    //             console.log(result.data);
    //             if (result.data === 0) {
    //                 let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
    //                 }, function (data) {
    //                     Feng.error("添加失败!" + data.responseJSON.message)
    //                 });
    //                 ajax.set("materialCode", $('#barCode').val());
    //                 ajax.set("workOrderNo", $('#workOrderNo').val());
    //                 ajax.set("state", "是");
    //                 ajax.start();
    //                 // initBomTable();
    //                 initMaterialShortage();
    //             } else {
    //                 layer.open({
    //                     title: "操作提示",
    //                     icon: 0,
    //                     closeBtn: 2,
    //                     area: ['450px', '160px'],
    //                     time: 5000,
    //                     content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
    //                 });
    //             }
    //         }else {
    //             layer.open({
    //                 title: "操作提示",
    //                 icon: 0,
    //                 closeBtn: 2,
    //                 area: ['450px', '160px'],
    //                 time: 5000,
    //                 content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
    //             });
    //         }
    //     }
    // });
 
    $('#btnClean').click(function (){
        clean()
    });
 
    function clean(){
        $('#barCode').val("");
        $('#number').val("");
    }
    $('#confirm').click(function (){
        inputMethod($('#barCode').val());
       // let barCode = $('#barCode').val();
       // let batch = barCode.substring(14,25);
       // let number = $('#number').val();
       // if(barCode === '' || number === ''){
       //     Feng.error("请输入条码和数量的完整信息");
       //     return
       // }else if(barCode.length!==25){
       //     Feng.error("请输入完整长度信息");
       //     return
       // }
       // var checkLocationCode = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/checkLocationCode?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val());
       // var checkLocationCodeResult = checkLocationCode.start();
       // if(checkLocationCodeResult.data === 0){
       //     Feng.error("条码信息异常")
       //     return
       // }
       //  var updateOrderBatchInfo = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateOrderBatchInfo?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val()+ "&spareField1="+ number + "&loadingCode="+ batch);
       //  var updateOrderBatchInfoResult = updateOrderBatchInfo.start();
       //  Feng.success("录入成功")
       //  clean()
       //  initMaterialShortage()
    });
 
    function inputMethod(inBarCode){
        let barCode = inBarCode;
        let batch = barCode.substring(14,25);
        let number = $('#number').val();
        if(barCode === '' || number === ''){
            Feng.error("请输入条码和数量的完整信息");
            return
        }else if(barCode.length!==25){
            Feng.error("请输入完整长度信息");
            return
        }
        // var checkLocationCode = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/checkLocationCode?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val());
        // var checkLocationCodeResult = checkLocationCode.start();
        // if(checkLocationCodeResult.data === 0){
        //     Feng.error("条码信息异常")
        //     return
        // }
        var updateOrderBatchInfo = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateOrderBatchInfo?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val()+ "&quantity="+ number + "&batch="+ batch+ "&residueQuantity="+ number);
        var updateOrderBatchInfoResult = updateOrderBatchInfo.start();
        if(updateOrderBatchInfoResult.data === "0"){
            Feng.error("批次不同无法录入");
            return;
        }
        Feng.success("录入成功")
        clean()
        initMaterialShortage()
    }
 
 
    var websocket = null;
    //判断当前浏览器是否支持WebSocket
    if('WebSocket' in window) {
        //改成你的地址
        // websocket = new WebSocket('ws://'+ip+':8083/websocket/materialRegistration');
        websocket = new WebSocket('ws://127.0.0.1:8083/websocket/materialRegistration');
    } else {
        alert('当前浏览器 Not support websocket')
    }
    //接收到消息的回调方法
    websocket.onmessage = function(event) {
        inputMethod(event.data);
        // console.log(event);
        // console.log(event.data)
        // $('#barCode').val(event.data);
        //     var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
        //     var result1 = ajax1.start();
        //     console.log(result1.data);
        //     if(result1.data!==0) {
        //         //回车执行查询
        //         var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
        //         var result = ajax.start();
        //         console.log(result.data);
        //         if (result.data === 0) {
        //             let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
        //             }, function (data) {
        //                 Feng.error("添加失败!" + data.responseJSON.message)
        //             });
        //             ajax.set("materialCode", $('#barCode').val());
        //             ajax.set("workOrderNo", $('#workOrderNo').val());
        //             ajax.set("state", "是");
        //             ajax.start();
        //             // initBomTable();
        //             initMaterialShortage();
        //         } else {
        //             layer.open({
        //                 title: "操作提示",
        //                 icon: 0,
        //                 closeBtn: 2,
        //                 area: ['450px', '160px'],
        //                 time: 5000,
        //                 content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
        //             });
        //         }
        //     }else {
        //         layer.open({
        //             title: "操作提示",
        //             icon: 0,
        //             closeBtn: 2,
        //             area: ['450px', '160px'],
        //             time: 5000,
        //             content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
        //         });
        //     }
    }
 
    //连接成功建立的回调方法
    websocket.onopen = function() {
        Feng.info("扫码枪连接建立成功")
        console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接成功")
    }
 
    //连接关闭的回调方法
    websocket.onclose = function() {
        Feng.info("扫码枪连接已关闭")
        console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接失败不能发送消息")
    }
 
    window.onunload = function(){
        websocket.close();
    }
 
 
});