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