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 ScannerConfig = { tableId: "scannerConfigTable" }; /** * 初始化表格的列 */ ScannerConfig.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: 'id'}, {field: 'locationCode', sort: true, title: '工位编码'}, {field: 'ipAddress', sort: true, title: 'ip地址'}, {field: 'createUser', sort: true, title: '创建人'}, {field: 'createTime', sort: true, title: '创建时间'}, {align: 'center', toolbar: '#tableBar', title: '操作'} ]]; }; /** * 点击查询按钮 */ ScannerConfig.search = function () { var queryData = {}; queryData['locationCode'] = $('#locationCode').val(); queryData['ipAddress'] = $('#ipAddress').val(); table.reload(ScannerConfig.tableId, { where: queryData, page: {curr: 1} }); }; /** * 跳转到添加页面 */ ScannerConfig.jumpAddPage = function () { window.location.href = Feng.ctxPath + '/scannerConfig/add' }; /** * 跳转到编辑页面 * * @param data 点击按钮时候的行数据 */ ScannerConfig.jumpEditPage = function (data) { window.location.href = Feng.ctxPath + '/scannerConfig/edit?id=' + data.id }; /** * 导出excel按钮 */ ScannerConfig.exportExcel = function () { var checkRows = table.checkStatus(ScannerConfig.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ ScannerConfig.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/scannerConfig/delete", function (data) { Feng.success("删除成功!"); table.reload(ScannerConfig.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + ScannerConfig.tableId, url: Feng.ctxPath + '/scannerConfig/list', page: true, height: "full-158", cellMinWidth: 100, cols: ScannerConfig.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { ScannerConfig.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { ScannerConfig.jumpAddPage(); }); // 导出excel $('#btnExp').click(function () { ScannerConfig.exportExcel(); }); // 工具条点击事件 table.on('tool(' + ScannerConfig.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { ScannerConfig.jumpEditPage(data); } else if (layEvent === 'delete') { ScannerConfig.onDeleteItem(data); } }); });