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