<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>入闱命题任务批次详情</title>
<%@ include file="../common/top.jsp"%>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />
<style>
select{
	width: 120px;
}
</style>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/importTask.js"></script>
<script type="text/javascript">

	$(function(){
		
		$("#viewBtn").click(function(){
			var rowData = $("#dg").datagrid('getSelected');
			if(rowData != null){
				var url = "${ctx}/taskCenter/viewTaskCenterDetail/"+rowData.id;
				window.location.href = url;
			}
		});
		
		$("#dg").datagrid({
		    onDblClickRow: function (rowIndex, rowData) {
		    	$("#viewBtn").click();
		    }
		});
		
		$('#search-form').submit(function(event){
	        event.preventDefault(); 
	        var param = $('#search-form').serializeJson();
	        param = $.extend(param, {page:1,rows:10});
	        $('#dg').datagrid({
	        	'url':'${ctx}/business/queryPaperTask',
	        	'queryParams':param
	        });
	    });
		
		window.setTimeout(function(){$('#search-form').submit();},200);
		
		$("#saveChange").on('click',function(){
			if($("#oldTeacher").val()==$("#newTeacher").val()){
				$.messager.alert('提示','不能修改为同一个人','error');
			}else{
				var obj={
					"id":$("#taskId").val(),
					"oldId":$("#oldTeacher").val(),
					"name":$("#oldTeacher").find("option:selected").text(),
					"newId":$("#newTeacher").val()
				}
				$.post('${ctx}/business/updatePaperTask',obj,function(callback){
					if(callback.flag=='success'){
						$.messager.alert('提示','修改成功','info');	
						$('#dg').datagrid('reload');
					}
				});
			}
			
		});
	});
	function editTaskPerson(){
		var row=$("#dg").datagrid('getSelected');
		if(row){
			//先要查出是否可以修改任务单相关人员
			var obj={
				"id":row.id	
			};
			$.post('${ctx}/business/validateChange',obj,function(callback){
				if(callback.flag=='success'){
					$("#modifyTaskNo").window('open');
					
					$("#taskId").val(row.id);
					
					$("#oldTeacher").empty();
					$("#newTeacher").empty();
					
					$("#taskNo").html(row.taskNo);
					
					var ropositionTeacherHtml="<option value="+getUserId(row.propositionTeacherBean)+">"+formatNormalBean(row.propositionTeacherBean)+"(命题教师1)</option>";
					var auditTeacherHtml="<option value="+getUserId(row.auditTeacherBean)+">"+formatNormalBean(row.auditTeacherBean)+"(命题教师2)</option>";
					var primarySecretaryHtml="<option value="+getUserId(row.primarySecretaryBean)+">"+formatNormalBean(row.primarySecretaryBean)+"(学科秘书1)</option>";
					/* var assistantSecretaryHtml="<option value="+getUserId(row.assistantSecretaryBean)+">"+formatNormalBean(row.assistantSecretaryBean)+"(学科秘书2)</option>"; */
					var typesetterHtml="<option value="+getUserId(row.typesetterBean)+">"+formatNormalBean(row.typesetterBean)+"(排版员)</option>";
					
					$("#oldTeacher").append(ropositionTeacherHtml);
					$("#oldTeacher").append(auditTeacherHtml);
					$("#oldTeacher").append(primarySecretaryHtml);
					/* $("#oldTeacher").append(assistantSecretaryHtml); */
					$("#oldTeacher").append(typesetterHtml);
					
					obj={
							"id":getUserId(row.propositionTeacherBean)
					}
					$.post('${ctx}/user/queryTeacher',obj,function(callback){
						var users=callback.users;
						for(var i=0;i<users.length;i++){
							var userHtml="<option value="+users[i].id+">"+users[i].name+"</option>";
							$("#newTeacher").append(userHtml);
						}
					});
					
				}else{
					$.messager.alert('提示','该任务已经开启,无法修改任务单信息','error');		
				}
			});
		}else{
			 $.messager.alert('提示','请选择要修改任务单信息','error');
		}
	}
	function rejectTask(){
		var row=$("#dg").datagrid('getSelected');
		if(row){
			//先要查出是否可以修改任务单相关人员
			var obj={
				"id":row.id	
			};
			
			$.messager.confirm("操作提示", "确定要删除任务单吗?删除后将不能恢复?", function (data) {
				if(data){
					$.post('${ctx}/business/validateChange',obj,function(callback){
						if(callback.flag=='success'){
							$.post('${ctx}/business/deleteTask',obj,function(callback){
								if(callback.flag=='success'){
									$.messager.alert('提示','删除成功','info');
									//$('#dg').datagrid('reload');
									reloadWin();
								}else{
									$.messager.alert('提示','删除失败!','error');		
								}
							});
						}else{
							$.messager.alert('提示','该任务已经开启,无法撤销任务单信息','error');		
						}
					});
				}
			});
		}else{
			 $.messager.alert('提示','请选择要删除任务单信息','error');
		}
		
	}
	
	function formatBoolean(value,row,index){
		return value == null ? '未创建' : '已创建';
	}
