个人博客

2021年5月22日:

上次制定了一些基本的计划,包括入团申请的完善,其中包括检索社团和部门是否满员,部长是否有人担当,以下是我简单做的代码:

@RequestMapping("/qingqiu")
public String xiugai(String ifyes, String photo, String username, String clubname, String refuse, String job,
String emptyname) {
if (ifyes.equals("yes")) {
if (job.equals("部长")) {
empty.update(clubname, emptyname, username);
} else {
empty.update2(clubname, emptyname);
}
club.updatecount(clubname);
apply.xiugaiyes(photo);
m.xiugai(photo);
userService.update(username);
Clubuser clubuser1 = new Clubuser(userService.get(username).getId(), club.get(clubname).getId(), new Date(),
null);
clubuser.add(clubuser1);
return "forward:/index?club=" + clubname + "&user=" + username;
} else {
apply.xiugaino(photo, refuse);
m.xiugai(photo);
return "forward:/index.jsp?clubname=" + clubname + "&user=" + username + "&refuse=" + refuse;
}
}

这一段代码就是我原先用来做社团申请的,这是我的前端代码:

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="/index_head.jsp">
<jsp:param name="title" value="社团申请" />
<jsp:param name="needSwitch" value="true" />
<jsp:param name="needCropper" value="true" />
</jsp:include>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>
社团申请表<small style="color: red;">请认真填写此表,社长才能回应你的申请请求!</small>
</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<br>
<form action="${pageContext.request.contextPath}/club/apply"
method="post" id="demo-form2"
class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="login-mail">真实姓名<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control col-md-7 col-xs-12"
required name="user_name" id="userno"></input> <input
type="hidden" name="club_name" value="${name}"> <input
type="hidden" name="clubusername" value="${username}">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">性别</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="checkbox" id="chkSex" /> <input id="hidSex"
type="hidden" name="sex" value="男" />
</div>
</div>

<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="login-mail">学院<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control col-md-7 col-xs-12"
required name="xueyuan"></input>
</div>
</div>

<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="login-mail">班级<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control col-md-7 col-xs-12"
required name="banji"></input>
</div>
</div>

<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="login-mail">专业<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control col-md-7 col-xs-12"
required name="zhuanye"></input>
</div>
</div>

<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="login-mail">学号<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control col-md-7 col-xs-12"
required name="stuid"></input>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="login-mail">上传照片(请上传你的个人头像)<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12" id="imgdiv">
<button type="button" class="btn btn-success"
onclick="uploadLogo()" id="img">上传头像</button>
<input type="hidden" name="photo" id="imgData" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="true-name">申请的部门<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="form-control" required id="empty" name="empty_name">
<option disabled selected style="display: none;"></option>
<c:forEach items="${emptys}" var="type">
<option value="${type.name}"
<c:if test="${type.renshu==type.peoplecount}">disabled</c:if>>${type.name}<c:if
test="${type.renshu==type.peoplecount}">(该部门人数已满,请选择其他部门)</c:if></option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group" style="display: none;" id="reason">
<label class="control-label col-md-3 col-sm-3 col-xs-12"
for="phone">申请缘由(可写个人简历或者本人的获奖经历)<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea rows="10" class="form-control col-md-7 col-xs-12 "
required name="content"></textarea>
</div>
</div>
<div class="form-group">
<label for="id-card"
class="control-label col-md-3 col-sm-3 col-xs-12">申请职位<span
class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="form-control" required name="job">
<option disabled selected style="display: none;"></option>
<option value="普通团员">普通团员</option>
<option value="部长" id="buzhang">部长</option>
</select>
</div>
</div>
<div class="form-group">
<div
class="col-md-6 col-sm-6 col-xs-12 col-sm-offset-3 col-md-offset-3">
<button type="submit" class="btn btn-primary" id="a">提交申请</button>
</div>
</div>
</form>
</div>
</div>
</div>
<jsp:include page="/index_foot.jsp">
<jsp:param name="needSwitch" value="true" />
<jsp:param name="needAlert" value="true" />
<jsp:param name="needCropper" value="true" />
</jsp:include>

其中在这段代码的添加部门处有一个判断是否部门满员的选项,如果满了就不可用

function ajaxRequest(params) {
var club = {};
club.id = $("#clubId").val().trim();
club.name = $("#clubName").val().trim();
if ($("#clubType").val() > 0) {
club.type_id = $("#clubType").val();
}
params.data.obj = club;
$.ajax({
url : params.url,
data : JSON.stringify(params.data),
type : "POST",
contentType : "application/json",
dataType : "json",
success : function(data) {
params.success(data);
$.each($(".shenqing"), function(i,a) {
$.each(data.rows,function(i,v){
if(v.name==$(a).attr("data-name")){
if(v.renshu==v.peoplecount){
$(a).text("社团已满").attr("disabled",true).removeClass("btn-success").addClass("btn-secondary");
}
$.each(${applylist},function(){
if(this.club_name==$(a).attr("data-name")){
if(this.status==0){
if(v.renshu==v.peoplecount){
$(a).text("社团已满").attr("disabled",true).removeClass("btn-success").addClass("btn-secondary");
}
else
{
$(a).remove();
}
}
if(this.status==2){
$(a).text("已加").attr("disabled",true).removeClass("btn-success").addClass("btn-secondary");
}
}
})
}
})
})
}
})
}

这是判断社团是否满员的代码,如果满了就在按钮那显示已满,不然就允许用户添加。

posted @ 2021-05-22 21:18  一条快乐的小鲸鱼  阅读(52)  评论(0编辑  收藏  举报