<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,member-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/html5.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/respond.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/PIE_IE678.js"></script>
<![endif]-->
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>试卷题目管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 试卷管理 <span class="c-gray en">&gt;</span> 试卷查看 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
	<form action="${pageContext.request.contextPath }/admin/questionPaper/list" method="post" id="searchForm">
		<div class="text-c" style="font-size: 35px;"> 
				${paperList[0].paperName }
		</div>
	</form>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		
			<a href="javascript:;" onclick="update('添加题目','${pageContext.request.contextPath}/admin/questionPaper/toPaperAdd?paperId=${paperId}','','600')" class="btn btn-primary radius">
				<i class="Hui-iconfont">&#xe600;</i> 添加题目
			</a>
	</div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg">
	
		<tbody>
			<c:if test="${!empty paperList }">
			<c:set var="for1" value="0"> </c:set>
			
				<c:if test="${questionId == 2}">
				<c:set var="lastid" value="0"></c:set>
					<c:forEach items="${paperList }"  var="paper" varStatus="status">
						<c:if test="${lastid!=paper.questionId }">
							<tr class="text-c">
								<td style="background-color: #dddde0;">
								<span type="1" id="${paper.questionId }">${paper.questionName }</span>&nbsp;&nbsp;&nbsp;
								多选 
								<input type="radio"  
								<c:if test="${paper.isChekcbox ==1}"> checked="checked" </c:if>  testid="${paper.questionId }" 
								id="testId1${paper.questionId }" name="testIs${paper.questionId }" value="1"/>
								
								单选 
								<input type="radio" <c:if test="${paper.isChekcbox ==2}"> checked="checked" </c:if>  
								
								 testid="${paper.questionId }" id="testId2${paper.questionId }" name="testIs${paper.questionId }" value="2"/>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" onclick="deleteQuestion(${paper.questionId });" class="btn btn-primary">
																		 删除题目
																	</a>
																	<input type="hidden" id="questionId${paper.questionOrder }" value="${paper.questionId }" >
																	<c:if test="${!status.first}">
																	<a href="javascript:;" onclick="moveUp(${paper.questionId },${paper.questionOrder });" class="btn btn-primary">
																		 上移
																	</a>
																	</c:if>
																	<%-- <c:if test="${!status.last}">
																	<a href="javascript:;" onclick="moveDown(${paper.questionId },${paper.questionOrder });" class="btn btn-primary">
																		 下移
																	</a>
																	</c:if> --%>
								 </td>
							</tr>
							
							<c:forEach items="${paperList }" var="paper2">
								<c:if test="${paper2.questionId == paper.questionId}">
								<c:set var="for1" value="${for1+1}" > </c:set>
									<tr class="text-c">
										<td>
										<span type="2" index="1" name="optionName" id="${paper2.optionId }"> ${paper2.optionName }</span>
										（<span type="3" index="2" name="optionScore" id="${paper2.testId }" > ${paper2.score }</span>）
										</td>
									</tr>
								</c:if>
							</c:forEach>
							<c:set var="lastid" value="${paper.questionId }"></c:set>
						 </c:if>
					</c:forEach>
					</c:if>
			</c:if>
				<c:if test="${questionId == 1}">
				<tr class="text-c">
					<td colspan="9">请添加试卷题目</td>
				</tr>
				</c:if>
		</tbody>
	</table>
	</div>
</div>

<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script> 
<script type="text/javascript">



	$("span").click(function() {
		
		update('','${pageContext.request.contextPath }/admin/questionPaper/toPaperUpdate?id='+this.id+'&content='+this.innerHTML+'&type='+$(this).attr("type"),'','','300');
		
		
	});
	
	
	$(":radio").click(function() {
		
	
		$.ajax({
			url: '${pageContext.request.contextPath }/admin/questionPaper/updatePaper',
			data: {"id":$(this).attr("testid"),"content":$(this).attr("value"),"type":4},
			dataType:'json',//服务器返回json格式数据
			type:'post',	//HTTP请求类型
			error:function(data){
				//alert("-----error:function----->>" + data);
	      	  	layer.msg("修改失败!",{icon: 5,time:2000});
	        },
	        success:  function(data){
	        	//alert("----success------>>" + data);
	      	  	//layer.msg(data.status,{icon: 1,time:2000});
	      	  	if(data.flag){
	      		  layer.msg(data.info,{icon:1,time:2000},function(){
	      			parent.$("#"+$("#id").val()).text($("#content").val());
	        	  });
	      	  	}else{
	      	  		layer.msg(data.info,{icon:5,time:3000});
	      	  	}
	      	  
	        }
		});
		
	});
	//删除试卷题目
function deleteQuestion(id){
	$.ajax({
		url: '${pageContext.request.contextPath }/admin/questionPaper/deletePaperQuestion',
		data: {"questionId":id},
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
			//alert("-----error:function----->>" + data);
      	  	layer.msg("删除失败!",{icon: 5,time:2000});
        },
        success:  function(data){
        	//alert("----success------>>" + data);
      	  	//layer.msg(data.status,{icon: 1,time:2000});
      	  
      	  		layer.msg(data.status,{icon:1,time:2000});
      	  	reloadWindow();
        }
	});
}
	
	//排序 上移
function moveUp(questionId,questionOrder){
	var questionId2 = $("#questionId"+(questionOrder-1)).val();
	var questionOrder1 = questionOrder-1;
	$.ajax({
		url: '${pageContext.request.contextPath }/admin/answer/updatePaperOrder',
		data: {"questionId1":questionId,"questionOrder1":questionOrder1,"questionId2":questionId2,"questionOrder2":questionOrder},
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
			//alert("-----error:function----->>" + data);
      	  	layer.msg("修改失败!",{icon: 5,time:2000});
        },
        success:  function(data){
        	//alert("----success------>>" + data);
      	  	//layer.msg(data.status,{icon: 1,time:2000});
      	  
      	  		layer.msg(data.status,{icon:1,time:2000});
      	  	reloadWindow();
        }
	});
}
//排序 下移
function moveDown(questionId,questionOrder){
	var questionId2 = $("#questionId"+(questionOrder+1)).val();
	var questionOrder1 = questionOrder+1;
	$.ajax({
		url: '${pageContext.request.contextPath }/admin/answer/updatePaperOrder',
		data: {"questionId1":questionId,"questionOrder1":questionOrder1,"questionId2":questionId2,"questionOrder2":questionOrder},
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
      	  	layer.msg("修改失败!",{icon: 5,time:2000});
        },
        success:  function(data){
      	  
      	  		layer.msg(data.status,{icon:1,time:2000});
      	  	reloadWindow();
        }
	});
}
	
function reloadWindow() {
	window.location.reload();
}

/*优惠券类型-编辑*/
function update(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*优惠券类型-详情*/
function detailCType(title,url,id,w,h){
	layer_show(title,url,w,h);
}

</script> 
</body>
</html>