<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<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="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="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/icheck/icheck.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" />
<link href="${pageContext.request.contextPath }/common/other/kingedit/themes/default/default.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="" class="form form-horizontal" id="form-coupon-add">
  					<h2>${questionnaireQuestionDto.questionName}</h2>	
  				<c:if test="${!empty questionnaireOptionList }">
						<c:forEach items="${questionnaireOptionList }" var="questionOption" varStatus="status">
						<tr class="text-c">
						 <div class="row cl">
							<label class="form-label col-2">${questionOption.optionOrder }：</label>
								<div class="formControls col-8">
									选项标题：<input id="option${questionOption.optionId }" name="" type="text" class="input-text" value="${questionOption.optionName }" placeholder="">

									选项分数：<input id="score${questionOption.optionId }" name="" type="text" class="input-text" value="${questionOption.optionScore }" placeholder="">
									选项类型：<select class="select" id="optionIsChekcbox${questionOption.optionId }" name="optionIsChekcbox">
								      	<option value="1" <c:if test="${questionOption.optionIsChekcbox == 1 }">selected="selected"</c:if>>多选</option>
										<option value="2" <c:if test="${questionOption.optionIsChekcbox == 2 }">selected="selected"</c:if>>单选</option>
		    						</select>
									
									<input type="hidden" id="Up${status.index +1}" calss="upclass" value="${questionOption.optionId }">
									<input type="hidden" id="order${status.index +1}" calss="upclass" value="${questionOption.optionOrder }">
									<c:if test="${(status.index +1) != 1}">
									<input id="" class="btn btn-primary radius upload-btn" onclick="moveUp(${status.index +1},${questionOption.optionOrder},${questionOption.optionId });" type="button" value="上移" />&nbsp;
									</c:if>
									<c:if test="${(status.index +1) != questionnaireOptionList.size()}">
									<input id="" class="btn btn-primary radius upload-btn" onclick="moveDown(${status.index +1},${questionOption.optionOrder},${questionOption.optionId });" type="button" value="下移" />&nbsp;
									</c:if>
									<input id="" class="btn btn-primary radius upload-btn" onclick="updateOption(${questionOption.optionId });" type="button" value="修改" />&nbsp;
								</div>
							</div>
						</c:forEach>
					</c:if>
					
  </form>
</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/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/Validform/5.3.2/Validform.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/js/tips.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/lib/My97DatePicker/WdatePicker.js"></script>  
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript">
$(function(){

});


function checkForm(){
	//名称验证
	/*  if(!commonTypeJdg('questionName',null,null,true)){
		layer.msg("题目名称不能为空",{icon: 2,time:2000});
		return false;
	}  */
	$.ajax({
		url: '${pageContext.request.contextPath }/admin/answer/insertQuestion',
		data:$('#form-coupon-add').serialize(),
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
			//alert("-----error:function----->>" + data);
      	  	layer.msg("添加失败!",{icon: 5,time:2000});
        },
        success:  function(data){
        	layer.msg(data.status,{icon:1,time:2000},function(){
				 parent.window.location.href = '${pageContext.request.contextPath }/admin/answer/getAllProblem';
			});
        }
	});
}
//修改选项
function updateOption(id){
	  if(!commonTypeJdg("option"+id,null,null,true)){
		layer.msg("选项内容不能为空",{icon: 2,time:2000});
		return false;
	} 
	  if(!commonTypeJdg("score"+id,null,null,true)){
			layer.msg("选项分数不能为空",{icon: 2,time:2000});
			return false;
		}  
		var optionName = $("#option"+id).val();
		var score = $("#score"+id).val();
		var optionIsChekcbox = $("#optionIsChekcbox"+id).val();
	$.ajax({
		url: '${pageContext.request.contextPath }/option/updateOptionById',
		data:{ "optionId":id,"optionName":optionName,"score":score,"optionIsChekcbox":optionIsChekcbox},
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
			//alert("-----error:function----->>" + data);
      	  	layer.msg("修改失败!",{icon: 5,time:2000});
        },
        success:  function(data){
        	layer.msg(data.status,{icon:1,time:2000});
        }
	});
}


function reloadWindow() {
	window.location.reload();
}


//关闭隐藏div
function closeDiv() {
	$("#userInfoList").hide();
}
//排序  上移
function moveUp(index,orderId,optionId){
	//打开遮罩层	
	 maskLayer();
	var optionId2 = $("#Up"+(index-1)).val();//被替换的选项ID
	var order2 = $("#order"+(index-1)).val();//被替换的选项序号
	$.ajax({
		url: '${pageContext.request.contextPath }/option/optionSortingById',
		data:{ "optionId":optionId,"orderId":order2,"optionId2":optionId2,"orderId2":orderId},
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
			//alert("-----error:function----->>" + data);
      	  	layer.msg("修改失败!",{icon: 5,time:2000});
        },
        success:  function(data){
        	layer.msg(data.status,{icon:1,time:1000},function(){
				/*  parent.window.location.href = '${pageContext.request.contextPath }/admin/answer/getAllProblem'; */
				reloadWindow();
			});
        	
        }
	});
	
}

function moveDown(index,orderId,optionId){
	//打开遮罩层	
	 maskLayer();
	var optionId2 = $("#Up"+(index+1)).val();//被替换的选项ID
	var order2 = $("#order"+(index+1)).val();//被替换的选项序号
	$.ajax({
		url: '${pageContext.request.contextPath }/option/optionSortingById',
		data:{ "optionId":optionId,"orderId":order2,"optionId2":optionId2,"orderId2":orderId},
		dataType:'json',//服务器返回json格式数据
		type:'post',	//HTTP请求类型
		error:function(data){
			//alert("-----error:function----->>" + data);
     	  	layer.msg("修改失败!",{icon: 5,time:2000});
       },
       success:  function(data){
       	layer.msg(data.status,{icon:1,time:1000},function(){
				/*  parent.window.location.href = '${pageContext.request.contextPath }/admin/answer/getAllProblem'; */
				reloadWindow();
			});
       	
       }
	});
}
//增加遮罩层
function maskLayer(){  
    var docHeight = $(document).height(); //获取窗口高度  
    $('body').append('<div id="overlay"></div>');  
    $('#overlay')  
      .height(docHeight)  
      .css({  
        'opacity': .9, //透明度  
        'position': 'absolute',  
        'top': 0,  
        'left': 0,  
        'background-color': 'black',  
        'width': '100%',  
        'z-index': 5000 //保证这个悬浮层位于其它内容之上  
      });  
      setTimeout(function(){$('#overlay').fadeOut('slow')}, 3000); //设置3秒后覆盖层自动淡出  
  };

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