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