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