</script>
</head>



<body>
	<%@ include file="../common/header.jsp"%>
	<div id="content" class="content">
        <%@ include file="../common/sub_menu.jsp"%>
	        <div id="page" class="page">
		   <div class="page-header">任务列表</div>
		   <div class="page-body">
		   		<div>
		            <form id="search-form" method="post" >
			            <input name="keyword" placeholder="请输入任务单编号或者课程信息搜索" style="width: 270px;"/>
			            
			            <select name="status">
			            	<c:forEach var="map" items="${status }">
			            		<option value="${map['status'] }">${map['statusName'] } (${map['count'] } 套)</option>
			            	</c:forEach>
			            </select>
			            <input name="batchId" value="${batchId }" type="hidden"/>
			            <button id="searchBtn">查询</button>
		            </form>
				</div>
				
		  	<div class="right" style="min-height:300px;position: relative;">
	             <div id="list-wrap posts" class="listview">
	                 <table id="dg" class="easyui-datagrid"
	                     data-options="fitColumns:true,singleSelect:true,striped:true,pagination:true,toolbar: '#tb'">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'taskNo',width:120">试卷编号</th>
	                             <th data-options="field:'statusName',width:90">状态</th>
	                             <th data-options="field:'courseName',width:130,formatter: function(value,row,index){
					return row.course.name + (row.course.code != null && row.course.code != ''?('(' + row.course.code + ')'):'');
				}">课程</th>
	                             <th data-options="field:'bookName',width:120,formatter: function(value,row,index){
					return row.book.name + (row.book.code != null && row.book.code != ''?('(' + row.book.code + ')'):'');
				}">教材</th>
	                             <th data-options="field:'propositionTeacherBean',formatter:formatNormalBean,width:70">命题教师1</th>
	                             <th data-options="field:'auditTeacherBean',formatter:formatNormalBean,width:70">命题教师2</th>
	                             <th data-options="field:'primarySecretaryBean',formatter:formatNormalBean,width:70">学科秘书</th>
	                             <!-- <th data-options="field:'assistantSecretaryBean',formatter:formatNormalBean,width:70">学科秘书2</th> -->
	                             <th data-options="field:'typesetterBean',formatter:formatNormalBean,width:70">排版员</th>
	                             <th data-options="field:'paperId',formatter:formatBoolean,width:90">试卷</th>
	                             <th data-options="field:'teacherAssessmentId',formatter:formatBoolean,width:90">教师评价</th>
	                             <th data-options="field:'difficultyEstimateTableId',formatter:formatBoolean,width:90">平均分数预估表</th>
	                         </tr>
	                     </thead>
	                   </table>
	               </div>
	            </div>
	            
	            <div id="tb" style="height:auto">
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" id="viewBtn">查看任务单</a>
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editTaskPerson()">修改任务单相关人员</a>
					        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true" onclick="rejectTask()">删除任务单</a>
					    </div>
		</div>
		</div>
     </div>
     
     <div id="modifyTaskNo" class="easyui-window"  data-options="modal:true,closed:true,iconCls:'icon-import',draggable:false" 
     style="width:320px;height:200px;padding:5px;overflow-x: hidden;">
     	<div style="padding-top: 10px;font-weight: bold;font-size: 14px;">
     		<span>任务单编号:<span id="taskNo"></span></span>
     	</div>
     	<div style="padding-top: 30px;">
     		<select id="oldTeacher">
     			
     		</select>
     		<span>替换为:</span>
     		<select id="newTeacher">
     			
     		</select>
     	</div>
     	<div align="right" style="padding-top: 30px;padding-right: 30px;">
     		<input type="button" value="保存" id="saveChange"/>
     	</div>
     	<input type="hidden" id="taskId"/>
     </div>
</body>
</html>