懒羊羊
2024-01-10 1b72fc0dd1d7004de54ab0886e0323cb1b96198d
提交 | 用户 | 时间
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'},
71e81e 131             {field: 'id', hide: true, title: 'ID'},
37478c 132             {field: 'workOrderNo', sort: true, title: '工单号', width: 150},
71e81e 133             // {field: 'loadingCode', sort: true, title: '上料工位', width: 105},
37478c 134             {field: 'locationCode', sort: true, title: '工位编号', width: 100},
a55627 135             //{field: 'loadingCode', sort: true, title: '扫码工位编号', width: 105},
37478c 136             {field: 'materialCode', sort: true, title: '物料编码', width: 170},
7f2919 137             {field: 'spareField1', sort: true, title: '上料数量'},
a55627 138             {field: 'spareField2', sort: true, title: '单位'},
37478c 139             {field: 'loadingCode', sort: true, title: '物料批次',width: 120},
A 140             {field: 'state', sort: true, title: '是否上料', width: 105,templet: '#stateTpl'},
a55627 141             // {field: 'orderStatus', sort: true, title: '状态',align:'center',width:80,templet: '#orderStatusTpl'},
142
71e81e 143         ]];
144     };
145
146     function initMaterialShortage(){
147         var queryData = {};
148         queryData['workOrderNo'] = $("#workOrderNo").val();
a55627 149         // queryData['loadingCode'] = $("#locationCode").val();
71e81e 150
151         // 渲染表格
152         var tableResult = table.render({
153             elem: '#' + MaterialShortage.tableId,
154             url: Feng.ctxPath + '/productionOrderBatchInfo/boardList',
155             // page: true,
156             height: 345,
1b72fc 157             toolbar: '#toolbarDemo',
71e81e 158             cellMinWidth: 80,
159             where:queryData,
160             cols: MaterialShortage.initColumn()
161         });
1b72fc 162     }
163
164     // 工具栏事件
165     table.on('toolbar(materialShortageTable)', function(obj){
166         var id = obj.config.id;
167         var checkStatus = table.checkStatus(id);
168         switch(obj.event){
169             case 'getCheckData':
170                 var data = checkStatus.data;
171                 console.log(data.length)
172                 console.log(data)
173                 if(data.length!==1){
174                     Feng.error("请正确选择一条数据")
175                     return
176                 }
177                 resetting(data[0].id)
178                 break;
179         };
180     });
181
182     function resetting(data){
183         var resetting = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/resetting?id=" + data);
184         var resettingResult = resetting.start();
185         initMaterialShortage()
186         Feng.success("重置成功")
71e81e 187     }
188
189     // 生产工单设置按钮点击事件
190     $('#orderBtnSet').click(function () {
191         KanbanConf.openOrderEditPage();
192     });
193
194     // 设置按钮点击事件
195     $('#btnSet').click(function () {
196         var id = $("#id").val();
197         if(id == "" || id == undefined){
198             KanbanConf.openAddDlg();
199         }else{
200             KanbanConf.openEditPage(id);
201         }
202
203     });
204
205     /**
206      * 弹出添加页面设置对话框
207      */
208     KanbanConf.openAddDlg = function () {
209         layer.open({
210             type: 2,
211             area: ['1000px', '600px'],
212             title: '添加看板配置',
213             content: Feng.ctxPath + '/materialRegistration/add',
214             success: function (layero, index) {
215                 let body = layer.getChildFrame('body', index);
216                 body.find('form').find('#testlineCode').val($('#lineCode').val());
217                 body.find('form').find('#testlocationCode').val($('#locationCode').val());
218             },
219             end: function () {
220                 console.log("end")
221                 let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
222                 let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
223                 $('#lineCode').val(lineCode);
224                 $('#locationCode').val(locationCode);
225                 initKanBanConfInfo()
226             }
227         });
228     };
229
230     /**
231      * 弹出编辑页面设置对话框
232      *
233      * @param data 点击按钮时候的行数据
234      */
235     KanbanConf.openEditPage = function (data) {
236         func.open({
237             title: '添加看板配置',
238             content: Feng.ctxPath + '/materialRegistration/edit?id=' + data,
239             //tableId: KanbanConf.tableId
240         });
241
242     };
243
244     $('#revert').click(function () {
245         window.location.href = Feng.ctxPath + '/badBoard/boardHome'
246     });
247
248     KanbanConf.openOrderEditPage = function (data) {
249         layer.open({
250             type: 2,
251             area: ['1000px', '600px'],
252             title: '工单配置',
253             content: Feng.ctxPath + '/materialRegistration/orderEdit',
254             success: function () {
255                 console.log($('#lineCode').val());
256                 window.lineCode = $('#lineCode').val();
257             },
258             end: function () {
259                 let msg = JSON.parse(window.localStorage.getItem('message'));
260                 console.log("选择工单_id", msg.id)
261                 $('#orderId').val(msg.id);
262                 $('#workOrderNo').val(msg.workOrderNo);
263                 $('#materialCode').val(msg.materialCode);
264                 $('#materialName').val(msg.materialName);
265                 $('#planQty').val(msg.planQty);
266                 $('#createTime').val(msg.createTime);
267                 $('#actualQty').val(msg.actualQty);
268                 initMaterialShortage();
269             }
270         });
271     };
272
a55627 273     // $("#barCode").bind("keydown",function(e){
274     //     // 兼容FF和IE和Opera
275     //     var theEvent = e || window.event;
276     //     var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
277     //     if (code === 13) {
278     //         var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
279     //         var result1 = ajax1.start();
280     //         console.log(result1.data);
281     //         if(result1.data!==0) {
282     //             //回车执行查询
283     //             var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
284     //             var result = ajax.start();
285     //             console.log(result.data);
286     //             if (result.data === 0) {
287     //                 let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
288     //                 }, function (data) {
289     //                     Feng.error("添加失败!" + data.responseJSON.message)
290     //                 });
291     //                 ajax.set("materialCode", $('#barCode').val());
292     //                 ajax.set("workOrderNo", $('#workOrderNo').val());
293     //                 ajax.set("state", "是");
294     //                 ajax.start();
295     //                 // initBomTable();
296     //                 initMaterialShortage();
297     //             } else {
298     //                 layer.open({
299     //                     title: "操作提示",
300     //                     icon: 0,
301     //                     closeBtn: 2,
302     //                     area: ['450px', '160px'],
303     //                     time: 5000,
304     //                     content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
305     //                 });
306     //             }
307     //         }else {
308     //             layer.open({
309     //                 title: "操作提示",
310     //                 icon: 0,
311     //                 closeBtn: 2,
312     //                 area: ['450px', '160px'],
313     //                 time: 5000,
314     //                 content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
315     //             });
316     //         }
317     //     }
318     // });
71e81e 319
320     $('#btnClean').click(function (){
a55627 321         clean()
71e81e 322     });
a55627 323
324     function clean(){
325         $('#barCode').val("");
326         $('#number').val("");
327     }
328     $('#confirm').click(function (){
329         inputMethod($('#barCode').val());
330        // let barCode = $('#barCode').val();
331        // let batch = barCode.substring(14,25);
332        // let number = $('#number').val();
333        // if(barCode === '' || number === ''){
334        //     Feng.error("请输入条码和数量的完整信息");
335        //     return
336        // }else if(barCode.length!==25){
337        //     Feng.error("请输入完整长度信息");
338        //     return
339        // }
340        // var checkLocationCode = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/checkLocationCode?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val());
341        // var checkLocationCodeResult = checkLocationCode.start();
342        // if(checkLocationCodeResult.data === 0){
343        //     Feng.error("条码信息异常")
344        //     return
345        // }
346        //  var updateOrderBatchInfo = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateOrderBatchInfo?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val()+ "&spareField1="+ number + "&loadingCode="+ batch);
347        //  var updateOrderBatchInfoResult = updateOrderBatchInfo.start();
348        //  Feng.success("录入成功")
349        //  clean()
350        //  initMaterialShortage()
351     });
352
353     function inputMethod(inBarCode){
354         let barCode = inBarCode;
355         let batch = barCode.substring(14,25);
356         let number = $('#number').val();
357         if(barCode === '' || number === ''){
358             Feng.error("请输入条码和数量的完整信息");
359             return
360         }else if(barCode.length!==25){
361             Feng.error("请输入完整长度信息");
362             return
363         }
1b72fc 364         // var checkLocationCode = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/checkLocationCode?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val());
365         // var checkLocationCodeResult = checkLocationCode.start();
366         // if(checkLocationCodeResult.data === 0){
367         //     Feng.error("条码信息异常")
368         //     return
369         // }
a55627 370         var updateOrderBatchInfo = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateOrderBatchInfo?materialCode=" + barCode.substring(0, 14) + "&workOrderNo="+ $('#workOrderNo').val()+ "&spareField1="+ number + "&loadingCode="+ batch);
371         var updateOrderBatchInfoResult = updateOrderBatchInfo.start();
1b72fc 372         if(updateOrderBatchInfoResult.data === "0"){
373             Feng.error("批次不同无法录入");
374             return;
375         }
a55627 376         Feng.success("录入成功")
377         clean()
378         initMaterialShortage()
379     }
380
71e81e 381
382     var websocket = null;
383     //判断当前浏览器是否支持WebSocket
384     if('WebSocket' in window) {
385         //改成你的地址
386         // websocket = new WebSocket('ws://'+ip+':8083/websocket/materialRegistration');
387         websocket = new WebSocket('ws://127.0.0.1:8083/websocket/materialRegistration');
388     } else {
389         alert('当前浏览器 Not support websocket')
390     }
391     //接收到消息的回调方法
392     websocket.onmessage = function(event) {
a55627 393         inputMethod(event.data);
394         // console.log(event);
395         // console.log(event.data)
396         // $('#barCode').val(event.data);
397         //     var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
398         //     var result1 = ajax1.start();
399         //     console.log(result1.data);
400         //     if(result1.data!==0) {
401         //         //回车执行查询
402         //         var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
403         //         var result = ajax.start();
404         //         console.log(result.data);
405         //         if (result.data === 0) {
406         //             let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
407         //             }, function (data) {
408         //                 Feng.error("添加失败!" + data.responseJSON.message)
409         //             });
410         //             ajax.set("materialCode", $('#barCode').val());
411         //             ajax.set("workOrderNo", $('#workOrderNo').val());
412         //             ajax.set("state", "是");
413         //             ajax.start();
414         //             // initBomTable();
415         //             initMaterialShortage();
416         //         } else {
417         //             layer.open({
418         //                 title: "操作提示",
419         //                 icon: 0,
420         //                 closeBtn: 2,
421         //                 area: ['450px', '160px'],
422         //                 time: 5000,
423         //                 content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
424         //             });
425         //         }
426         //     }else {
427         //         layer.open({
428         //             title: "操作提示",
429         //             icon: 0,
430         //             closeBtn: 2,
431         //             area: ['450px', '160px'],
432         //             time: 5000,
433         //             content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
434         //         });
435         //     }
71e81e 436     }
437
438     //连接成功建立的回调方法
439     websocket.onopen = function() {
440         Feng.info("扫码枪连接建立成功")
441         console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接成功")
442     }
443
444     //连接关闭的回调方法
445     websocket.onclose = function() {
446         Feng.info("扫码枪连接已关闭")
447         console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接失败不能发送消息")
448     }
449
450     window.onunload = function(){
451         websocket.close();
452     }
453
454
455 });