懒羊羊
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     var form = layui.form;
9
10
11     $(document).ready(function() {
12         console.log("111111111111111111111");
13         $.ajax({
14             type: "POST",
15             contentType: "application/json;charset=UTF-8",
16             url: Feng.ctxPath + '/lineInfo/list',
17             success: function (result) {
18                 $('#lineCode').empty();
19                 $('#lineCode').append(new Option("请选择产线", ""));// 下拉菜单里添加元素
20
21                 $.each(result.data, function (index, value) {
22                     $('#lineCode').append(new Option(value.lineCode, value.lineCode));// 下拉菜单里添加元素
23                 });
24                 layui.form.render("select");//重新渲染 固定写法
25             },
26         });
27     });
28
29     form.on("select", function (data) {
30         if (data.value !== "") {
31             if (data.elem.id === "lineCode") {
32                 $.ajax({
33                     type: "POST",
34                     contentType: "application/json;charset=UTF-8",
35                     url: Feng.ctxPath + '/locationInfo/list?productionLineCode='+ $('#lineCode').val(),
36                     success: function (result) {
37                         $('#locationCode').empty();
38                         $('#locationCode').append(new Option("请选择工位", ""));// 下拉菜单里添加元素
39
40                         $.each(result.data, function (index, value) {
41                             $('#locationCode').append(new Option(value.locationCode, value.locationCode));// 下拉菜单里添加元素
42                         });
43                         layui.form.render("select");//重新渲染 固定写法
44                     },
45                 });
46             }
47             if (data.elem.id === "locationCode") {
48                 $.ajax({
49                     type: "POST",
50                     contentType: "application/json;charset=UTF-8",
51                     url: Feng.ctxPath + '/badReasonConf/list?locationCode='+$("#locationCode").val(),
52                     success: function (result) {
53                         $('#typeCode').empty();
54                         $('#badCode').empty();
55                         $.each(result.data, function (index, value) {
56                             $('#typeCode').append(new Option(value.typeCode));// 下拉菜单里添加元素
57                         });
58                         $.each(result.data, function (index, value) {
59                             $('#badCode').append(new Option(value.badCode));// 下拉菜单里添加元素
60                         });
61                         layui.form.render("select");//重新渲染 固定写法
62                     },
63                 });
64             }
65         }
66     });
67
68     /**
69      * 看板配置管理
70      */
71     var KanbanConf = {
72         tableId: "kanbanConfTable"
73     };
74
75     /**
76      * bom信息管理
77      */
78     var BomInfo = {
79         tableId: "bomInfoTable"
80     };
81
82     /**
83      * bom信息管理
84      */
85     var MaterialShortage = {
86         tableId: "materialShortageTable"
87     };
88
89     initPageInfo();
90     async function initPageInfo() {
91         await initKanBanConfInfo();//初始化配置信息
92         await initOrderInfo();
93         initBomTable();
94         initMaterialShortage();
95     }
96
97     function initKanBanConfInfo() {
98         // 根据ip查询配置信息
99         var ajax = new $ax(Feng.ctxPath + "/badBoard/qryKBConflist?pageCode=" + 'KB_WLDJ_003');
100         var result = ajax.start();
101         if (result.data.length > 0) {
102             let msg = result.data[0];
103             $('#id').val(msg.id);
104             $('#ipAddress').val(msg.ipAddress);
105             $('#pageCode').val(msg.pageCode);
106             $('#workshopCode').val(msg.workshopCode);
107             $('#lineCode').val(msg.lineCode);
108             $('#locationCode').val(msg.locationCode);
109         }
110     }
111
112
113     function initOrderInfo() {
114         // 根据ip查询配置信息
115         var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/list?orderStatus=" + '3');
116         var result = ajax.start();
117         if (result.data.length > 0) {
118             let msg = result.data[0];
119             $('#orderId').val(msg.id);
120             $('#workOrderNo').val(msg.workOrderNo);
121             $('#materialCode').val(msg.materialCode);
122             $('#materialName').val(msg.materialName);
123             $('#planQty').val(msg.planQty);
124
125             $('#custom').val(msg.custom);
126             $('#createTime').val(msg.createTime);
127             $('#actualQty').val(msg.actualQty);
128             $('#planStartTime').val(msg.planStartTime);
129             $('#planEndTime').val(msg.planEndTime);
130         }
131     }
132     function initBomTable(){
133         var queryData = {};
134         queryData['locationCode'] = $("#locationCode").val();
135         queryData['workOrderNo'] = $("#workOrderNo").val();
136         // 渲染表格
137         var tableResult = table.render({
138             elem: '#' + BomInfo.tableId,
139             url: Feng.ctxPath + '/productionOrderRecords/list',
140             // page: true,
141             // height: 475,
142             height: 435,
143             cellMinWidth: 100,
144             where:queryData,
145             cols: BomInfo.initColumn()
146         });
147     }
148     /**
149      * 物料Bom初始化表格的列
150      */
151     BomInfo.initColumn = function () {
152         return [[
153             {field: 'id', hide: true, title: 'ID'},
154             {field: 'productNo', sort: true, title: '产品序列号'},
155             {field: 'workOrderNo', sort: true, title: '生产工单号'},
156             {field: 'materialCode', sort: true, title: '物料编号'},
157             {field: 'locationCode', sort: true, title: '工位编号'},
158             {field: 'productQty', sort: true, title: '报工时间'},
159             {
160                 field: 'print',
161                 title: '标签打印',
162                 align: 'center',
163                 toolbar:'#applyIDXZ'
164             }
165         ]];
166     };
167
168     /**
169      * 缺料报警初始化表格的列
170      */
171     MaterialShortage.initColumn = function () {
172         return [[
173             {type: 'checkbox'},
174             {field: 'id', hide: true, title: 'ID'},
175             {field: 'workOrderNo', sort: true, title: '工单号',width:150},
176             {field: 'sfcCode', sort: true, title: '总成序列号',width:150},
177             // {field: 'productCode', sort: true, title: '扫码编号'},
178             // {field: 'workshopCode', sort: true, title: '车间编码'},
179             {field: 'productionLine', sort: true, title: '产线编号'},
180             {field: 'locationCode', sort: true, title: '工位编号'},
181             {field: 'typeCode', sort: true, title: '不良类型编码'},
182             {field: 'badCode', sort: true, title: '不良原因编码'},
183         ]];
184     };
185
186     function initMaterialShortage(){
187         var queryData = {};
188         queryData['workOrderNo'] = $("#workOrderNo").val();
189         // 渲染表格
190         var tableResult = table.render({
191             elem: '#' + MaterialShortage.tableId,
192             url: Feng.ctxPath + '/badCollection/list',
193             page: true,
194             cellMinWidth: 80,
195             height: 350,
196             where:queryData,
197             cols: MaterialShortage.initColumn()
198         });
199     }
200
201     $('#enter').click(function (enterNum){
202         if($('#lineCode').val() === null){
203             Feng.error("请选择产线!")
204             return;
205         }
206         if($('#locationCode').val() === null){
207             Feng.error("请选择工位!")
208             return;
209         }
210         if($('#typeCode').val() === null){
211             Feng.error("请选择不良类型!")
212             return;
213         }
214         if($('#badCode').val() === null){
215             Feng.error("请选择不良原因!")
216             return;
217         }
218         if($('#scrapNumber').val() < 1){
219             Feng.error("请输扫码!")
220             return;
221         }
222         var obj = {
223             'workOrderNo': $("#workOrderNo").val(),
224             'badCode': $("#badCode").val(),
225             'typeCode': $("#typeCode").val(),
226             'locationCode': $("#locationCode").val(),
227             'productionLine': $("#lineCode").val(),
228             'sfcCode': $("#scanCode").val(),
229         };
230         var ajax = new $ax(Feng.ctxPath + "/badCollection/addItem", function (data) {
231             Feng.success("录入成功!");
232         }, function (data) {
233             Feng.error("添加失败!" + data.responseJSON.message)
234         });
235         ajax.set(obj);
236         ajax.start();
237         initMaterialShortage();
238         $("#scanCode").val().empty();
239     });
240
241     // 生产工单设置按钮点击事件
242     $('#orderBtnSet').click(function () {
243         KanbanConf.openOrderEditPage();
244     });
245
246     $('#revert').click(function () {
247         window.location.href = Feng.ctxPath + '/badBoard/boardHome'
248     });
249
250     // 设置按钮点击事件
251     $('#btnSet').click(function () {
252         var id = $("#id").val();
253         if(id == "" || id == undefined){
254             KanbanConf.openAddDlg();
255         }else{
256             KanbanConf.openEditPage(id);
257         }
258
259     });
260
261     /**
262      * 弹出添加页面设置对话框
263      */
264     KanbanConf.openAddDlg = function () {
265         console.log("111111111");
266         layer.open({
267             type: 2,
268             area: ['1000px', '600px'],
269             title: '添加看板配置',
270             content: Feng.ctxPath + '/badBoard/add',
271             success: function (layero, index) {
272                 let body = layer.getChildFrame('body', index);
273                 body.find('form').find('#testlineCode').val($('#lineCode').val());
274                 body.find('form').find('#testlocationCode').val($('#locationCode').val());
275             },
276             end: function () {
277                 console.log("end")
278                 let lineCode = JSON.parse(window.localStorage.getItem('lineCode'));
279                 let locationCode = JSON.parse(window.localStorage.getItem('locationCode'));
280                 $('#lineCode').val(lineCode);
281                 $('#locationCode').val(locationCode);
282                 initKanBanConfInfo();
283                 getBadList();
284
285             }
286         });
287     };
288
289     /**
290      * 弹出编辑页面设置对话框
291      *
292      * @param data 点击按钮时候的行数据
293      */
294     KanbanConf.openEditPage = function (data) {
295         func.open({
296             title: '添加看板配置',
297             content: Feng.ctxPath + '/badBoard/edit?id=' + data,
298             //tableId: KanbanConf.tableId
299         });
300
301     };
302
303
304
305     KanbanConf.openOrderEditPage = function (data) {
306         layer.open({
307             type: 2,
308             area: ['1000px', '600px'],
309             title: '工单配置',
310             content: Feng.ctxPath + '/badBoard/orderEdit',
311             success: function () {
312                 console.log($('#lineCode').val());
313                 window.lineCode = $('#lineCode').val();
314             },
315             end: function () {
316                 let msg = JSON.parse(window.localStorage.getItem('message'));
317                 console.log("选择工单_id", msg.id)
318                 $('#orderId').val(msg.id);
319                 $('#workOrderNo').val(msg.workOrderNo);
320                 $('#materialCode').val(msg.materialCode);
321                 $('#materialName').val(msg.materialName);
322                 $('#planQty').val(msg.planQty);
323                 $('#createTime').val(msg.createTime);
324                 $('#actualQty').val(msg.actualQty);
325                 initMaterialShortage();
326             }
327         });
328     };
329
330     $("#badBtnSet").click(function (){
331         if($('#typeCode').val() === null){
332             Feng.error("请选择不良类型!")
333             return;
334         }
335         if($('#badCode').val() === null){
336             Feng.error("请选择不良原因!")
337             return;
338         }
339         console.log($("#workOrderNo").val());
340         console.log($("#badCode").val());
341         console.log($("#typeCode").val());
342         console.log($("#locationCode").val());
343         var obj = {
344             'workOrderNo': $("#workOrderNo").val(),
345             'badCode': $("#badCode").val(),
346             'typeCode': $("#typeCode").val(),
347             'locationCode': $("#locationCode").val(),
348         };
349         var ajax = new $ax(Feng.ctxPath + "/badCollection/addItem", function (data) {
350             Feng.success("录入成功!");
351         }, function (data) {
352             Feng.error("添加失败!" + data.responseJSON.message)
353         });
354         ajax.set(obj);
355         ajax.start();
356         initMaterialShortage();
357     });
358
359     function print(data){
360         layer.msg("打印"+JSON.stringify(data));
361     }
362
363     setInterval(function(){
364         console.log("1111111");
365         initBomTable();
366     }, 10000);
367
368     table.on('tool(bomInfoTable)', function(obj) {
369         var data = obj.data;
370         if (obj.event === 'applyIDXZInfo'){
371             print(data);
372         }
373     });
374
375 });