懒羊羊
2024-01-10 a556270e96bc6e7fa4202c466d57cc75f778c614
提交 | 用户 | 时间
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
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 initPoorLine();
34         await initOrderInfo();
35         initBomTable();
36         initMaterialShortage();
37      /*   xR();
38         xa();*/
39     }
40
41     function initPoorLine(){
42         $.ajax({
43             type: "POST",
44             contentType: "application/json;charset=UTF-8",
45             url: Feng.ctxPath + '/locationInfo/list?productionLineCode='+ $('#lineCode').val(),
46             success: function (result) {
47                 $('#poorLocationCode').empty();
48                 $('#poorLocationCode').append(new Option("请选择工位", ""));// 下拉菜单里添加元素
49
50                 $.each(result.data, function (index, value) {
51                     $('#poorLocationCode').append(new Option(value.locationCode, value.locationCode));// 下拉菜单里添加元素
52                 });
53                 layui.form.render("select");//重新渲染 固定写法
54             },
55         });
56     }
57
58     function initKanBanConfInfo() {
59         // 根据ip查询配置信息
60         var ajax = new $ax(Feng.ctxPath + "/scrapBoard/qryKBConflist?pageCode=" + 'KB_WLDJ_006');
61         var result = ajax.start();
62         if (result.data.length > 0) {
63             let msg = result.data[0];
64             $('#id').val(msg.id);
65             $('#ipAddress').val(msg.ipAddress);
66             $('#pageCode').val(msg.pageCode);
67             $('#workshopCode').val(msg.workshopCode);
68             $('#lineCode').val(msg.lineCode);
69             $('#locationCode').val(msg.locationCode);
70
71             $('#scrapCategory').val(msg.warehouseCode);
72             $('#scrapReason').val(msg.warehouseName);
73             console.log(msg)
74
75         }
76     }
77
78     function initOrderInfo(sfc) {
79         // 根据ip查询配置信息
80         var ajax = new $ax(Feng.ctxPath + "/repairManageInfo/list?sfc=" + sfc);
81         // var ajax = new $ax(Feng.ctxPath + "/repairManageInfo/list?sfc=222222222");
82         var result = ajax.start();
83         if (result.data.length > 0) {
84             let msg = result.data[0];
85             $('#orderId').val(msg.id);
86             $('#workOrderNo').val(msg.workOrderNo);
87             $('#productName').val(msg.productName);
88             $('#productCode').val(msg.productCode);
89             $('#sfc1').val(msg.sfc);
90             $('#locationCode1').val(msg.locationCode);
91             $('#productionLine1').val(msg.productionLine);
92             $('#poorLocationCode1').val(msg.poorLocationCode);
93             $('#poorContent1').val(msg.poorContent);
94
95         }
96     }
97
98     function initBomTable(){
99         var queryData = {};
100         queryData['loadingCode'] = $("#locationCode").val();
101         // queryData['workOrderNo'] = $("#workOrderNo").val();
102
103         // 渲染表格
104         var tableResult = table.render({
105             elem: '#' + BomInfo.tableId,
106             url: Feng.ctxPath + '/bomInfo/kbListTable',
107             // page: true,
108             // height: 475,
109             height: 435,
110             cellMinWidth: 100,
111             where:queryData,
112             cols: BomInfo.initColumn()
113         });
114     }
115     /**
116      * 物料Bom初始化表格的列
117      */
118     BomInfo.initColumn = function () {
119         return [[
120             // {type: 'checkbox'},
121             /*  {type:"numbers" ,title:'序号',width:40,fixed:'left'},*/
122             {field: 'id', hide: true, title: 'ID'},
123             {field: 'materialCode', sort: true, title: '物料编号'},
124             {field: 'materialName', sort: true, title: '物料名称'},
125             // {field: 'workorderNo', sort: true, title: '工单编号'},
126             // {field: 'productCode', sort: true, title: '产品编号'},
127             {field: 'locationCode', sort: true, title: '工位编号'},
128             {field: 'loadingCode', sort: true, title: '上料工位编号'},
129             // {field: 'state', sort: true, title: '是否扫码'},
130             // {field: 'batchCode', sort: true, title: '批次码'},
131         ]];
132     };
133
134     /**
135      * 缺料报警初始化表格的列
136      */
137     MaterialShortage.initColumn = function () {
138         return [[
139             {field: 'id', hide: true, title: 'id'},
140             {field: 'sfc', sort: true, title: '总成编码',width:200},
141             {field: 'productionLine', sort: true, title: '产线编号',width:110},
142             {field: 'locationCode', sort: true, title: '工位编号',width:110},
143             {field: 'poorLocationCode', sort: true, title: '不良工位',width:110},
144             {field: 'poorContent', sort: true, title: '不良内容',width:110},
145             {field: 'workOrderNo', sort: true, title: '工单编号',width:160},
146             {field: 'productCode', sort: true, title: '产品编号',width:150},
147             {field: 'productName', sort: true, title: '产品名称',width:270},
148             // {field: 'manageType', sort: true, title: '类型',width:120},
149             {field: 'operateTime', sort: true, title: '操作时间',width:170},
150             {field: 'operateUser', sort: true, title: '操作人',width:100},
151         ]];
152     };
153
154     function initMaterialShortage(){
155         var queryData = {};
156         queryData['manageType'] = "2";
157
158         // 渲染表格
159         var tableResult = table.render({
160             elem: '#' + MaterialShortage.tableId,
161             url: Feng.ctxPath + '/repairManageInfo/list',
162             // page: true,
163             height: 360,
164             cellMinWidth: 80,
165             where:queryData,
166             cols: MaterialShortage.initColumn()
167         });
168     }
169
170
171     // 生产工单设置按钮点击事件
172     $('#orderBtnSet').click(function () {
173         KanbanConf.openOrderEditPage();
174     });
175
176     // 设置按钮点击事件
177     $('#btnSet').click(function () {
178         var id = $("#id").val();
179         if(id == "" || id == undefined){
180             KanbanConf.openAddDlg();
181         }else{
182             KanbanConf.openEditPage(id);
183         }
184
185     });
186
187     $('#enter').click(function (){
188         if($('#lineCode').val().length===0||$('#locationCode').val().length===0){
189             Feng.error("请设置产线工位!")
190             return;
191         }
192         if($('#poorLocationCode').val().length===0){
193             Feng.error("请选择不良工位!")
194             return;
195         }
196         if($('#lineCode').val() === "OP"||$('#lineCode').val() === "EOP"){
197             if($('#sfc').val().length===0){
198                 Feng.error("请输入总成编码!")
199                 return;
200             }
201         }
202         let ajaxEnter = new $ax(Feng.ctxPath + "/repairManageInfo/editGoLive", function (data) {
203             Feng.success("添加成功!")
204         }, function (data) {
205             Feng.error("添加失败!" + data.responseJSON.message)
206         });
207         ajaxEnter.set("productionLine", $('#lineCode').val());
208         ajaxEnter.set("locationCode", $('#locationCode').val());
209         ajaxEnter.set("poorLocationCode", $('#poorLocationCode').val());
210         ajaxEnter.set("sfc", $('#sfc').val());
211         ajaxEnter.set("manageType", "2");
212         ajaxEnter.start();
213         initMaterialShortage();
214         initOrderInfo($('#sfc').val());
215     });
216
217     /**
218      * 弹出添加页面设置对话框
219      */
220     KanbanConf.openAddDlg = function () {
221         console.log("弹出添加页面设置对话框");
222         layer.open({
223             type: 2,
224             area: ['1000px', '600px'],
225             title: '添加看板配置',
226             content: Feng.ctxPath + '/reworkAndLaunch/add',
227             success: function (layero, index) {
228                 let body = layer.getChildFrame('body', index);
229                 body.find('form').find('#testlineCode').val($('#lineCode').val());
230                 body.find('form').find('#testlocationCode').val($('#locationCode').val());
231             },
232             end: function () {
233                 console.log("end")
234                 let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
235                 let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
236                 $('#lineCode').val(lineCode);
237                 $('#locationCode').val(locationCode);
238                 initKanBanConfInfo()
239             }
240         });
241     };
242
243     /**
244      * 弹出编辑页面设置对话框
245      *
246      * @param data 点击按钮时候的行数据
247      */
248     KanbanConf.openEditPage = function (data) {
249         func.open({
250             title: '添加看板配置',
251             content: Feng.ctxPath + '/materialRegistration/edit?id=' + data,
252             //tableId: KanbanConf.tableId
253         });
254
255     };
256
257     $('#revert').click(function () {
258         window.location.href = Feng.ctxPath + '/badBoard/boardHome'
259     });
260
261     var websocket = null;
262     //判断当前浏览器是否支持WebSocket
263     if('WebSocket' in window) {
264         //改成你的地址
265         websocket = new WebSocket('ws://127.0.0.1:8083/websocket/reworkAndLaunch');
266     } else {
267         alert('当前浏览器 Not support websocket')
268     }
269     //接收到消息的回调方法
270     websocket.onmessage = function(event) {
271         $('#sfc').val(event.data);
272         initOrderInfo(event.data);
273
274     }
275
276     //连接成功建立的回调方法
277     websocket.onopen = function() {
278         Feng.info("扫码枪连接建立成功")
279     }
280
281     //连接关闭的回调方法
282     websocket.onclose = function() {
283         Feng.info("扫码枪连接已关闭")
284     }
285
286     window.onunload = function(){
287         websocket.close();
288     }
289
290 });