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 form = layui.form; /** * 保养计划管理 */ var EquipmentMaintainPlan = { tableId: "equipmentMaintainPlanTable" }; /** * 初始化表格的列 */ EquipmentMaintainPlan.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: '主键id'}, {field: 'equipmentNo', sort: true, title: '设备编号', width: 125}, {field: 'equipmentName', sort: true, title: '设备名称', width: 125}, {field: 'planNo', sort: true, title: '计划编号', width: 155}, {field: 'planName', sort: true, title: '计划名称', width: 125}, {field: 'planType', sort: true, title: '计划类型', width: 125}, {field: 'maintainType', sort: true, title: '保养类别', width: 125}, {field: 'intervalTime', sort: true, title: '间隔时间', width: 125}, {field: 'intervalUnit', sort: true, title: '间隔单位', width: 125}, // {field: 'state', sort: true, title: '状态'}, {field: 'state', sort: true, templet: '#stateTpl', title: '状态'}, {field: 'remarks', sort: true, title: '备注'}, {field: 'createUser', sort: true, title: '创建用户', width: 125}, {field: 'updateUser', sort: true, title: '更改用户', width: 125}, {field: 'createTime', sort: true, title: '创建时间',minWidth:160}, {field: 'updateTime', sort: true, title: '更改时间',minWidth:160}, {field: 'startTime', sort: true, title: '开始保养时间',minWidth:160}, {field: 'endTime', sort: true, title: '结束保养时间',minWidth:160}, {align: 'center', toolbar: '#tableBar', title: '操作', width: 125} ]]; }; /** * 点击查询按钮 */ EquipmentMaintainPlan.search = function () { var queryData = {}; queryData['planNo'] = $('#planNo').val(); queryData['equipmentName'] = $('#equipmentName').val(); queryData['equipmentNo'] = $('#equipmentNo').val(); table.reload(EquipmentMaintainPlan.tableId, { where: queryData, page: {curr: 1} }); }; form.on('switch(status)', function (obj) { var id = obj.elem.value; var checked = obj.elem.checked ? 1 : 0; EquipmentMaintainPlan.changeStatus(id, checked); }); // 修改状态方法 EquipmentMaintainPlan.changeStatus = function (id, checked) { var ajax = new $ax(Feng.ctxPath + "/equipmentMaintainPlan/editItem", function (data) { Feng.success("修改成功!"); }, function (data) { Feng.error("修改失败!" + data.message); table.reload(BsWorkshopInfo.tableId); }); ajax.set("id", id); ajax.set("state", checked); ajax.start(); }; /** * 弹出添加对话框 */ EquipmentMaintainPlan.openAddDlg = function () { window.location.href = Feng.ctxPath + '/equipmentMaintainPlan/add' }; /** * 点击编辑 * * @param data 点击按钮时候的行数据 */ EquipmentMaintainPlan.openEditDlg = function (data) { window.location.href = Feng.ctxPath + '/equipmentMaintainPlan/edit?id=' + data.id }; /** * 导出excel按钮 */ EquipmentMaintainPlan.exportExcel = function () { var checkRows = table.checkStatus(EquipmentMaintainPlan.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ EquipmentMaintainPlan.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/equipmentMaintainPlan/delete", function (data) { Feng.success("删除成功!"); table.reload(EquipmentMaintainPlan.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + EquipmentMaintainPlan.tableId, url: Feng.ctxPath + '/equipmentMaintainPlan/list', page: true, height: "full-158", cellMinWidth: 100, cols: EquipmentMaintainPlan.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { EquipmentMaintainPlan.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { EquipmentMaintainPlan.openAddDlg(); }); // 导出excel $('#btnExp').click(function () { EquipmentMaintainPlan.exportExcel(); }); // 工具条点击事件 table.on('tool(' + EquipmentMaintainPlan.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { EquipmentMaintainPlan.openEditDlg(data); } else if (layEvent === 'delete') { EquipmentMaintainPlan.onDeleteItem(data); } }); });