layui.use(['table', 'admin', 'ax', 'func'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; /** * 不良数据采集管理 */ var BadCollection = { tableId: "badCollectionTable" }; /** * 初始化表格的列 */ BadCollection.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: '主键id'}, {field: 'workOrderNo', sort: true, title: '工单编号',width: 160}, {field: 'sfcCode', sort: true, title: '总成序列号',width: 160}, {field: 'workshopCode', sort: true, title: '车间编码',width: 125}, {field: 'productCode', sort: true, title: '产品编号',width: 125}, {field: 'productionLine', sort: true, title: '产线编号'}, {field: 'locationCode', sort: true, title: '工位编号',width: 125}, {field: 'equipmentNo', sort: true, title: '设备编号',width: 125}, {field: 'typeCode', sort: true, title: '不良类型编码',width: 145}, {field: 'typeName', sort: true, title: '不良类型名称',width: 145}, {field: 'badCode', sort: true, title: '不良原因编码',width: 145}, {field: 'badDesc', sort: true, title: '不良原因',width: 125}, {field: 'collectionTime', sort: true, title: '采集时间',width: 160}, {field: 'collectionUser', sort: true, title: '采集用户',width: 125}, {field: 'createUser', sort: true, title: '创建用户',width: 125}, {field: 'createTime', sort: true, title: '创建时间',width: 160}, {field: 'updateUser', sort: true, title: '更改用户',width: 125}, {field: 'updateTime', sort: true, title: '更改时间',width: 160}, // {align: 'center', toolbar: '#tableBar', title: '操作',width: 125} ]]; }; /** * 点击查询按钮 */ BadCollection.search = function () { var queryData = {}; queryData['workOrderNo'] = $('#workOrderNo').val(); queryData['sfcCode'] = $('#sfcCode').val(); queryData['productCode'] = $('#productCode').val(); table.reload(BadCollection.tableId, { where: queryData, page: {curr: 1} }); }; /** * 弹出添加对话框 */ BadCollection.openAddDlg = function () { func.open({ title: '添加不良数据采集', content: Feng.ctxPath + '/badCollection/add', tableId: BadCollection.tableId }); }; /** * 点击编辑 * * @param data 点击按钮时候的行数据 */ BadCollection.openEditDlg = function (data) { func.open({ title: '修改不良数据采集', content: Feng.ctxPath + '/badCollection/edit?id=' + data.id, tableId: BadCollection.tableId }); }; /** * 导出excel按钮 */ BadCollection.exportExcel = function () { var checkRows = table.checkStatus(BadCollection.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ BadCollection.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/badCollection/delete", function (data) { Feng.success("删除成功!"); table.reload(BadCollection.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + BadCollection.tableId, url: Feng.ctxPath + '/badCollection/list', page: true, height: "full-158", cellMinWidth: 100, cols: BadCollection.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { BadCollection.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { BadCollection.openAddDlg(); }); // 导出excel $('#btnExp').click(function () { BadCollection.exportExcel(); }); // 工具条点击事件 table.on('tool(' + BadCollection.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { BadCollection.openEditDlg(data); } else if (layEvent === 'delete') { BadCollection.onDeleteItem(data); } }); });