layui.use(['form', 'table', 'admin', 'ax', 'func'], function () { var $ = layui.$; var table = layui.table; var $ax = layui.ax; var admin = layui.admin; var func = layui.func; var form = layui.form; /** * 基础BOM管理 */ var ProductBomInfo = { tableId: "productBomInfoTable" }; /** * 初始化表格的列 */ ProductBomInfo.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: '主键id'}, // {field: 'bomCode', sort: true, title: 'BOM编码',width:130}, { field: 'bomCode',width:130, align: "center", sort: true, title: 'BOM编码', templet: function (d) { var url = Feng.ctxPath + '/productBomChildInfo?bomCode=' + d.bomCode; return '' + d.bomCode + ''; } }, {field: 'bomName', sort: true, title: 'BOM名称',width:160}, {field: 'productCode', sort: true, title: '产品编码',width:130}, {field: 'productName', sort: true, title: '产品名称',width:160}, {field: 'version', sort: true, title: '版本',width:100}, {field: 'status', align: "center", sort: true, templet: '#statusTpl', title: '状态'}, {field: 'remark', sort: true, title: '备注',width:100}, {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}, {fixed: 'right',width: 125, minWidth: 125, align: 'center', toolbar: '#tableBar', title: '操作'} ]]; }; form.on('switch(status)', function (obj) { var id = obj.elem.value; var checked = obj.elem.checked ? 'ENABLE' : 'DISABLE'; ProductBomInfo.changeStatus(id, checked); }); // 修改状态方法 ProductBomInfo.changeStatus = function (id, checked) { var ajax = new $ax(Feng.ctxPath + "/productBomInfo/editItem", function (data) { Feng.success("修改成功!"); }, function (data) { Feng.error("修改失败!" + data.message); }); ajax.set("id", id); ajax.set("status", checked); ajax.start(); }; /** * 点击查询按钮 */ ProductBomInfo.search = function () { var queryData = {}; queryData['bomCode'] = $('#bomCode').val(); queryData['bomName'] = $('#bomName').val(); queryData['productCode'] = $('#productCode').val(); queryData['productName'] = $('#productName').val(); table.reload(ProductBomInfo.tableId, { where: queryData, page: {curr: 1} }); }; /** * 跳转到添加页面 */ ProductBomInfo.jumpAddPage = function () { window.location.href = Feng.ctxPath + '/productBomInfo/add' }; /** * 跳转到编辑页面 * * @param data 点击按钮时候的行数据 */ ProductBomInfo.jumpEditPage = function (data) { window.location.href = Feng.ctxPath + '/productBomInfo/edit?id=' + data.id }; /** * 导出excel按钮 */ ProductBomInfo.exportExcel = function () { var checkRows = table.checkStatus(ProductBomInfo.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ ProductBomInfo.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/productBomInfo/delete", function (data) { Feng.success("删除成功!"); table.reload(ProductBomInfo.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.set("bomCode", data.bomCode); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + ProductBomInfo.tableId, url: Feng.ctxPath + '/productBomInfo/list', page: true, height: "full-158", cellMinWidth: 100, cols: ProductBomInfo.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { ProductBomInfo.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { ProductBomInfo.jumpAddPage(); }); // 导出excel $('#btnExp').click(function () { ProductBomInfo.exportExcel(); }); // 工具条点击事件 table.on('tool(' + ProductBomInfo.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { ProductBomInfo.jumpEditPage(data); } else if (layEvent === 'delete') { ProductBomInfo.onDeleteItem(data); } }); });