Files
HRS/SMMS/WebContent/view/teacherList.jsp

486 lines
18 KiB
Plaintext
Raw Normal View History

2026-04-01 07:43:05 +08:00
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta charset="UTF-8">
<title>教师列表</title>
<link rel="stylesheet" type="text/css" href="static/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="static/easyui/css/demo.css">
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/js/validateExtends.js"></script>
<script type="text/javascript">
$(function() {
var table;
//datagrid初始化
$('#dataList').datagrid({
title:'教师列表',
iconCls:'icon-more',//图标
border: true,
collapsible:false,//是否可折叠的
fit: true,//自动大小
method: "post",
url:"TeacherServlet?method=TeacherList&t="+new Date().getTime(),
idField:'userId',
singleSelect:false,//是否单选
pagination:true,//分页控件
rownumbers:true,//行号
sortName:'userId',
sortOrder:'DESC',
remoteSort: false,
columns: [[
{field:'chk',checkbox: true,width:50},
{field:'userId',title:'ID',width:50, sortable: true},
{field:'name',title:'姓名',width:150, sortable: true},
{field:'sex',title:'性别',width:150,
formatter: function(value,row,index){
if (row.sex == '0') {
return '男';
}
return '女';
}
},
{field:'userName',title:'用户名',width:100},
{field:'phone',title:'联系方式',width:150},
{field:'isCounselor',title:'辅导员',width:150,
formatter: function(value,row,index){
if (row.isCounselor == 'y') {
return '是';
}
return '否';
}
}
]],
toolbar: "#toolbar",
onBeforeLoad : function(){
try{
$("#clazzList").combobox("getData")
}catch(err){
preLoadClazz();
}
}
});
//设置分页控件
var p = $('#dataList').datagrid('getPager');
$(p).pagination({
pageSize: 10,//每页显示的记录条数默认为10
pageList: [10,20,30,50,100],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
});
//设置工具类按钮
$("#add").click(function(){
table = $("#addTable");
$("#addDialog").dialog("open");
});
//修改
$("#edit").click(function(){
table = $("#editTable");
var selectRows = $("#dataList").datagrid("getSelections");
if(selectRows.length != 1){
$.messager.alert("消息提醒", "请选择一条数据进行操作!", "warning");
} else{
$("#editDialog").dialog("open");
}
});
//删除
$("#delete").click(function(){
var selectRows = $("#dataList").datagrid("getSelections");
var selectLength = selectRows.length;
if(selectLength == 0){
$.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
} else{
var teacherIds = [];
$(selectRows).each(function(i, row){
teacherIds[i] = row.teacherId;
});
var userIds = [];
$(selectRows).each(function(i, row){
userIds[i] = row.userId;
});
$.messager.confirm("消息提醒", "将删除与教师相关的所有数据,确认继续?", function(r){
if(r){
$.ajax({
type: "post",
url: "TeacherServlet?method=DeleteTeacher",
data: {userIds: userIds, teacherIds: teacherIds},
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","删除成功!","info");
//刷新表格
$("#dataList").datagrid("reload");
$("#dataList").datagrid("uncheckAll");
} else if(msg == "isHaveClazz"){
$.messager.alert("消息提醒","所选教师目前仍是班级负责人,删除失败!","info");
return;
} else if(msg == "isHaveLeave"){
$.messager.alert("消息提醒","所选教师目前仍有未完成的请假审核,删除失败!","info");
return;
} else{
$.messager.alert("消息提醒","删除失败!","warning");
return;
}
}
});
}
});
}
});
function preLoadClazz(){
$("#clazzList").combobox({
width: "150",
height: "25",
valueField: "id",
textField: "clazzName",
multiple: false, //可多选
editable: false, //不可编辑
method: "post",
url: "ClazzServlet?method=getClazzList&t="+new Date().getTime()+"&from=combox",
onChange: function(newValue, oldValue){
}
});
}
//设置添加窗口
$("#addDialog").dialog({
title: "添加教师",
width: 650,
height: 350,
iconCls: "icon-add",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'添加',
plain: true,
iconCls:'icon-user_add',
handler:function(){
var validate = $("#addForm").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
$.ajax({
type: "post",
url: "TeacherServlet?method=AddTeacher",
data: $("#addForm").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","添加成功!","info");
//关闭窗口
$("#addDialog").dialog("close");
//清空原表格数据
$("#add_name").textbox('setValue', "");
$("#add_sex").textbox('setValue', "");
$("#add_userName").textbox('setValue', "");
$("#add_number").textbox('setValue', "");
$("#add_phone").textbox('setValue', "");
$("#add_clazzList").textbox('setValue', "");
$("#add_isCounselor").textbox('setValue', "");
$(table).find(".chooseTr").remove();
//重新刷新页面数据
$('#dataList').datagrid("reload");
} else{
$.messager.alert("消息提醒","添加失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#add_name").textbox('setValue', "");
$("#add_sex").textbox('setValue', "");
$("#add_userName").textbox('setValue', "");
$("#add_number").textbox('setValue', "");
$("#add_phone").textbox('setValue', "");
$("#add_clazzList").textbox('setValue', "");
$("#add_isCounselor").textbox('setValue', "");
$(table).find(".chooseTr").remove();
//重新加载班级
$("#add_gradeList").combobox("clear");
$("#add_gradeList").combobox("reload");
}
},
],
onClose: function(){
$("#add_name").textbox('setValue', "");
$("#add_sex").textbox('setValue', "");
$("#add_userName").textbox('setValue', "");
$("#add_number").textbox('setValue', "");
$("#add_phone").textbox('setValue', "");
$("#add_clazzList").textbox('setValue', "");
$("#add_isCounselor").textbox('setValue', "");
$(table).find(".chooseTr").remove();
//重新加载班级
$("#add_gradeList").combobox("clear");
$("#add_gradeList").combobox("reload");
}
});
//下拉框通用属性
$("#edit_clazzList, #add_clazzList").combobox({
width: "200",
height: "30",
valueField: "id",
textField: "clazzName",
multiple: true, //可多选
editable: false, //不可编辑
method: "post",
});
$("#add_clazzList").combobox({
url: "ClazzServlet?method=getClazzList&t="+new Date().getTime()+"&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");
$(this).combobox("setValue", data[0].id);
}
});
//编辑教师信息班级下拉框
$("#edit_clazzList").combobox({
url: "ClazzServlet?method=getClazzList&t="+new Date().getTime()+"&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");
$(this).combobox("setValue", data[0].id);
}
});
//编辑教师信息
$("#editDialog").dialog({
title: "修改教师信息",
width: 650,
height: 350,
iconCls: "icon-edit",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'提交',
plain: true,
iconCls:'icon-user_add',
handler:function(){
var validate = $("#editForm").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
$.ajax({
type: "post",
url: "TeacherServlet?method=EditTeacher",
data: $("#editForm").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","修改成功!","info");
//关闭窗口
$("#editDialog").dialog("close");
//清空原表格数据
$("#edit_name").textbox('setValue', "");
$("#edit_sex").textbox('setValue', "");
$("#edit_userName").textbox('setValue', "");
$("#edit_number").textbox('setValue', "");
$("#edit_phone").textbox('setValue', "");
$("#edit_clazzList").textbox('setValue', "");
$("#edit_isCounselor").textbox('setValue', "");
//重新刷新页面数据
$('#dataList').datagrid("reload");
$('#dataList').datagrid("uncheckAll");
} else{
$.messager.alert("消息提醒","修改失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#edit_name").textbox('setValue', "");
$("#edit_sex").textbox('setValue', "");
$("#edit_userName").textbox('setValue', "");
$("#edit_number").textbox('setValue', "");
$("#edit_phone").textbox('setValue', "");
$("#edit_clazzList").textbox('setValue', "");
$("#edit_isCounselor").textbox('setValue', "");
$(table).find(".chooseTr").remove();
}
},
],
onBeforeOpen: function(){
var selectRow = $("#dataList").datagrid("getSelected");
var teacherId = selectRow.teacherId;
$("#edit_name").textbox('setValue', selectRow.name);
$("#edit_userName").textbox('setValue', selectRow.userName);
$("#edit_phone").textbox('setValue', selectRow.phone);
$("#edit-teacherId").val(teacherId);
$("#edit-userId").val(selectRow.userId);
var clazzId;
$.ajax({
type: "post",
url: "TeacherServlet?method=GetTeacherClazz",
data: {teacherId: teacherId},
success: function(data){
clazzId = data.split(",")
}
});
$("#edit_isCounselor").combobox('setValue', selectRow.isCounselor);
var sex = selectRow.sex;
setTimeout(function(){
$("#edit_clazzList").combobox('setValues', clazzId);
$("#edit_sex").combobox('setValue', sex);
}, 100);
},
onClose: function(){
$("#edit_name").textbox('setValue', "");
$("#edit_sex").textbox('setValue', "");
$("#edit_userName").textbox('setValue', "");
$("#edit_number").textbox('setValue', "");
$("#edit_phone").textbox('setValue', "");
$("#edit_clazzList").textbox('setValue', "");
$("#edit_isCounselor").textbox('setValue', "");
}
});
//搜索按钮监听事件
$("#search-btn").click(function(){
$('#dataList').datagrid('load',{
name: $('#search_teacher_name').val(),
clazzId: $("#clazzList").combobox('getValue') == '' ? 0 : $("#clazzList").combobox('getValue')
});
});
//清空搜索条件
$("#clear-btn").click(function(){
$('#dataList').datagrid("reload",{});
$("#clazzList").combobox('clear');
$("#search_teacher_name").textbox('setValue', "");
});
});
</script>
</head>
<body>
<!-- 数据列表 -->
<table id="dataList" cellspacing="0" cellpadding="0">
</table>
<!-- 工具栏 -->
<div id="toolbar">
<c:if test="${roleCode == 'admin'}">
<div style="float: left;"><a id="add" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a></div>
<div style="float: left;" class="datagrid-btn-separator"></div>
</c:if>
<div style="float: left;"><a id="edit" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a></div>
<div style="float: left;" class="datagrid-btn-separator"></div>
<c:if test="${roleCode == 'admin'}">
<div style="float: left;"><a id="delete" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-some-delete',plain:true">删除</a></div>
</c:if>
<div style="float: left;margin-top:4px;" class="datagrid-btn-separator" >
&nbsp;&nbsp;姓名:<input id="search_teacher_name" class="easyui-textbox" name="name" />
</div>
<div style="margin-left: 10px;margin-top:4px;" >
班级:<input id="clazzList" class="easyui-textbox" name="clazzId" />
<a id="search-btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索</a>
<a id="clear-btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">清空搜索</a>
</div>
</div>
<!-- 添加窗口 -->
<div id="addDialog" style="padding: 10px;">
<form id="addForm" method="post">
<table id="addTable" cellpadding="6" >
<tr>
<td>姓名:</td>
<td><input id="add_name" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="name" data-options="required:true, missingMessage:'请填写姓名'" /></td>
<td>性别:</td>
<td><select id="add_sex" class="easyui-combobox" data-options="required:true, missingMessage:'请选择性别',editable: false, panelHeight: 50, width: 60, height: 30" name="sex"><option value="0">男</option><option value="1">女</option></select></td>
</tr>
<tr>
<td>用户名:</td>
<td>
<input id="add_userName" class="easyui-textbox" style="width: 200px; height: 30px;" type="text" name="userName" data-options="required:true, missingMessage:'请输入用户名'" />
</td>
<td>联系方式:</td>
<td><input id="add_phone" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="phone" validType="mobile" /></td>
</tr>
<tr>
<td>是否是导员:</td>
<td><select id="add_isCounselor" class="easyui-combobox" data-options="required:true, missingMessage:'请选择是否是导员',editable: false, panelHeight: 50, width: 60, height: 30" name="isCounselor"><option value="n">否</option><option value="y">是</option></select></td>
<td>班级:</td>
<td><input id="add_clazzList" style="width: 200px; height: 30px;" class="easyui-textbox" name="clazzIds" data-options="required:true, missingMessage:'请选择班级'" /></td>
</tr>
</table>
</form>
</div>
<!-- 修改窗口 -->
<div id="editDialog" style="padding: 10px">
<form id="editForm" method="post">
<input type="hidden" name="userId" id="edit-userId">
<input type="hidden" name="teacherId" id="edit-teacherId">
<table id="editTable" cellpadding="8" >
<tr>
<td>姓名:</td>
<td><input id="edit_name" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="name" data-options="required:true, missingMessage:'请填写姓名'" /></td>
<td>性别:</td>
<td><select id="edit_sex" class="easyui-combobox" data-options="required:true, missingMessage:'请选择性别',editable: false, panelHeight: 50, width: 60, height: 30" name="sex"><option value="0">男</option><option value="1">女</option></select></td>
</tr>
<tr>
<td>用户名:</td>
<td>
<input id="edit_userName" class="easyui-textbox" style="width: 200px; height: 30px;" type="text" name="userName" data-options="required:true, missingMessage:'请输入用户名'" />
</td>
<td>联系方式:</td>
<td><input id="edit_phone" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="phone" validType="mobile" /></td>
</tr>
<tr>
<td>是否是导员:</td>
<td><select id="edit_isCounselor" class="easyui-combobox" data-options="required:true, missingMessage:'请选择是否是导员',editable: false, panelHeight: 50, width: 60, height: 30" name="isCounselor"><option value="n">否</option><option value="y">是</option></select></td>
<td>班级:</td>
<td><input id="edit_clazzList" style="width: 200px; height: 30px;" class="easyui-textbox" name="clazzIds" data-options="required:true, missingMessage:'请选择班级'" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>