admin
2024-01-12 3cc468703cb525bfcb1d9a1089c8e8c335e66487
提交 | 用户 | 时间
71e81e 1
2 layui.use(['table', 'admin', 'ax', 'func'], function () {
3     var $ = layui.$;
4     var table = layui.table;
5     var $ax = layui.ax;
6     var admin = layui.admin;
7     var func = layui.func;
8
9         /**
10      * 看板配置管理
11      */
12     var KanbanConf = {
13         tableId: "kanbanConfTable"
14     };
15
16     /**
17      * bom信息管理
18      */
19     var BomInfo = {
20         tableId: "bomInfoTable"
21     };
22
23     /**
24      * bom信息管理
25      */
26     var MaterialShortage = {
27         tableId: "materialShortageTable"
28     };
29
30     initPageInfo();
31     async function initPageInfo() {
32         await initKanBanConfInfo();//初始化配置信息
33         await initOrderInfo();
a55627 34        // initBomTable();
71e81e 35         initMaterialShortage();
36      /*   xR();
37         xa();*/
38     }
a55627 39
71e81e 40
41
42
43
44     function initKanBanConfInfo() {
45         // 根据ip查询配置信息
46         var ajax = new $ax(Feng.ctxPath + "/materialRegistration/qryKBConflist?pageCode=" + 'KB_WLDJ_001');
47         var result = ajax.start();
48         if (result.data.length > 0) {
49             let msg = result.data[0];
50             $('#id').val(msg.id);
51             $('#ipAddress').val(msg.ipAddress);
52             $('#pageCode').val(msg.pageCode);
53             $('#workshopCode').val(msg.workshopCode);
54             $('#lineCode').val(msg.lineCode);
55             $('#locationCode').val(msg.locationCode);
56         }
57     }
58
59     var ip = "";
60     $(document).ready(function () {
61         console.log("111111111");
62         console.log($('#locationCode').val());
63         var ajax = new $ax(Feng.ctxPath + "/scannerConfig/getOneByLocationCode?locationCode=" + $('#locationCode').val());
64         var result = ajax.start();
65         console.log(result.data);
66         ip = result.data.ipAddress;
67     });
68
69     function initOrderInfo() {
70         // 根据ip查询配置信息
71         var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/list?orderStatus=" + '3');
72         var result = ajax.start();
73         if (result.data.length > 0) {
74             let msg = result.data[0];
75             $('#orderId').val(msg.id);
76             $('#workOrderNo').val(msg.workOrderNo);
77             $('#materialCode').val(msg.materialCode);
78             $('#materialName').val(msg.materialName);
79             $('#planQty').val(msg.planQty);
80
81             $('#custom').val(msg.custom);
82             $('#createTime').val(msg.createTime);
83             $('#actualQty').val(msg.actualQty);
84             $('#planStartTime').val(msg.planStartTime);
85             $('#planEndTime').val(msg.planEndTime);
86         }
87     }
88
89     function initBomTable(){
90         var queryData = {};
a55627 91         // queryData['loadingCode'] = $("#locationCode").val();
71e81e 92         // queryData['workOrderNo'] = $("#workOrderNo").val();
93
94         // 渲染表格
95         var tableResult = table.render({
96             elem: '#' + BomInfo.tableId,
97             url: Feng.ctxPath + '/bomInfo/kbListTable',
98             // page: true,
99             // height: 475,
100             height: 435,
101             cellMinWidth: 100,
102             where:queryData,
103             cols: BomInfo.initColumn()
104         });
105     }
106     /**
107      * 物料Bom初始化表格的列
108      */
109     BomInfo.initColumn = function () {
110         return [[
111             // {type: 'checkbox'},
112             /*  {type:"numbers" ,title:'序号',width:40,fixed:'left'},*/
113             {field: 'id', hide: true, title: 'ID'},
114             {field: 'materialCode', sort: true, title: '物料编号'},
115             {field: 'materialName', sort: true, title: '物料名称'},
116             // {field: 'workorderNo', sort: true, title: '工单编号'},
117             // {field: 'productCode', sort: true, title: '产品编号'},
118             {field: 'locationCode', sort: true, title: '工位编号'},
a55627 119            // {field: 'loadingCode', sort: true, title: '上料工位编号'},
71e81e 120             // {field: 'state', sort: true, title: '是否扫码'},
121             // {field: 'batchCode', sort: true, title: '批次码'},
122         ]];
123     };
124
125     /**
126      * 缺料报警初始化表格的列
127      */
128     MaterialShortage.initColumn = function () {
129         return [[
1b72fc 130             {type: 'checkbox', fixed: 'left'},
3cc468 131
71e81e 132             {field: 'id', hide: true, title: 'ID'},
3cc468 133           /*  {field: 'workOrderNo', sort: true, title: '工单号', width: 150},*/
71e81e 134             // {field: 'loadingCode', sort: true, title: '上料工位', width: 105},
37478c 135             {field: 'locationCode', sort: true, title: '工位编号', width: 100},
a55627 136             //{field: 'loadingCode', sort: true, title: '扫码工位编号', width: 105},
37478c 137             {field: 'materialCode', sort: true, title: '物料编码', width: 170},
be26d5 138             {field: 'batch', sort: true, title: '物料批次',width: 120},
139             {field: 'quantity', sort: true, title: '上料数量',width: 120},
140             {field: 'residueQuantity', sort: true, title: '剩余数量',width: 120},
141             {field: 'unit', sort: true, title: '单位'},
142             {field: 'status', sort: true, title: '是否上料', width: 105,templet: '#stateTpl'},
a55627 143             // {field: 'orderStatus', sort: true, title: '状态',align:'center',width:80,templet: '#orderStatusTpl'},
144
71e81e 145         ]];
146     };
147
148     function initMaterialShortage(){
149         var queryData = {};
150         queryData['workOrderNo'] = $("#workOrderNo").val();
a55627 151         // queryData['loadingCode'] = $("#locationCode").val();
71e81e 152
153         // 渲染表格
154         var tableResult = table.render({
155             elem: '#' + MaterialShortage.tableId,
156             url: Feng.ctxPath + '/productionOrderBatchInfo/boardList',
157             // page: true,
158             height: 345,
1b72fc 159             toolbar: '#toolbarDemo',
71e81e 160             cellMinWidth: 80,
161             where:queryData,
162             cols: MaterialShortage.initColumn()
163         });
1b72fc 164     }
165
166     // 工具栏事件
167     table.on('toolbar(materialShortageTable)', function(obj){
168         var id = obj.config.id;
169         var checkStatus = table.checkStatus(id);
170         switch(obj.event){
171             case 'getCheckData':
172                 var data = checkStatus.data;
173                 console.log(data.length)
174                 console.log(data)
175                 if(data.length!==1){
176                     Feng.error("请正确选择一条数据")
177                     return
178                 }
179                 resetting(data[0].id)
180                 break;
181         };
182     });
183
184     function resetting(data){
185         var resetting = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/resetting?id=" + data);
186         var resettingResult = resetting.start();
187         initMaterialShortage()
188         Feng.success("重置成功")
71e81e 189     }
190
191     // 生产工单设置按钮点击事件
192     $('#orderBtnSet').click(function () {
193         KanbanConf.openOrderEditPage();
194     });
195
196     // 设置按钮点击事件
197     $('#btnSet').click(function () {
198         var id = $("#id").val();
199         if(id == "" || id == undefined){
200             KanbanConf.openAddDlg();
201         }else{
202             KanbanConf.openEditPage(id);
203         }
204
205     });
206
207     /**
208      * 弹出添加页面设置对话框
209      */
210     KanbanConf.openAddDlg = function () {
211         layer.open({
212             type: 2,
213             area: ['1000px', '600px'],
214             title: '添加看板配置',
215             content: Feng.ctxPath + '/materialRegistration/add',
216             success: function (layero, index) {
217                 let body = layer.getChildFrame('body', index);
218                 body.find('form').find('#testlineCode').val($('#lineCode').val());
219                 body.find('form').find('#testlocationCode').val($('#locationCode').val());
220             },
221             end: function () {
222                 console.log("end")
223                 let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
224                 let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
225                 $('#lineCode').val(lineCode);
226                 $('#locationCode').val(locationCode);
227                 initKanBanConfInfo()
228             }
229         });
230     };
231
232     /**
233      * 弹出编辑页面设置对话框
234      *
235      * @param data 点击按钮时候的行数据
236      */
237     KanbanConf.openEditPage = function (data) {
238         func.open({
239             title: '添加看板配置',
240             content: Feng.ctxPath + '/materialRegistration/edit?id=' + data,
241             //tableId: KanbanConf.tableId
242         });
243
244     };
245
246     $('#revert').click(function () {
247         window.location.href = Feng.ctxPath + '/badBoard/boardHome'
248     });
249
250     KanbanConf.openOrderEditPage = function (data) {
251         layer.open({
252             type: 2,
253             area: ['1000px', '600px'],
254             title: '工单配置',
255             content: Feng.ctxPath + '/materialRegistration/orderEdit',
256             success: function () {
257                 console.log($('#lineCode').val());
258                 window.lineCode = $('#lineCode').val();
259             },
260             end: function () {
261                 let msg = JSON.parse(window.localStorage.getItem('message'));
262                 console.log("选择工单_id", msg.id)
263                 $('#orderId').val(msg.id);
264                 $('#workOrderNo').val(msg.workOrderNo);
265                 $('#materialCode').val(msg.materialCode);
266                 $('#materialName').val(msg.materialName);
267                 $('#planQty').val(msg.planQty);
268                 $('#createTime').val(msg.createTime);
269                 $('#actualQty').val(msg.actualQty);
270                 initMaterialShortage();
271             }
272         });
273     };
274
a55627 275     // $("#barCode").bind("keydown",function(e){
276     //     // 兼容FF和IE和Opera
277     //     var theEvent = e || window.event;
278     //     var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
279     //     if (code === 13) {
280     //         var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
281     //         var result1 = ajax1.start();
282     //         console.log(result1.data);
283     //         if(result1.data!==0) {
284     //             //回车执行查询
285     //             var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
286     //             var result = ajax.start();
287     //             console.log(result.data);
288     //             if (result.data === 0) {
289     //                 let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
290     //                 }, function (data) {
291     //                     Feng.error("添加失败!" + data.responseJSON.message)
292     //                 });
293     //                 ajax.set("materialCode", $('#barCode').val());
294     //                 ajax.set("workOrderNo", $('#workOrderNo').val());
295     //                 ajax.set("state", "是");
296     //                 ajax.start();
297     //                 // initBomTable();
298     //                 initMaterialShortage();
299     //             } else {
300     //                 layer.open({
301     //                     title: "操作提示",
302     //                     icon: 0,
303     //                     closeBtn: 2,
304     //                     area: ['450px', '160px'],
305     //                     time: 5000,
306     //                     content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
307     //                 });
308     //             }
309     //         }else {
310     //             layer.open({
311     //                 title: "操作提示",
312     //                 icon: 0,
313     //                 closeBtn: 2,
314     //                 area: ['450px', '160px'],
315     //                 time: 5000,
316     //                 content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
317     //             });
318     //         }
319     //     }
320     // });
71e81e 321
322     $('#btnClean').click(function (){
a55627 323         clean()
71e81e 324     });
a55627 325
326     function clean(){
327         $('#barCode').val("");
328         $('#number').val("");
329     }
330     $('#confirm').click(function (){
331         inputMethod($('#barCode').val());
332        // let barCode = $('#barCode').val();
333        // let batch = barCode.substring(14,25);
334        // let number = $('#number').val();
335        // if(barCode === '' || number === ''){
336        //     Feng.error("请输入条码和数量的完整信息");
337        //     return
338        // }else if(barCode.length!==25){
339        //     Feng.error("请输入完整长度信息");
340        //     return
341        // }
342        // var checkLocationCode = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/checkLocationCode?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val());
343        // var checkLocationCodeResult = checkLocationCode.start();
344        // if(checkLocationCodeResult.data === 0){
345        //     Feng.error("条码信息异常")
346        //     return
347        // }
348        //  var updateOrderBatchInfo = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateOrderBatchInfo?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val()+ "&spareField1="+ number + "&loadingCode="+ batch);
349        //  var updateOrderBatchInfoResult = updateOrderBatchInfo.start();
350        //  Feng.success("录入成功")
351        //  clean()
352        //  initMaterialShortage()
353     });
354
355     function inputMethod(inBarCode){
356         let barCode = inBarCode;
357         let batch = barCode.substring(14,25);
358         let number = $('#number').val();
359         if(barCode === '' || number === ''){
360             Feng.error("请输入条码和数量的完整信息");
361             return
362         }else if(barCode.length!==25){
363             Feng.error("请输入完整长度信息");
364             return
365         }
1b72fc 366         // var checkLocationCode = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/checkLocationCode?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val());
367         // var checkLocationCodeResult = checkLocationCode.start();
368         // if(checkLocationCodeResult.data === 0){
369         //     Feng.error("条码信息异常")
370         //     return
371         // }
be26d5 372         var updateOrderBatchInfo = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateOrderBatchInfo?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val()+ "&quantity="+ number + "&batch="+ batch+ "&residueQuantity="+ number);
a55627 373         var updateOrderBatchInfoResult = updateOrderBatchInfo.start();
1b72fc 374         if(updateOrderBatchInfoResult.data === "0"){
375             Feng.error("批次不同无法录入");
376             return;
377         }
a55627 378         Feng.success("录入成功")
379         clean()
380         initMaterialShortage()
381     }
382
71e81e 383
384     var websocket = null;
385     //判断当前浏览器是否支持WebSocket
386     if('WebSocket' in window) {
387         //改成你的地址
388         // websocket = new WebSocket('ws://'+ip+':8083/websocket/materialRegistration');
389         websocket = new WebSocket('ws://127.0.0.1:8083/websocket/materialRegistration');
390     } else {
391         alert('当前浏览器 Not support websocket')
392     }
393     //接收到消息的回调方法
394     websocket.onmessage = function(event) {
a55627 395         inputMethod(event.data);
396         // console.log(event);
397         // console.log(event.data)
398         // $('#barCode').val(event.data);
399         //     var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
400         //     var result1 = ajax1.start();
401         //     console.log(result1.data);
402         //     if(result1.data!==0) {
403         //         //回车执行查询
404         //         var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
405         //         var result = ajax.start();
406         //         console.log(result.data);
407         //         if (result.data === 0) {
408         //             let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
409         //             }, function (data) {
410         //                 Feng.error("添加失败!" + data.responseJSON.message)
411         //             });
412         //             ajax.set("materialCode", $('#barCode').val());
413         //             ajax.set("workOrderNo", $('#workOrderNo').val());
414         //             ajax.set("state", "是");
415         //             ajax.start();
416         //             // initBomTable();
417         //             initMaterialShortage();
418         //         } else {
419         //             layer.open({
420         //                 title: "操作提示",
421         //                 icon: 0,
422         //                 closeBtn: 2,
423         //                 area: ['450px', '160px'],
424         //                 time: 5000,
425         //                 content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
426         //             });
427         //         }
428         //     }else {
429         //         layer.open({
430         //             title: "操作提示",
431         //             icon: 0,
432         //             closeBtn: 2,
433         //             area: ['450px', '160px'],
434         //             time: 5000,
435         //             content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
436         //         });
437         //     }
71e81e 438     }
439
440     //连接成功建立的回调方法
441     websocket.onopen = function() {
442         Feng.info("扫码枪连接建立成功")
443         console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接成功")
444     }
445
446     //连接关闭的回调方法
447     websocket.onclose = function() {
448         Feng.info("扫码枪连接已关闭")
449         console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接失败不能发送消息")
450     }
451
452     window.onunload = function(){
453         websocket.close();
454     }
455
456
457 });