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 EquipmentMaintainTask = { tableId: "equipmentMaintainTaskTable" }; /** * 初始化表格的列 */ EquipmentMaintainTask.initColumn = function () { return [[ {type: 'checkbox'}, {field: 'id', hide: true, title: '主键id'}, {align: 'center', toolbar: '#tableBar', title: '操作',width :120}, {field: 'equipmentNo', sort: true, title: '设备编号', width: 125}, {field: 'equipmentName', sort: true, title: '设备名称', width: 125}, {field: 'taskNo', sort: true, title: '任务编号', width: 125}, {field: 'planNo', sort: true, title: '计划编号', width: 125}, {field: 'planName', sort: true, title: '计划名称', width: 125}, {field: 'maintainType', sort: true, title: '保养类别', width: 125}, {field: 'maintainState', sort: true, title: '保养状态', width: 125}, {field: 'maintainResult', sort: true, title: '保养结果', width: 125}, {field: 'reason', sort: true, title: '保养描述', width: 155}, {field: 'maintainPrice', sort: true, title: '保养价格', width: 125}, {field: 'externalMaintain', sort: true, title: '外部保养', width: 125}, {field: 'maintainUser', sort: true, title: '保养人', width: 125}, {field: 'finishTime', sort: true, title: '保养时间',minWidth:160}, {field: 'maintainTime', sort: true, title: '保养日期',minWidth:160}, {field: 'remarks', sort: true, title: '备注'}, ]]; }; /** * 点击查询按钮 */ EquipmentMaintainTask.search = function () { var queryData = {}; queryData['equipmentNo'] = $("#equipmentNo").val(); queryData['equipmentName'] = $("#equipmentName").val(); queryData['taskNo'] = $("#taskNo").val(); queryData['planNo'] = $("#planNo").val(); table.reload(EquipmentMaintainTask.tableId, { where: queryData, page: {curr: 1} }); }; /** * 弹出添加对话框 */ EquipmentMaintainTask.openAddDlg = function () { window.location.href = Feng.ctxPath + '/equipmentMaintainTask/add' // func.open({ // title: '添加保养任务', // content: Feng.ctxPath + '/equipmentMaintainTask/add', // tableId: EquipmentMaintainTask.tableId // }); }; /** * 点击编辑 * * @param data 点击按钮时候的行数据 */ EquipmentMaintainTask.openEditDlg = function (data) { window.location.href = Feng.ctxPath + '/equipmentMaintainTask/edit?id=' + data.id // func.open({ // title: '修改保养任务', // content: Feng.ctxPath + '/equipmentMaintainTask/edit?id=' + data.id, // tableId: EquipmentMaintainTask.tableId // }); }; /** * 导出excel按钮 */ EquipmentMaintainTask.exportExcel = function () { var checkRows = table.checkStatus(EquipmentMaintainTask.tableId); if (checkRows.data.length === 0) { Feng.error("请选择要导出的数据"); } else { table.exportFile(tableResult.config.id, checkRows.data, 'xls'); } }; /** * 点击删除 * * @param data 点击按钮时候的行数据 */ EquipmentMaintainTask.onDeleteItem = function (data) { var operation = function () { var ajax = new $ax(Feng.ctxPath + "/equipmentMaintainTask/delete", function (data) { Feng.success("删除成功!"); table.reload(EquipmentMaintainTask.tableId); }, function (data) { Feng.error("删除失败!" + data.responseJSON.message + "!"); }); ajax.set("id", data.id); ajax.start(); }; Feng.confirm("是否删除?", operation); }; // 渲染表格 var tableResult = table.render({ elem: '#' + EquipmentMaintainTask.tableId, url: Feng.ctxPath + '/equipmentMaintainTask/list', page: true, height: "full-158", cellMinWidth: 100, cols: EquipmentMaintainTask.initColumn() }); // 搜索按钮点击事件 $('#btnSearch').click(function () { EquipmentMaintainTask.search(); }); // 添加按钮点击事件 $('#btnAdd').click(function () { EquipmentMaintainTask.openAddDlg(); }); // 导出excel $('#btnExp').click(function () { EquipmentMaintainTask.exportExcel(); }); // 工具条点击事件 table.on('tool(' + EquipmentMaintainTask.tableId + ')', function (obj) { var data = obj.data; var layEvent = obj.event; if (layEvent === 'edit') { EquipmentMaintainTask.openEditDlg(data); } else if (layEvent === 'delete') { EquipmentMaintainTask.onDeleteItem(data); } }); });