OPC
懒羊羊
2023-12-23 9a879095206a68280f7b322e60039524473bcd1d
提交 | 用户 | 时间
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();
34         initBomTable();
35         initMaterialShortage();
36      /*   xR();
37         xa();*/
38     }
39
40
41
42
43     function initKanBanConfInfo() {
44         // 根据ip查询配置信息
45         var ajax = new $ax(Feng.ctxPath + "/materialRegistration/qryKBConflist?pageCode=" + 'KB_WLDJ_001');
46         var result = ajax.start();
47         if (result.data.length > 0) {
48             let msg = result.data[0];
49             $('#id').val(msg.id);
50             $('#ipAddress').val(msg.ipAddress);
51             $('#pageCode').val(msg.pageCode);
52             $('#workshopCode').val(msg.workshopCode);
53             $('#lineCode').val(msg.lineCode);
54             $('#locationCode').val(msg.locationCode);
55         }
56     }
57
58     var ip = "";
59     $(document).ready(function () {
60         console.log("111111111");
61         console.log($('#locationCode').val());
62         var ajax = new $ax(Feng.ctxPath + "/scannerConfig/getOneByLocationCode?locationCode=" + $('#locationCode').val());
63         var result = ajax.start();
64         console.log(result.data);
65         ip = result.data.ipAddress;
66     });
67
68     function initOrderInfo() {
69         // 根据ip查询配置信息
70         var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/list?orderStatus=" + '3');
71         var result = ajax.start();
72         if (result.data.length > 0) {
73             let msg = result.data[0];
74             $('#orderId').val(msg.id);
75             $('#workOrderNo').val(msg.workOrderNo);
76             $('#materialCode').val(msg.materialCode);
77             $('#materialName').val(msg.materialName);
78             $('#planQty').val(msg.planQty);
79
80             $('#custom').val(msg.custom);
81             $('#createTime').val(msg.createTime);
82             $('#actualQty').val(msg.actualQty);
83             $('#planStartTime').val(msg.planStartTime);
84             $('#planEndTime').val(msg.planEndTime);
85         }
86     }
87
88     function initBomTable(){
89         var queryData = {};
90         queryData['loadingCode'] = $("#locationCode").val();
91         // queryData['workOrderNo'] = $("#workOrderNo").val();
92
93         // 渲染表格
94         var tableResult = table.render({
95             elem: '#' + BomInfo.tableId,
96             url: Feng.ctxPath + '/bomInfo/kbListTable',
97             // page: true,
98             // height: 475,
99             height: 435,
100             cellMinWidth: 100,
101             where:queryData,
102             cols: BomInfo.initColumn()
103         });
104     }
105     /**
106      * 物料Bom初始化表格的列
107      */
108     BomInfo.initColumn = function () {
109         return [[
110             // {type: 'checkbox'},
111             /*  {type:"numbers" ,title:'序号',width:40,fixed:'left'},*/
112             {field: 'id', hide: true, title: 'ID'},
113             {field: 'materialCode', sort: true, title: '物料编号'},
114             {field: 'materialName', sort: true, title: '物料名称'},
115             // {field: 'workorderNo', sort: true, title: '工单编号'},
116             // {field: 'productCode', sort: true, title: '产品编号'},
117             {field: 'locationCode', sort: true, title: '工位编号'},
118             {field: 'loadingCode', sort: true, title: '上料工位编号'},
119             // {field: 'state', sort: true, title: '是否扫码'},
120             // {field: 'batchCode', sort: true, title: '批次码'},
121         ]];
122     };
123
124     /**
125      * 缺料报警初始化表格的列
126      */
127     MaterialShortage.initColumn = function () {
128         return [[
129             {type: 'numbers'},
130             {field: 'id', hide: true, title: 'ID'},
131             {field: 'workOrderNo', sort: true, title: '工单号', width: 165},
132             // {field: 'loadingCode', sort: true, title: '上料工位', width: 105},
133             {field: 'locationCode', sort: true, title: '工位编号', width: 105},
134             {field: 'loadingCode', sort: true, title: '扫码工位编号', width: 105},
135             {field: 'materialCode', sort: true, title: '物料编码'},
136             {field: 'barCode', sort: true, title: '扫码编号'},
137             {field: 'state', sort: true, title: '是否扫码', width: 105},
138         ]];
139     };
140
141     function initMaterialShortage(){
142         var queryData = {};
143         queryData['workOrderNo'] = $("#workOrderNo").val();
144         queryData['loadingCode'] = $("#locationCode").val();
145
146         // 渲染表格
147         var tableResult = table.render({
148             elem: '#' + MaterialShortage.tableId,
149             url: Feng.ctxPath + '/productionOrderBatchInfo/boardList',
150             // page: true,
151             height: 345,
152             cellMinWidth: 80,
153             where:queryData,
154             cols: MaterialShortage.initColumn()
155         });
156     }
157
158     // 生产工单设置按钮点击事件
159     $('#orderBtnSet').click(function () {
160         KanbanConf.openOrderEditPage();
161     });
162
163     // 设置按钮点击事件
164     $('#btnSet').click(function () {
165         var id = $("#id").val();
166         if(id == "" || id == undefined){
167             KanbanConf.openAddDlg();
168         }else{
169             KanbanConf.openEditPage(id);
170         }
171
172     });
173
174     /**
175      * 弹出添加页面设置对话框
176      */
177     KanbanConf.openAddDlg = function () {
178         layer.open({
179             type: 2,
180             area: ['1000px', '600px'],
181             title: '添加看板配置',
182             content: Feng.ctxPath + '/materialRegistration/add',
183             success: function (layero, index) {
184                 let body = layer.getChildFrame('body', index);
185                 body.find('form').find('#testlineCode').val($('#lineCode').val());
186                 body.find('form').find('#testlocationCode').val($('#locationCode').val());
187             },
188             end: function () {
189                 console.log("end")
190                 let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
191                 let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
192                 $('#lineCode').val(lineCode);
193                 $('#locationCode').val(locationCode);
194                 initKanBanConfInfo()
195             }
196         });
197     };
198
199     /**
200      * 弹出编辑页面设置对话框
201      *
202      * @param data 点击按钮时候的行数据
203      */
204     KanbanConf.openEditPage = function (data) {
205         func.open({
206             title: '添加看板配置',
207             content: Feng.ctxPath + '/materialRegistration/edit?id=' + data,
208             //tableId: KanbanConf.tableId
209         });
210
211     };
212
213     $('#revert').click(function () {
214         window.location.href = Feng.ctxPath + '/badBoard/boardHome'
215     });
216
217     KanbanConf.openOrderEditPage = function (data) {
218         layer.open({
219             type: 2,
220             area: ['1000px', '600px'],
221             title: '工单配置',
222             content: Feng.ctxPath + '/materialRegistration/orderEdit',
223             success: function () {
224                 console.log($('#lineCode').val());
225                 window.lineCode = $('#lineCode').val();
226             },
227             end: function () {
228                 let msg = JSON.parse(window.localStorage.getItem('message'));
229                 console.log("选择工单_id", msg.id)
230                 $('#orderId').val(msg.id);
231                 $('#workOrderNo').val(msg.workOrderNo);
232                 $('#materialCode').val(msg.materialCode);
233                 $('#materialName').val(msg.materialName);
234                 $('#planQty').val(msg.planQty);
235                 $('#createTime').val(msg.createTime);
236                 $('#actualQty').val(msg.actualQty);
237                 initMaterialShortage();
238             }
239         });
240     };
241
242     $("#barCode").bind("keydown",function(e){
243         // 兼容FF和IE和Opera
244         var theEvent = e || window.event;
245         var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
246         if (code === 13) {
247             var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
248             var result1 = ajax1.start();
249             console.log(result1.data);
250             if(result1.data!==0) {
251                 //回车执行查询
252                 var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
253                 var result = ajax.start();
254                 console.log(result.data);
255                 if (result.data === 0) {
256                     let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
257                     }, function (data) {
258                         Feng.error("添加失败!" + data.responseJSON.message)
259                     });
260                     ajax.set("materialCode", $('#barCode').val());
261                     ajax.set("workOrderNo", $('#workOrderNo').val());
262                     ajax.set("state", "是");
263                     ajax.start();
264                     // initBomTable();
265                     initMaterialShortage();
266                 } else {
267                     layer.open({
268                         title: "操作提示",
269                         icon: 0,
270                         closeBtn: 2,
271                         area: ['450px', '160px'],
272                         time: 5000,
273                         content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
274                     });
275                 }
276             }else {
277                 layer.open({
278                     title: "操作提示",
279                     icon: 0,
280                     closeBtn: 2,
281                     area: ['450px', '160px'],
282                     time: 5000,
283                     content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
284                 });
285             }
286         }
287     });
288
289     $('#btnClean').click(function (){
290         $('#barCode').val("");
291     });
292
293     var websocket = null;
294     //判断当前浏览器是否支持WebSocket
295     if('WebSocket' in window) {
296         //改成你的地址
297         // websocket = new WebSocket('ws://'+ip+':8083/websocket/materialRegistration');
298         websocket = new WebSocket('ws://127.0.0.1:8083/websocket/materialRegistration');
299     } else {
300         alert('当前浏览器 Not support websocket')
301     }
302     //接收到消息的回调方法
303     websocket.onmessage = function(event) {
304         console.log(event);
305         console.log(event.data)
306         $('#barCode').val(event.data);
307             var ajax1 = new $ax(Feng.ctxPath + "/bomInfo/bomCheck?materialCode=" +$('#barCode').val()+"&loadingCode="+$('#locationCode').val());
308             var result1 = ajax1.start();
309             console.log(result1.data);
310             if(result1.data!==0) {
311                 //回车执行查询
312                 var ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/barCodeCheck?materialCode=" + $('#barCode').val() + "&workOrderNo=" + $('#workOrderNo').val());
313                 var result = ajax.start();
314                 console.log(result.data);
315                 if (result.data === 0) {
316                     let ajax = new $ax(Feng.ctxPath + "/productionOrderBatchInfo/updateState", function (data) {
317                     }, function (data) {
318                         Feng.error("添加失败!" + data.responseJSON.message)
319                     });
320                     ajax.set("materialCode", $('#barCode').val());
321                     ajax.set("workOrderNo", $('#workOrderNo').val());
322                     ajax.set("state", "是");
323                     ajax.start();
324                     // initBomTable();
325                     initMaterialShortage();
326                 } else {
327                     layer.open({
328                         title: "操作提示",
329                         icon: 0,
330                         closeBtn: 2,
331                         area: ['450px', '160px'],
332                         time: 5000,
333                         content: '<span style="font-size: 30px;color: red">该标签已被扫描!!!</span>'
334                     });
335                 }
336             }else {
337                 layer.open({
338                     title: "操作提示",
339                     icon: 0,
340                     closeBtn: 2,
341                     area: ['450px', '160px'],
342                     time: 5000,
343                     content: '<span style="font-size: 30px;color: red">BOM校验错误请重新扫码!!!</span>'
344                 });
345             }
346     }
347
348     //连接成功建立的回调方法
349     websocket.onopen = function() {
350         Feng.info("扫码枪连接建立成功")
351         console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接成功")
352     }
353
354     //连接关闭的回调方法
355     websocket.onclose = function() {
356         Feng.info("扫码枪连接已关闭")
357         console.log("与weksoket地址"+'ws://'+ip+':8083/websocket/materialRegistration'+"连接失败不能发送消息")
358     }
359
360     window.onunload = function(){
361         websocket.close();
362     }
363
364
365 });