layui.use(['upload', 'table', 'admin', 'ax', 'func'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; var upload = layui.upload; /** * 生产订单管理 */ var SalesOrder = { tableId: "salesOrderTable" }; /** * 初始化表格的列 */ SalesOrder.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: '主键id'}, {field: 'salesOrderCode', sort: true, title: '订单编号',width: 160}, {field: 'customerNo', sort: true, title: '客户编号',width: 120}, {field: 'cargoNo', sort: true, title: '货号',width: 120}, {field: 'productCode', sort: true, title: '产品编号',width: 160}, {field: 'productName', sort: true, title: '产品名称',width: 160}, {field: 'planNumber', sort: true, title: '计划数量',width: 120}, { field: 'state', align: "center", title: '状态', templet: function (d) { switch(d.state){ case "1" : return "未开始"; break; case "2" : return "已拆分"; break; case "3" : return "已下发"; break; case "4" : return "已关闭"; break; default : } } }, {field: 'planStartTime', sort: true, title: '计划开始时间',width: 160}, {field: 'planEndTime', sort: true, title: '计划结束时间',width: 160}, {field: 'workshopCode', sort: true, title: '车间编码',width: 120}, {field: 'lineCode', sort: true, title: '产线编码',width: 120}, {field: 'deliveryTime', sort: true, title: '交货时间',width: 160}, {field: 'orderSource', sort: true, title: '订单来源',width: 120}, {field: 'createUser', sort: true, title: '创建用户',width: 120}, {field: 'createTime', sort: true, title: '创建时间',width: 160}, {field: 'updateUser', sort: true, title: '更改用户',width: 120}, {field: 'updateTime', sort: true, title: '更改时间',width: 160}, {field: 'remark', sort: true, title: '备注'}, {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'} ]]; }; /** * 点击查询按钮 */ SalesOrder.search = function () { var queryData = {}; queryData['salesOrderCode'] = $('#salesOrderCode').val(); queryData['customerNo'] = $('#customerNo').val(); queryData['cargoNo'] = $('#cargoNo').val(); queryData['productCode'] = $('#productCode').val(); queryData['productName'] = $('#productName').val(); queryData['workshopCode'] = $('#workshopCode').val(); queryData['lineCode'] = $('#lineCode').val(); queryData['state'] = $('#state').val(); table.reload(SalesOrder.tableId, { where: queryData, page: {curr: 1} }); }; //下载模板 $("#btnTemp").click(function () { window.location.href = Feng.ctxPath + "/salesOrder/exportOut" }); // 导入excel var uploadInst = upload.render({ elem: '#import' ,url: Feng.ctxPath + '/salesOrder/importIn' ,accept: 'file' ,done: function (res) { table.reload(SalesOrder.tableId, {url: Feng.ctxPath + "/salesOrder/list"}); Feng.success("上传成功") } ,error: function () { Feng.error("上传失败") } }); $('#split').click(function (){ var checkRows = table.checkStatus(SalesOrder.tableId); if (checkRows.data.length !== 1) { Feng.error("请选择一条要拆分的订单"); } window.location.href = Feng.ctxPath + '/salesOrder/split?id=' + checkRows.data[0].id }); /** * 跳转到添加页面 */ SalesOrder.jumpAddPage = function () { window.location.href = Feng.ctxPath + '/salesOrder/add' }; /** * 跳转到编辑页面 * * @param data 点击按钮时候的行数据 */ SalesOrder.jumpEditPage = function (data) { window.location.href = Feng.ctxPath + '/salesOrder/edit?id=' + data.id }; /** * 导出excel按钮 */ SalesOrder.exportExcel = function () { var checkRows = table.checkStatus(SalesOrder.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 下发订单 */ SalesOrder.distribute = function (data) { layer.alert(data); }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ SalesOrder.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/salesOrder/delete", function (data) { Feng.success("删除成功!"); table.reload(SalesOrder.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + SalesOrder.tableId, url: Feng.ctxPath + '/salesOrder/list', page: true, height: "full-158", cellMinWidth: 100, cols: SalesOrder.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { SalesOrder.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { SalesOrder.jumpAddPage(); }); // 导出excel $('#btnExp').click(function () { SalesOrder.exportExcel(); }); let salesId = []; // 绑定下发 $('#distribute').click(function () { var checkRows = table.checkStatus(SalesOrder.tableId); if(checkRows.data[0].state === "3"){ Feng.error("该工单已下发完毕!"); return; } if (checkRows.data.length !== 1) { Feng.error("请选择一条要下发的订单"); return; } var checkRows = table.checkStatus(SalesOrder.tableId); console.log(checkRows.data); window.location.href = Feng.ctxPath + '/salesOrder/bindParam?id=' + checkRows.data[0].id // layer.open({ // type: 2, // area: ['1000px', '600px'], // title: '下发订单', // content: Feng.ctxPath + '/salesOrder/bindParam', // success: function (layero, index) { // // let body = layer.getChildFrame('body', index); // // body.find('form').find('#salesOrderList').val(checkRows.data); // // 获取子页面的iframe // var iframe = window['layui-layer-iframe'+index]; // // 向子页面的全局函数child传参 // iframe.child(checkRows.data); // }, // end: function () { // table.reload(SalesOrder.tableId, { // where: null, page: {curr: 1} // }); // } // }); }); // 工具条点击事件 table.on('tool(' + SalesOrder.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { SalesOrder.jumpEditPage(data); } else if (layEvent === 'delete') { SalesOrder.onDeleteItem(data); } }); });