cl
2024-01-23 6dadf36ef118fbb3b2cd5aca94cde88e29fb55dc
提交 | 用户 | 时间
71e81e 1
2 layui.use(['form','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     var form = layui.form;
9
10
11     /**
12      * 看板配置管理
13      */
14     var KanbanConf = {
15         tableId: "kanbanConfTable"
16     };
17
18     /**
19      * bom信息管理
20      */
21     var BomInfo = {
22         tableId: "bomInfoTable"
23     };
24
25     /**
26      * bom信息管理
27      */
28     var MaterialShortage = {
29         tableId: "materialShortageTable"
30     };
31
32     $(document).ready(function() {
33         // $.ajax({
34         //     type: "POST",
35         //     contentType: "application/json;charset=UTF-8",
36         //     url: Feng.ctxPath + '/lineInfo/list',
37         //     success: function (result) {
38         //         $('#productionLine').empty();
39         //         $('#productionLine').append(new Option("请选择产线", ""));// 下拉菜单里添加元素
40         //
41         //         $.each(result.data, function (index, value) {
42         //             $('#productionLine').append(new Option(value.lineCode, value.lineCode));// 下拉菜单里添加元素
43         //         });
44         //         layui.form.render("select");//重新渲染 固定写法
45         //     },
46         // });
47     });
48
49     // form.on("select", function (data) {
50     //     if (data.value !== "") {
51     //         if (data.elem.id === "productionLine") {
52     //             $("#sfc").val("");
53     //             if($('#productionLine').val() === "BOP"||$('#productionLine').val() === "COP"){
54     //                 console.log("选择了BOP或者COP");
55     //                 $("#sfc").attr("readonly","readonly");
56     //             }else {
57     //                 $("#sfc").removeAttr("readonly");
58     //                 Feng.success("请扫描总成编码!")
59     //             }
60     //             $.ajax({
61     //                 type: "POST",
62     //                 contentType: "application/json;charset=UTF-8",
63     //                 url: Feng.ctxPath + '/locationInfo/list?productionLineCode='+ $('#productionLine').val(),
64     //                 success: function (result) {
65     //                     $('#locationCode').empty();
66     //                     $('#locationCode').append(new Option("请选择工位", ""));// 下拉菜单里添加元素
67     //
68     //                     $.each(result.data, function (index, value) {
69     //                         $('#locationCode').append(new Option(value.locationCode, value.locationCode));// 下拉菜单里添加元素
70     //                     });
71     //                     layui.form.render("select");//重新渲染 固定写法
72     //                 },
73     //             });
74     //         }
75     //     }
76     // });
77
78     initPageInfo();
79     async function initPageInfo() {
80         await initKanBanConfInfo();//初始化配置信息
81         await initPoorLine();
82         await initOrderInfo();
83         initBomTable();
84         initMaterialShortage();
85      /*   xR();
86         xa();*/
87     }
88
89     function initPoorLine(){
90         $.ajax({
91             type: "POST",
92             contentType: "application/json;charset=UTF-8",
93             url: Feng.ctxPath + '/locationInfo/list?productionLineCode='+ $('#lineCode').val(),
94             success: function (result) {
95                 $('#poorLocationCode').empty();
96                 $('#poorLocationCode').append(new Option("请选择工位", ""));// 下拉菜单里添加元素
97
98                 $.each(result.data, function (index, value) {
99                     $('#poorLocationCode').append(new Option(value.locationCode, value.locationCode));// 下拉菜单里添加元素
100                 });
101                 layui.form.render("select");//重新渲染 固定写法
102             },
103         });
104     }
105
106     function initKanBanConfInfo() {
107         // 根据ip查询配置信息
108         var ajax = new $ax(Feng.ctxPath + "/scrapBoard/qryKBConflist?pageCode=" + 'KB_WLDJ_005');
109         var result = ajax.start();
110         if (result.data.length > 0) {
111             let msg = result.data[0];
112             $('#id').val(msg.id);
113             $('#ipAddress').val(msg.ipAddress);
114             $('#pageCode').val(msg.pageCode);
115             $('#workshopCode').val(msg.workshopCode);
116             $('#lineCode').val(msg.lineCode);
117             $('#locationCode').val(msg.locationCode);
118
119             $('#scrapCategory').val(msg.warehouseCode);
120             $('#scrapReason').val(msg.warehouseName);
121             console.log(msg)
122
123         }
124     }
125
126     function initOrderInfo() {
127         // 根据ip查询配置信息
128         var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/list?orderStatus=" + '3');
129         var result = ajax.start();
130         if (result.data.length > 0) {
131             let msg = result.data[0];
132             $('#orderId').val(msg.id);
133             $('#workOrderNo').val(msg.workOrderNo);
134             $('#materialCode').val(msg.materialCode);
135             $('#materialName').val(msg.materialName);
136             $('#planQty').val(msg.planQty);
137
138             $('#custom').val(msg.custom);
139             $('#createTime').val(msg.createTime);
140             $('#actualQty').val(msg.actualQty);
141             $('#planStartTime').val(msg.planStartTime);
142             $('#planEndTime').val(msg.planEndTime);
143         }
144     }
145
146     function initBomTable(){
147         var queryData = {};
148         queryData['loadingCode'] = $("#locationCode").val();
149         // queryData['workOrderNo'] = $("#workOrderNo").val();
150
151         // 渲染表格
152         var tableResult = table.render({
153             elem: '#' + BomInfo.tableId,
154             url: Feng.ctxPath + '/bomInfo/kbListTable',
155             // page: true,
156             // height: 475,
157             height:320,
158             cellMinWidth: 100,
159             where:queryData,
160             cols: BomInfo.initColumn()
161         });
162     }
163     /**
164      * 物料Bom初始化表格的列
165      */
166     BomInfo.initColumn = function () {
167         return [[
168             // {type: 'checkbox'},
169             /*  {type:"numbers" ,title:'序号',width:40,fixed:'left'},*/
170             {field: 'id', hide: true, title: 'ID'},
171             {field: 'materialCode', sort: true, title: '物料编号'},
172             {field: 'materialName', sort: true, title: '物料名称'},
173             // {field: 'workorderNo', sort: true, title: '工单编号'},
174             // {field: 'productCode', sort: true, title: '产品编号'},
175             {field: 'locationCode', sort: true, title: '工位编号'},
176             {field: 'loadingCode', sort: true, title: '上料工位编号'},
177             // {field: 'state', sort: true, title: '是否扫码'},
178             // {field: 'batchCode', sort: true, title: '批次码'},
179         ]];
180     };
181
182     /**
183      * 缺料报警初始化表格的列
184      */
185     MaterialShortage.initColumn = function () {
186         return [[
187             {field: 'id', hide: true, title: 'id'},
188             {field: 'sfc', sort: true, title: '总成编码',width:200},
189             {field: 'productionLine', sort: true, title: '产线编号',width:110},
190             {field: 'locationCode', sort: true, title: '工位编号',width:110},
191             {field: 'poorLocationCode', sort: true, title: '不良工位',width:110},
192             {field: 'poorContent', sort: true, title: '不良内容',width:110},
193             {field: 'workOrderNo', sort: true, title: '工单编号',width:160},
194             {field: 'productCode', sort: true, title: '产品编号',width:150},
195             {field: 'productName', sort: true, title: '产品名称',width:270},
196             // {field: 'manageType', sort: true, title: '类型',width:120},
197             {field: 'operateTime', sort: true, title: '操作时间',width:170},
198             {field: 'operateUser', sort: true, title: '操作人',width:100},
199         ]];
200     };
201
202     function initMaterialShortage(){
203         var queryData = {};
204         queryData['manageType'] = "1";
205         // 渲染表格
206         var tableResult = table.render({
207             elem: '#' + MaterialShortage.tableId,
208             url: Feng.ctxPath + '/repairManageInfo/list',
209             // page: true,
210             height: 360,
211             cellMinWidth: 80,
212             where:queryData,
213             cols: MaterialShortage.initColumn()
214         });
215     }
216
217
218     // 生产工单设置按钮点击事件
219     $('#orderBtnSet').click(function () {
220         KanbanConf.openOrderEditPage();
221     });
222
223     KanbanConf.openOrderEditPage = function (data) {
224         layer.open({
225             type: 2,
226             area: ['1000px', '600px'],
227             title: '工单配置',
228             content: Feng.ctxPath + '/badBoard/orderEdit',
229             success: function () {
230                 console.log($('#lineCode').val());
231                 window.lineCode = $('#lineCode').val();
232             },
233             end: function () {
234                 let msg = JSON.parse(window.localStorage.getItem('message'));
235                 console.log("选择工单_id", msg.id)
236                 $('#orderId').val(msg.id);
237                 $('#workOrderNo').val(msg.workOrderNo);
238                 $('#materialCode').val(msg.materialCode);
239                 $('#materialName').val(msg.materialName);
240                 $('#planQty').val(msg.planQty);
241                 $('#createTime').val(msg.createTime);
242                 $('#actualQty').val(msg.actualQty);
243                 initMaterialShortage();
244             }
245         });
246     };
247
248     // 设置按钮点击事件
249     $('#btnSet').click(function () {
250         var id = $("#id").val();
251         if(id == "" || id == undefined){
252             KanbanConf.openAddDlg();
253         }else{
254             KanbanConf.openEditPage(id);
255         }
256
257     });
258
259     $('#enter').click(function (){
260         if($('#lineCode').val().length===0||$('#locationCode').val().length===0){
261             Feng.error("请设置产线工位!")
262             return;
263         }
264         if($('#poorLocationCode').val().length===0){
265             Feng.error("请选择不良工位!")
266             return;
267         }
268         if($('#lineCode').val() === "OP"||$('#lineCode').val() === "EOP"){
269             if($('#sfc').val().length===0){
270                 Feng.error("请输入总成编码!")
271                 return;
272             }
273         }
274         let ajaxEnter = new $ax(Feng.ctxPath + "/repairManageInfo/addItem", function (data) {
275             Feng.success("添加成功!")
276         }, function (data) {
277             Feng.error("添加失败!" + data.responseJSON.message)
278         });
279         ajaxEnter.set("productionLine", $('#lineCode').val());
280         ajaxEnter.set("locationCode", $('#locationCode').val());
281         ajaxEnter.set("poorLocationCode", $('#poorLocationCode').val());
282         ajaxEnter.set("poorContent", $('#poorContent').val());
283         ajaxEnter.set("sfc", $('#sfc').val());
284         ajaxEnter.set("productCode", $('#materialCode').val());
285         ajaxEnter.set("productName", $('#materialName').val());
286         ajaxEnter.set("workOrderNo", $('#workOrderNo').val());
287         ajaxEnter.set("manageType", "1");
288         ajaxEnter.start();
289         initMaterialShortage();
290     });
291
292     /**
293      * 弹出添加页面设置对话框
294      */
295     KanbanConf.openAddDlg = function () {
296         console.log("弹出添加页面设置对话框");
297         layer.open({
298             type: 2,
299             area: ['1000px', '600px'],
300             title: '添加看板配置',
301             content: Feng.ctxPath + '/reworkOffline/add',
302             success: function (layero, index) {
303                 let body = layer.getChildFrame('body', index);
304                 body.find('form').find('#testlineCode').val($('#lineCode').val());
305                 body.find('form').find('#testlocationCode').val($('#locationCode').val());
306             },
307             end: function () {
308                 console.log("end")
309                 let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
310                 let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
311                 $('#lineCode').val(lineCode);
312                 $('#locationCode').val(locationCode);
313                 initKanBanConfInfo()
314             }
315         });
316     };
317
318     /**
319      * 弹出编辑页面设置对话框
320      *
321      * @param data 点击按钮时候的行数据
322      */
323     KanbanConf.openEditPage = function (data) {
324         func.open({
325             title: '添加看板配置',
326             content: Feng.ctxPath + '/materialRegistration/edit?id=' + data,
327             //tableId: KanbanConf.tableId
328         });
329
330     };
331
332     $('#revert').click(function () {
333         window.location.href = Feng.ctxPath + '/badBoard/boardHome'
334     });
335
336     var websocket = null;
337     //判断当前浏览器是否支持WebSocket
338     if('WebSocket' in window) {
339         //改成你的地址
340         websocket = new WebSocket('ws://127.0.0.1:8083/websocket/reworkOffline');
341     } else {
342         alert('当前浏览器 Not support websocket')
343     }
344     //接收到消息的回调方法
345     websocket.onmessage = function(event) {
346         $('#sfc').val(event.data);
347     }
348
349     //连接成功建立的回调方法
350     websocket.onopen = function() {
351         Feng.info("扫码枪连接建立成功")
352     }
353
354     //连接关闭的回调方法
355     websocket.onclose = function() {
356         Feng.info("扫码枪连接已关闭")
357     }
358
359     window.onunload = function(){
360         websocket.close();
361     }
362 });