layui.use(['form', 'table', 'admin', 'ax', 'func'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; var form = layui.form; $(document).ready(function() { console.log("111111111111111111111"); $.ajax({ type: "POST", contentType: "application/json;charset=UTF-8", url: Feng.ctxPath + '/lineInfo/list', success: function (result) { $('#lineCode').empty(); $('#lineCode').append(new Option("请选择产线", ""));// 下拉菜单里添加元素 $.each(result.data, function (index, value) { $('#lineCode').append(new Option(value.lineCode, value.lineCode));// 下拉菜单里添加元素 }); layui.form.render("select");//重新渲染 固定写法 }, }); }); form.on("select", function (data) { if (data.value !== "") { if (data.elem.id === "lineCode") { $.ajax({ type: "POST", contentType: "application/json;charset=UTF-8", url: Feng.ctxPath + '/locationInfo/list?productionLineCode='+ $('#lineCode').val(), success: function (result) { $('#locationCode').empty(); $('#locationCode').append(new Option("请选择工位", ""));// 下拉菜单里添加元素 $.each(result.data, function (index, value) { $('#locationCode').append(new Option(value.locationCode, value.locationCode));// 下拉菜单里添加元素 }); layui.form.render("select");//重新渲染 固定写法 }, }); } if (data.elem.id === "locationCode") { $.ajax({ type: "POST", contentType: "application/json;charset=UTF-8", url: Feng.ctxPath + '/badReasonConf/list?locationCode='+$("#locationCode").val(), success: function (result) { $('#typeCode').empty(); $('#badCode').empty(); $.each(result.data, function (index, value) { $('#typeCode').append(new Option(value.typeCode));// 下拉菜单里添加元素 }); $.each(result.data, function (index, value) { $('#badCode').append(new Option(value.badCode));// 下拉菜单里添加元素 }); layui.form.render("select");//重新渲染 固定写法 }, }); } } }); /** * 看板配置管理 */ var KanbanConf = { tableId: "kanbanConfTable" }; /** * bom信息管理 */ var BomInfo = { tableId: "bomInfoTable" }; /** * bom信息管理 */ var MaterialShortage = { tableId: "materialShortageTable" }; initPageInfo(); async function initPageInfo() { await initKanBanConfInfo();//初始化配置信息 await initOrderInfo(); initBomTable(); initMaterialShortage(); } function initKanBanConfInfo() { // 根据ip查询配置信息 var ajax = new $ax(Feng.ctxPath + "/badBoard/qryKBConflist?pageCode=" + 'KB_WLDJ_003'); var result = ajax.start(); if (result.data.length > 0) { let msg = result.data[0]; $('#id').val(msg.id); $('#ipAddress').val(msg.ipAddress); $('#pageCode').val(msg.pageCode); $('#workshopCode').val(msg.workshopCode); $('#lineCode').val(msg.lineCode); $('#locationCode').val(msg.locationCode); } } function initOrderInfo() { // 根据ip查询配置信息 var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/list?orderStatus=" + '3'); var result = ajax.start(); if (result.data.length > 0) { let msg = result.data[0]; $('#orderId').val(msg.id); $('#workOrderNo').val(msg.workOrderNo); $('#materialCode').val(msg.materialCode); $('#materialName').val(msg.materialName); $('#planQty').val(msg.planQty); $('#custom').val(msg.custom); $('#createTime').val(msg.createTime); $('#actualQty').val(msg.actualQty); $('#planStartTime').val(msg.planStartTime); $('#planEndTime').val(msg.planEndTime); } } function initBomTable(){ var queryData = {}; queryData['locationCode'] = $("#locationCode").val(); queryData['workOrderNo'] = $("#workOrderNo").val(); // 渲染表格 var tableResult = table.render({ elem: '#' + BomInfo.tableId, url: Feng.ctxPath + '/productionOrderRecords/list', // page: true, // height: 475, height: 435, cellMinWidth: 100, where:queryData, cols: BomInfo.initColumn() }); } /** * 物料Bom初始化表格的列 */ BomInfo.initColumn = function () { return [[ {field: 'id', hide: true, title: 'ID'}, {field: 'productNo', sort: true, title: '产品序列号'}, {field: 'workOrderNo', sort: true, title: '生产工单号'}, {field: 'materialCode', sort: true, title: '物料编号'}, {field: 'locationCode', sort: true, title: '工位编号'}, {field: 'productQty', sort: true, title: '报工时间'}, { field: 'print', title: '标签打印', align: 'center', toolbar:'#applyIDXZ' } ]]; }; /** * 缺料报警初始化表格的列 */ MaterialShortage.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: 'ID'}, {field: 'workOrderNo', sort: true, title: '工单号',width:150}, {field: 'sfcCode', sort: true, title: '总成序列号',width:150}, // {field: 'productCode', sort: true, title: '扫码编号'}, // {field: 'workshopCode', sort: true, title: '车间编码'}, {field: 'productionLine', sort: true, title: '产线编号'}, {field: 'locationCode', sort: true, title: '工位编号'}, {field: 'typeCode', sort: true, title: '不良类型编码'}, {field: 'badCode', sort: true, title: '不良原因编码'}, ]]; }; function initMaterialShortage(){ var queryData = {}; queryData['workOrderNo'] = $("#workOrderNo").val(); // 渲染表格 var tableResult = table.render({ elem: '#' + MaterialShortage.tableId, url: Feng.ctxPath + '/badCollection/list', page: true, cellMinWidth: 80, height: 350, where:queryData, cols: MaterialShortage.initColumn() }); } $('#enter').click(function (enterNum){ if($('#lineCode').val() === null){ Feng.error("请选择产线!") return; } if($('#locationCode').val() === null){ Feng.error("请选择工位!") return; } if($('#typeCode').val() === null){ Feng.error("请选择不良类型!") return; } if($('#badCode').val() === null){ Feng.error("请选择不良原因!") return; } if($('#scrapNumber').val() < 1){ Feng.error("请输扫码!") return; } var obj = { 'workOrderNo': $("#workOrderNo").val(), 'badCode': $("#badCode").val(), 'typeCode': $("#typeCode").val(), 'locationCode': $("#locationCode").val(), 'productionLine': $("#lineCode").val(), 'sfcCode': $("#scanCode").val(), }; var ajax = new $ax(Feng.ctxPath + "/badCollection/addItem", function (data) { Feng.success("录入成功!"); }, function (data) { Feng.error("添加失败!" + data.responseJSON.message) }); ajax.set(obj); ajax.start(); initMaterialShortage(); $("#scanCode").val().empty(); }); // 生产工单设置按钮点击事件 $('#orderBtnSet').click(function () { KanbanConf.openOrderEditPage(); }); $('#revert').click(function () { window.location.href = Feng.ctxPath + '/badBoard/boardHome' }); // 设置按钮点击事件 $('#btnSet').click(function () { var id = $("#id").val(); if(id == "" || id == undefined){ KanbanConf.openAddDlg(); }else{ KanbanConf.openEditPage(id); } }); /** * 弹出添加页面设置对话框 */ KanbanConf.openAddDlg = function () { console.log("111111111"); layer.open({ type: 2, area: ['1000px', '600px'], title: '添加看板配置', content: Feng.ctxPath + '/badBoard/add', success: function (layero, index) { let body = layer.getChildFrame('body', index); body.find('form').find('#testlineCode').val($('#lineCode').val()); body.find('form').find('#testlocationCode').val($('#locationCode').val()); }, end: function () { console.log("end") let lineCode = JSON.parse(window.localStorage.getItem('lineCode')); let locationCode = JSON.parse(window.localStorage.getItem('locationCode')); $('#lineCode').val(lineCode); $('#locationCode').val(locationCode); initKanBanConfInfo(); getBadList(); } }); }; /** * 弹出编辑页面设置对话框 * * @param data 点击按钮时候的行数据 */ KanbanConf.openEditPage = function (data) { func.open({ title: '添加看板配置', content: Feng.ctxPath + '/badBoard/edit?id=' + data, //tableId: KanbanConf.tableId }); }; KanbanConf.openOrderEditPage = function (data) { layer.open({ type: 2, area: ['1000px', '600px'], title: '工单配置', content: Feng.ctxPath + '/badBoard/orderEdit', success: function () { console.log($('#lineCode').val()); window.lineCode = $('#lineCode').val(); }, end: function () { let msg = JSON.parse(window.localStorage.getItem('message')); console.log("选择工单_id", msg.id) $('#orderId').val(msg.id); $('#workOrderNo').val(msg.workOrderNo); $('#materialCode').val(msg.materialCode); $('#materialName').val(msg.materialName); $('#planQty').val(msg.planQty); $('#createTime').val(msg.createTime); $('#actualQty').val(msg.actualQty); initMaterialShortage(); } }); }; $("#badBtnSet").click(function (){ if($('#typeCode').val() === null){ Feng.error("请选择不良类型!") return; } if($('#badCode').val() === null){ Feng.error("请选择不良原因!") return; } console.log($("#workOrderNo").val()); console.log($("#badCode").val()); console.log($("#typeCode").val()); console.log($("#locationCode").val()); var obj = { 'workOrderNo': $("#workOrderNo").val(), 'badCode': $("#badCode").val(), 'typeCode': $("#typeCode").val(), 'locationCode': $("#locationCode").val(), }; var ajax = new $ax(Feng.ctxPath + "/badCollection/addItem", function (data) { Feng.success("录入成功!"); }, function (data) { Feng.error("添加失败!" + data.responseJSON.message) }); ajax.set(obj); ajax.start(); initMaterialShortage(); }); function print(data){ layer.msg("打印"+JSON.stringify(data)); } setInterval(function(){ console.log("1111111"); initBomTable(); }, 10000); table.on('tool(bomInfoTable)', function(obj) { var data = obj.data; if (obj.event === 'applyIDXZInfo'){ print(data); } }); });