layui.define(['form', 'laydate', 'table'], function (exports) { var form = layui.form; var laydate = layui.laydate; var table = layui.table; var teacherTable = null; var view = { init: function () { this.initTable(); this.initSearchForm(); this.initToolBar(); window.dataReload = function () { Lib.doSearchForm($("#searchForm"), teacherTable) } }, initTable: function () { teacherTable = table.render({ elem: '#teacherTable', height: Lib.getTableHeight(), cellMinWidth: 100, even: true, // skin:'nob', method: 'post', size: "lg", where: {teacherStatus: 1}, url: Common.ctxPath + '/jlw/teacher/list.json' // 数据接口 , page: Lib.tablePage // 开启分页 , limit: 10, cols: [[ // 表头 { field: 'universitiesCollegesIdText', title: '院校名称', align: "center" }, { field: 'teacherName', title: '教师姓名', align: "center" }, // { // field : 'teacherSn', title : '教师编号',align: "center" // }, { field: 'teacherJobNumber', title: '工号', align: "center" }, { field: 'teacherMobile', title: '电话', align: "center" }, { field: 'teacherEmail', title: '邮箱', align: "center" }, { field: 'addTime', title: '创建日期', align: "center" }, { field: 'userId', title: '操作',width:190, align: "center", templet: function (d) { var htm = '<a class="layui-table-link" lay-event="edit">编辑</a>'; htm += '<a class="layui-table-link" lay-event="del">删除</a>'; htm += '<a class="layui-table-link" lay-event="password">初始化密码</a>'; return htm; } } ]] }); table.on('checkbox(teacherTable)', function (obj) { var teacher = obj.data; if (obj.checked) { //按钮逻辑Lib.buttonEnable() } else { } }) }, initSearchForm: function () { Lib.initSearchForm($("#searchForm"), teacherTable, form); }, initToolBar: function () { toolbar = { add: function () { // 获取选中数据 var url = "/jlw/teacher/add.do"; Common.openDlg(url, "教师管理/添加教师",{area: ["350px", "400px"]}); }, refresh: function () {//刷新 searchForm.reset(); Lib.doSearchForm($("#searchForm"), teacherTable, 1); }, search: function () { Lib.doSearchForm($("#searchForm"), teacherTable, 1); }, import: function () { var url = "/jlw/teacher/importPage.do"; Common.openDlg(url, ""); }, export: function () {//导出 layer.confirm('是否确定导出教师信息?', function (index) { layer.close(index); window.open(Common.ctxPath + "/jlw/teacher/export.json"); }); } }; $('.ext-toolbar').on('click', function () { var type = $(this).data('type'); toolbar[type] ? toolbar[type].call(this) : ''; }); }, initTableTool: table.on('tool(teacherTable)', function (obj) { var data = obj.data; if (obj.event === 'edit') { var url = "/jlw/teacher/add.do?teacherId=" + data.teacherId; Common.openDlg(url, "教师管理/编辑教师"); } else if (obj.event === "del") { layer.confirm('是否确定删除该信息?', function (index) { var ret = Common.postAjax("/jlw/teacher/delete.json", {ids: data.teacherId}); layer.msg(ret.code == 0 ? "删除成功!" : ret.msg, { offset: ['50%'], icon: ret.code == 0 ? 1 : 2, time: 1500 //2秒关闭(如果不配置,默认是3秒) }, function () { if (ret.code == 0) { Lib.tableRefresh(); } }); }); } else if (obj.event === "password") { layer.confirm('是否确定初始化该老师密码?', function (index) { var ret = Common.postAjax("/jlw/teacher/initPassword.json", { teacherId: data.teacherId }); layer.msg(ret.code == 0 ? "密码初始化成功!" : ret.msg, { offset: ['50%'], icon: ret.code == 0 ? 1 : 2, time: 1500 //2秒关闭(如果不配置,默认是3秒) }, function () { if (ret.code == 0) { Lib.tableRefresh(); } }); }); } }) } exports('index', view); });