layui.use(['table', 'admin', 'ax','laydate', 'func', 'form', 'element','upload'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; var element = layui.element; var laydate = layui.laydate; var form = layui.form; var upload = layui.upload; /** * 生产工单管理 */ var ProductionOrdeInfo = { tableId: "productionOrdeInfoTable" }; //下载excel导入模板 $("#btnDownloadExc").click(function () { window.location.href = Feng.ctxPath + "/productionOrdeInfo/downloadExcelTemplate" }); //执行实例,导入excel var uploadInst = upload.render({ elem: '#btnUploadExc' , url: '/productionOrdeInfo/uploadExcel' ,accept: 'file' , done: function (res) { Feng.success("导入成功!"); table.reload(ProductionOrdeInfo.tableId, {url: Feng.ctxPath + "/productionOrdeInfo/list"}); } , error: function () { //请求异常回调 Feng.success("导入失败!"); } }); /** * 初始化表格的列 */ ProductionOrdeInfo.initColumn = function () { return [[ {type: 'radio'}, {align: 'center', toolbar: '#tableBar', title: '操作',minWidth:330}, {field: 'id', hide: true, title: 'ID'}, /*{field: 'salesOrderNo', sort: true, title: '销售工单号'},*/ {field: 'workOrderNo', sort: true, title: '生产工单号',minWidth:150}, /*{field: 'drawingNo', sort: true, title: '图号'},*/ /*{field: 'productionLine', sort: true, title: '生产线',minWidth:100},*/ {field: 'materialCode', sort: true, title: '产品编号',minWidth:160}, // {field: 'materialCode', sort: true, title: '产品编号',minWidth:120, // event: 'materialCodeClick', // style: 'cursor: pointer;color: blue;font-style: italic;text-decoration: underline;'}, {field: 'materialName', sort: true, title: '产品名称',minWidth:280}, /* {field: 'custom', sort: true, title: '客户编号',minWidth:120},*/ {field: 'orderStatus', sort: true, title: '状态',align:'center',width:80,templet: '#orderStatusTpl'}, {field: 'planQty', sort: true, title: '计划数量',align:'center',minWidth:120}, {field: 'actualQty', sort: true, title: '完成数量',align:'center',minWidth:120}, // {field: 'actualOnlineQty', sort: true, title: '实际上线数量',minWidth:120}, /*{field: 'scrapQty', sort: true, title: '报废数量'}, {field: 'repairQty', sort: true, title: '返修数量'}, {field: 'actualOnlineQty', sort: true, title: '实际上线数量'}, {field: 'onlineCompletionMark', sort: true, title: '上线完工标记'}, {field: 'demandDate', sort: true, title: '需求日期'},*/ {field: 'planStartTimeString', sort: true, title: '计划开始时间',minWidth:160}, {field: 'planEndTimeString', sort: true, title: '计划结束时间',minWidth:160}, /* {field: 'serialNumber', sort: true, title: '顺序号'},*/ {field: 'actualStartTime', sort: true, title: '实际开始时间',minWidth:160}, {field: 'actualEndTime', sort: true, title: '实际结束时间',minWidth:160}, /* {field: 'marketAreaCode', sort: true, title: '市场区域编码',minWidth:120},*/ {field: 'softwareVersionCode', sort: true, title: '产品型号',minWidth:120}, {field: 'productCompanyCode', sort: true, title: '班次',minWidth:120}, /* {field: 'spareField1', sort: true, title: '预留字段1'}, {field: 'spareField2', sort: true, title: '预留字段2'}, {field: 'spareField3', sort: true, title: '预留字段3'}, {field: 'spareField4', sort: true, title: '预留字段4'}, {field: 'createTime', sort: true, title: '创建时间'}, {field: 'updateTime', sort: true, title: '更新时间'}, {field: 'createUser', sort: true, title: '创建人'}, {field: 'updateUser', sort: true, title: '修改人'},*/ {field: 'remarks', sort: true, title: '备注'} ]]; }; /** * 点击查询按钮 */ ProductionOrdeInfo.search = function () { var queryData = {}; queryData['workOrderNo'] = $("#workOrderNo").val(); queryData['materialCode'] = $("#materialCode").val(); queryData['orderStatus'] = $("#orderStatus").val(); table.reload(ProductionOrdeInfo.tableId, { where: queryData, page: {curr: 1} }); }; /** * 跳转到添加页面 */ ProductionOrdeInfo.jumpAddPage = function () { window.location.href = Feng.ctxPath + '/productionOrdeInfo/add' }; /** * 跳转到编辑页面 * * @param data 点击按钮时候的行数据 */ ProductionOrdeInfo.jumpEditPage = function (data) { window.location.href = Feng.ctxPath + '/productionOrdeInfo/edit?id=' + data.id }; /** * 导出excel按钮 */ ProductionOrdeInfo.exportExcel = function () { var checkRows = table.checkStatus(ProductionOrdeInfo.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击开始工单 */ ProductionOrdeInfo.startOrder = function (data) { var ajax1 = new $ax(Feng.ctxPath + "/productionOrdeInfo/orderCount?orderStatus=3"); var result1 = ajax1.start(); if(result1.data===0) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) { Feng.success("开始工单成功!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("开始工单失败!" + data.responseJSON.message + "!"); }); ajax.set(data); ajax.set("flag","true"); ajax.start(); }; Feng.confirm("是否开始生产?", operation); }else { layer.open({ title: "操作提示", icon: 0, closeBtn: 2, area: ['450px', '200px'], time: 5000, content: '开始失败,只能有一条生产中的工单进行生产!' }); } }; /** * 点击冻结工单 */ ProductionOrdeInfo.freezeOrder = function (data) { // var ajax1 = new $ax(Feng.ctxPath + "/productionOrdeInfo/orderCount?orderStatus=3"); // var result1 = ajax1.start(); // if(result1.data>1) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) { Feng.success("冻结工单成功!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("冻结工单失败!" + data.responseJSON.message + "!"); }); ajax.set(data); ajax.start(); }; Feng.confirm("是否冻结工单?", operation); // }else { // layer.open({ // title: "操作提示", // icon: 0, // closeBtn: 2, // area: ['450px', '200px'], // time: 5000, // content: '解冻失败,只能有一条生产中的工单进行生产!' // }); // } }; /** * 点击解冻工单 */ ProductionOrdeInfo.thawOrder = function (data) { var ajax1 = new $ax(Feng.ctxPath + "/productionOrdeInfo/orderCount?orderStatus=3"); var result1 = ajax1.start(); if(result1.data === 0) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) { Feng.success("解冻工单成功!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("解冻工单失败!" + data.responseJSON.message + "!"); }); ajax.set(data); ajax.start(); }; Feng.confirm("是否解冻工单?", operation); }else { layer.open({ title: "操作提示", icon: 0, closeBtn: 2, area: ['450px', '200px'], time: 5000, content: '解冻失败,只能有一条生产中的工单进行生产!' }); } }; /** * 点击启用工单 */ ProductionOrdeInfo.enableOrder = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) { Feng.success("启用工单成功!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("启用工单失败!" + data.responseJSON.message + "!"); }); ajax.set(data); ajax.start(); }; Feng.confirm("是否启用工单?", operation); }; /** * 点击关闭工单 */ ProductionOrdeInfo.closeOrder = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) { Feng.success("关闭工单成功!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("关闭工单失败!" + data.responseJSON.message + "!"); }); ajax.set(data); ajax.start(); }; Feng.confirm("是否关闭工单?", operation); }; ProductionOrdeInfo.materialCodeClick = function (data){ layer.open({ type: 2, area: ['1000px', '600px'], title: '物料信息列表', content: Feng.ctxPath + '/productionOrdeInfo/materialList', success: function (layero, index) { window.materialType = '成品'; }, }); } /** * 点击删除 * * @param data 点击按钮时候的行数据 */ ProductionOrdeInfo.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/delete", function (data) { Feng.success("删除成功!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; var now = new Date(); /** * 点击完成 * * @param data 点击按钮时候的行数据 */ ProductionOrdeInfo.finish = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productionOrdeInfo/editItem", function (data) { Feng.success("已完成!"); table.reload(ProductionOrdeInfo.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set(data); ajax.start(); }; Feng.confirm("是否完成?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + ProductionOrdeInfo.tableId, url: Feng.ctxPath + '/productionOrdeInfo/list', toolbar: '#toolbarDemo', page: true, height: "full-158", cellMinWidth: 100, cols: ProductionOrdeInfo.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { ProductionOrdeInfo.search(); }); // 添加按钮点击事件 /* $('body').on('click', '#btnAdd', function() {*/ $('#btnAdd').click(function () { ProductionOrdeInfo.jumpAddPage(); }); // 导出excel $('#btnExp').click(function () { ProductionOrdeInfo.exportExcel(); }); var data_tr; table.on('radio(' + ProductionOrdeInfo.tableId + ')', function (obj) { data_tr = $(this); }); // 上移按钮点击事件 $('body').on('click', '#btnUpTr', function() { var checkRows = table.checkStatus(ProductionOrdeInfo.tableId); if (checkRows.data.length != 1) { layer.msg("请选择一行数据!"); return; } var tr=$(data_tr).parent().parent().parent(); if($(tr).prev().html()==null){ layer.msg("已经是最顶部了!"); return; }else { var tbData = table.cache.productionOrdeInfoTable; //未上移前,记录本行和上一行数据 var tem = tbData[tr.index()]; var tem2 = tbData[tr.prev().index()]; //将本身插入到目标tr之前 $(tr).insertBefore($(tr).prev()); var num1 = tem.serialNumber; var num2 = tem2.serialNumber; tem.serialNumber = num2; tem2.serialNumber = num1; //上移之后,数据交换 tbData[tr.index()]=tem; tbData[tr.next().index()]=tem2; } }); // 下移按钮点击事件 $('body').on('click', '#btnDownTr', function() { var checkRows = table.checkStatus(ProductionOrdeInfo.tableId); if (checkRows.data.length != 1) { layer.msg("请选择一行数据!"); return; } var tr=$(data_tr).parent().parent().parent(); if($(tr).next().html()==null){ layer.msg("已经是最低部了!"); return; }else { var tbData = table.cache.productionOrdeInfoTable; //未上移前,记录本行和下一行数据 var tem = tbData[tr.index()]; var tem2 = tbData[tr.next().index()]; // 将本身插入到目标tr的后面 $(tr).insertAfter($(tr).next()); var num1 = tem.serialNumber; var num2 = tem2.serialNumber; tem.serialNumber = num2; tem2.serialNumber = num1; //上移之后,数据交换 tbData[tr.index()]=tem; tbData[tr.prev().index()]=tem2; } }); // 保存顺序 $('body').on('click', '#btnSaveSort', function() { var tbData = table.cache.productionOrdeInfoTable; $.ajax({ url: "/productionOrdeInfo/editItemAll", data: JSON.stringify(tbData), type: "post", contentType: "application/json", dataType: "json", success: function(data) { Feng.success("更新成功!"); table.reload(ProductionOrdeInfo.tableId); }, error: function (data) { if (me.error !== undefined) { me.error(data); } } }); }); //获取当前日期 function getDateTime(){ let date = new Date(); let year = date.getFullYear(); let month = date.getMonth() + 1; let day = date.getDate(); let time = date.toLocaleTimeString(); // 对月份进行处理,1-9月在前面添加一个“0” if (month >= 1 && month <= 9) { month = "0" + month; } //对日期进行处理,1-9日在前面添加一个“0” if (day >= 0 && day <= 9) { day = "0" + day; } let separator = "-"; //添加分隔符“-” this.dateTime = year + separator + month + separator + day + " " + time; return this.dateTime; } // 工具条点击事件 table.on('tool(' + ProductionOrdeInfo.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') {//编辑 ProductionOrdeInfo.jumpEditPage(data); } else if (layEvent === 'start') {//开始 data.orderStatus = '3'; //data.actualStartTime = getDateTime(); ProductionOrdeInfo.startOrder(data); }else if (layEvent === 'freeze') {//冻结 data.orderStatus = '4'; ProductionOrdeInfo.freezeOrder(data); }else if (layEvent === 'thaw') {//解冻 data.orderStatus = '3'; ProductionOrdeInfo.thawOrder(data); }else if (layEvent === 'close') {//关闭 data.orderStatus = '6'; ProductionOrdeInfo.closeOrder(data); }else if (layEvent === 'enable') {//启用 data.orderStatus = '1'; ProductionOrdeInfo.enableOrder(data); }else if (layEvent === 'delete') { ProductionOrdeInfo.onDeleteItem(data); }else if (layEvent === 'materialCodeClick') { ProductionOrdeInfo.materialCodeClick(data); }else if (layEvent === 'finish') {//完成 data.orderStatus = '5'; data.actualEndTime = getDateTime(); ProductionOrdeInfo.finish(data); } }); });