<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/include/header2.jsp"%>
<!-- <link rel="stylesheet"  type="text/css" href="${ctx}/css/indexNew/jquery-ui.min.css" />
<link type="text/css" rel="stylesheet" href="${ctx}/css/baseFrame.css" />
<link type="text/css" rel="stylesheet" href="${ctx}/css/index.css" /> -->
<script src="${ctx}/component/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<title>任务列表</title>
<style>
	/*.c_table td.t_tit {
		width: 7%;	
	}
	#queryDiv div span {
		margin-right: 0px;
		display: inline-block;
		float: left;
	}
	#queryDiv div {
		height: 30px;
		line-height: 30px;
		text-indent: 25px; 
	}
	
	.Wdate{
		padding: 2px 4px;
	}
	#tbwrap td input,#tbwrap th input{
		margin-right: 5px;
	}*/
	.export{
		margin: 5px 5px 5px 0;
	}
	.export li{
		float: left;
		margin: 5px 0;
		margin-right: 20px;
	}
	.export .radio{
		margin:0 2px 0 5px;
	}
	.checkbox, .radio {
	    display: inline-block;
	}
</style>
</head>
<body>
<body class="bg1">
	<div class="headCon">
		<%@ include file="/WEB-INF/jsp/top2.jsp"%>
	</div>
	

		
		<!-- <ul>
			<hna:permission privilege="sysUser.view">
			<li><a href="${ctx}/sysUser/list.do">用户管理</a></li>
			</hna:permission>
			<hna:permission privilege="sysRole.view">
			<li><a href="${ctx}/sysRole/list.do">角色管理</a></li>
			</hna:permission>
			<hna:permission privilege="sysAuthority.view">
			<li><a href="${ctx}/sysAuthority/list.do">权限管理</a></li>
			</hna:permission>
			<hna:permission privilege="sysLog.view">
			<li><a href="${ctx}/sysLog/list.do">日志查看</a></li>
			</hna:permission>
			<hna:permission privilege="sysTask.issuing">
			<li class="on"><a href="${ctx}/sysTask/list.do">任务管理</a></li>
			</hna:permission>
			<li><a href="${ctx}/sysPersonal/list.do">个人管理</a></li>
		</ul> -->
	<div class="clear"></div>
	<div class="container_fluid">
		<!--左侧菜单-->
		<div class="searchCon left_menu managerLeft">
			<jsp:include page="/include/manageLeft.jsp">
				<jsp:param name="index" value="任务管理" />
			</jsp:include>
		</div>
	<!-- <div id="resultCon1" class="resultCon" style="margin-left: 255px;"> -->
	<div class="resultCon" style="margin-left: 255px;">
		<input type="hidden" id="CSRFToken" value="${csrfToken }"/>
		<div class="reSearch">
			<div class="p_bar" style="border-bottom: 1px dashed #afb4bb;">您当前的位置：任务管理</div>
			<div class="search-group">
				<ul class="export" id="timeFilterAlert2">
					<li>起始日期：<input name="beginOperationTime" 
								id="beginOperationTime"
								class="input_txt"
								readonly="readonly" 
								onfocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd',realDateFmt:'yyyy-MM-dd',realTimeFmt:'HH:mm:ss',minDate:'2010-01-01',maxDate:'#F{$dp.$D(\'endTimeOperationTime\')||\'%y-%M-%d\'}'})" 
								style="width:120px"/></li>
					<li>结束日期：<input name="endTimeOperationTime" 
								id="endTimeOperationTime" 
								class="input_txt"
								readonly="readonly" 
								onfocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd',realDateFmt:'yyyy-MM-dd',realTimeFmt:'HH:mm:ss',minDate:'#F{$dp.$D(\'beginOperationTime\')||\'2010-01-01\'}',maxDate:'%y-%M-%d'})" 
								style="width:120px"/></li>
					<li>
						<div id="checkRadio">
							<span><input class="radio" type="radio" name="type" data-type="" value="" checked="checked"/>全部</span>
							<span><input class="radio" type="radio" name="type" data-type="1" value="1"/>已处理</span>
							<span><input class="radio" type="radio" name="type" data-type="0" value="0"/>未处理</span>
						</div>
					</li>
					<li>
					<button id="exportBtn" class="btn btn-primary btn-confirm"><span class="glyphicon glyphicon-export" aria-hidden="ture"></span>导出</button>
					<!-- <span id="exportBtn" class="btn btn-primary" style="padding: 5px 10px;color: #fff;margin-left: 30px">导出</span> -->
					
					</li>
				</ul>
				<div class="clear"></div>
				<div class="action_box m_t10 t_c" id="queryDiv">
				</div>
			</div>
				<div class="row">
					<div class="search-group btnCon">
						<div>
							<button id="checkedCancel" class="btn btn-primary"><span class="glyphicon glyphicon-repeat" aria-hidden="ture"></span>选择撤销</button>
							<button id="allCancel" class="btn btn-primary"><span class="glyphicon glyphicon-refresh" aria-hidden="ture"></span>一键撤销</button>
							<!-- <span id="checkedCancel" class="btn btn-confirm" style="padding: 5px 10px;color: #fff;margin: 10px 0;float:right;">选择撤销</span>
							<span id="allCancel" class="btn btn-confirm" style="padding: 5px 10px;color: #fff;margin: 10px 10px;float:right;">一键撤销</span> -->
						</div>
					</div>
				</div>					
			</div>
			<div class="clear"></div>
			<div class="resultTable" style="width: 99%;padding: 10px;border-radius: 5px;">
				<table id="tbwrap" class="table table-bordered" style="table-layout:fixed;"></table>
				<div class="page eui-pager-custom" id="j_pager"></div>
			</div>	
			<!--right endTime-->
		</div>
	</div>
		<div id="menuContent" class="menuContent" style="display:none; position: absolute;background-color: white;">
			<ul id="treeDemo" class="ztree" style="margin-top:0; width:300px;"></ul>
		</div>
		<div id="menuContentForRole" class="menuContent" style="display:none; position: absolute;background-color: white;">
			<ul id="treeDemoForRole" class="ztree" style="margin-top:0; width:300px;"></ul>
		</div>
		<div><table id="dealCon" hidden></table></div>
	<script type="text/html" id="deal_template">
	     <tr>
              <td>任务名称</td>
              <td title="<!=item["name"]!>"><!=item["name"]!></td>
         </tr>
         <tr>
              <td>下发时间</td>
              <td title="<!=item["startTimeTime"]!>"><!=item["startTimeTime"]!></td>
         </tr>
         <!--<tr>
              <td>截止时间</td>
              <td title="<!=item["endTimeTime"]!>"><!=item["endTimeTime"]!></td>
         </tr>-->
         <tr>
              <td>下发人</td>
              <td title="<!=item["sysParentUserId"]!>"><!=item["sysParentUserId"]!></td>
         </tr>
         <tr>
              <td>任务状态</td>
              <td title="<!=item["status"]!>"><!=item["status"]!></td>
         </tr
		  <tr>
              <td>关联事件</td>
              <td title="<!=item["relatedId"]!>"><!=item["relatedId"]!></td>
         </tr>
         <!--<tr>
              <td>删除标志</td>
              <td title="<!=item["deleteFlag"]!>"><!=item["deleteFlag"]!></td>
         </tr>-->
          <tr>
              <td colspan="2" algin="center">
                  <input  type="button" id="btn_deal" value="完成">
                  <!--<input type="button" id="btn_cancel" value="取消">-->
                  <input type="button" id="btn_close" value="关闭">
              </td>
         </tr>
	</script>
	<script type="text/html" id="next_template">
		<thead>
			<tr>
				<th>用户ID</th>
				<th>用户名</th>
                <th>用户状态</th> 
				<th>用户级别</th>
				<th>删除标识</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody data-type="body">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td title="<!=item["userId"]!>"><!=item["userId"]!></td>
					<td title="<!=item["userName"]!>"><!=item["userName"]!></td>
					<td title="<!=item["status"]!>"><!=item["status"]!></td>
                    <td title="<!=item["level"]!>"><!=item["level"]!></td>
					<td title="<!=item["deleteFlag"]!>"><!=item["deleteFlag"]!></td>
					<td>
                        <a title="下发" data-value="<!=item["userId"]!>" data-name="<!=item["userDesc"]!>" onclick="nextTask(<!=item["userId"]!>)" class="nextTask">下发</a>
                    </td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="6"> 暂无数据</td>
					<td></td>
				</tr>
			<!}!>
		</tbody>
	</script>	
	<script type="text/html" id="tb_template">
		<thead>
			<tr>
				<th><input type="checkbox" class="check_all">全选</th>
				<th>任务执行人</th>
				<th>可撤回组数</th>
				<th>已完成组数</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody data-type="body">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<td><input type="checkbox" class="check_box" data-id="<!=item["userId"]!>"></td>
					<td title="<! if(item["user"]!=undefined){ !><!=item["user"]["userCnName"]!><! }else{ !><!=item["userId"]!><! } !>"><! if(item["user"]!=undefined){ !><!=item["user"]["userCnName"]!><! }else{ !><!=item["userId"]!><! } !></td>
					<td title="<!=item["countStatus0"]!>"><!=item["countStatus0"]!></td>
                    <td title="<!=item["countStatus3"]!>"><!=item["countStatus3"]!></td>
					<td>
						<a title="撤销" data-value="<!=item["userId"]!>" data-name="<!=item["userId"]!>" class="cancelTask btn btn-danger btn-xs" ><span class="glyphicon glyphicon-repeat" aria-hidden="ture"></span>撤销</a>
                    </td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="4"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>
	
	<script src="${ctx}/js/lib/core.js"></script>
	<!--<script src="${ctx}/component/My97DatePicker/WdatePicker.js" type="text/javascript"></script> -->
	<script>
		/*$("#exportBtn").click(function(){
			var stime = $("#beginOperationTime").val();
			var etime = $("#endTimeOperationTime").val();
			var type = $("input[name='type']:checked").val();
			download(stime,etime,type);
		});*/
	</script>

	<script type="text/javascript">
		var sysTaskDialog;
		$(function() {
            //下发任务
			$("#tbwrap").delegate(".nextTask","click",
				function(){
					var value=$(this).data("value");
					console.info(value);
					nextTask(value);
				}
			);
			// 1、处理
			/*$(".dealTask").delegate("click",
				function() {
					var value=$(this).data("value");
					$("#dealCon").data("id",value);
					var ht = baidu.template("deal_template",json);
					$("#dealCon").html(ht);
					$("#dealCon").show();
					seajs.use("component/dialog", function(dialog) {
						sysTaskDialog = new dialog({
							"width" : 800,
							"height" : 500,
							"contentType" : "iframe",
							"html" : "${ctx}/sysTask/dealTask.do",
							// 内容
							"title" : "添加系统用户信息" //标题
					});
				});
			});*/

			// 2、详细
			/*$("#tbwrap").delegate(
					".detail",
					"click",
					function() {
						// 2.1 获取主键
						var taskId = $(this).data("value");
						var taskDesc = $(this).data("name");
						// 2.2 弹窗窗口，显示详细信息
						seajs.use("component/dialog", function(dialog) {
							sysTaskDialog = new dialog({
								"width" : 800,
								"height" : 600,
								"contentType" : "iframe",
								"html" : "${ctx}/sysTask/detail.do?taskId="
										+ taskId, // 内容
								"title" : "查看"+taskDesc+"详细信息" //标题
							});
						});
					});*/

			
			// 3.撤销
			$("#tbwrap")
					.delegate(
							".cancelTask",
							"click",
							function() {
								var userId = $(this).data("value");

								if (confirm('确定撤销？')) {
									$
											.post(
													"${ctx}/sysTask/cancelTask.do",
													{
														userId : userId
													},
													function(result) {
														if ("succ" == result) {
															alert("操作成功");
															// 刷新列表页面
															top.location
																	.replace("${ctx}/sysTask/listDetail.do?ts="
																			+ new Date()
																					.getTime()); //如果操作成功则跳到列表界面 
															// 关闭弹窗窗口
															parent.sysTaskDialog
																	.close();
														} else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) { // 如果不通过安全检查
															var mess = result["mess"];
															$
																	.post(
																			"${ctx}/common/notThroughSecurityCheck.do?ts="
																					+ new Date()
																							.getTime(),
																			mess,
																			function(
																					res) {
																				alert(res);
																			},
																			"json");

														} else {
															alert(result);
														}
													}, "json");
								}

							});
			// 5、查询
			$("#searchBtn").click(function() {
				search();
			});
			
			//6.点击完成
			/*$(".btn_deal").click(function(){
				var id=$("#dealCon").data("id");
				$.post("${ctx}/sysTask/dealTask.do",{id:id},function(){
					
				})
				$("dealCon").hide();
			})*/

			// 页面加载完成调用查询分页
			search();
			
		//导出时选择时间过滤
			$("#timeFilterAlert2 .btn-confirm").click(function(){
				var startTime = $("#beginOperationTime").val();
				var endTime = $("#endTimeOperationTime").val();
				//alert(startTime+"我是startTime");
				
				if(startTime!='' && endTime!=''){
					var minTime = new Date(startTime);
					var maxTime = new Date(endTime);
					if(minTime.getTime()<=maxTime.getTime()){
						var status;
						if(("#checkRadio input:radio[name='type']:checked")){
							status=$("#checkRadio input:radio[name='type']:checked").data("type");
                            console.log(status);
														
						 }
						download(startTime,endTime,status);				
					}else{
						alert("起始时间不能大于终止时间！");
					}
					
				}else{
					alert("请选择需要导出的时间段！");
				}
			});
			$("#timeFilterAlert2 .btn-cancel").click(function(){
				$("#beginOperationTime").val('');
				$("#endTimeOperationTime").val('');
				//$("#timeFilterAlert2").css("display","none");
			});
			function download(startTime,endTime,status){
				var $form = $("<form style='display:none' target='downloadframe' action='${ctx}/baseInfo/downloadCaseByType.do' method='post'>");
				var $startTime = $("<input name='startTime' value='"+startTime+"'>");
				var $endTime = $("<input name='endTime' value='"+endTime+"'>");
				var $status = $("<input name='status' value='"+status+"'>");
				$form.append($startTime).append($endTime).append($status);
				$("body").append($form);
				$form.submit();
				$form.remove();
			}
			$("#tbwrap").delegate(".check_all","click",function(){
				if(this.checked){
					$(".check_box").prop("checked",true);
				}else{
					$(".check_box").prop("checked",false);
				}		
			});
			//判断是否全选
			$("#tbwrap").delegate(".check_box","click",function(){
				var n=0;
				$(".check_box").each(function(){
					if(this.checked){
						n++;
					}
				});
				if(n==$(".check_box").size()){
					$(".check_all").prop("checked",true);
				}else{
					$(".check_all").prop("checked",false);
				}
			});
			//点击选择撤销
			$("#checkedCancel").click(function(){
				var checkedIds=[];
				$("#tbwrap .check_box").each(function(){
					 if($(this).is(":checked")){
						checkedIds.push($(this).data("id"));
					 }
				 });
				var userId=checkedIds.join(",");
				if(userId==""){
					alert("请选择需要撤销的任务执行人！");
					return false;
				}
				if (confirm('确定要撤销？')) {
					$.ajax({
						type:"POST",
						data:{userId:userId},
						url:"${ctx}/sysTask/cancelTask.do",
						success:function(result){
							if ("succ" == result) {
								alert("操作成功");
								// 刷新列表页面
								top.location
										.replace("${ctx}/sysTask/listDetail.do?ts="
												+ new Date()
														.getTime()); //如果操作成功则跳到列表界面 
								// 关闭弹窗窗口
								parent.sysTaskDialog
										.close();
							} else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) { // 如果不通过安全检查
								var mess = result["mess"];
									$.post(
											"${ctx}/common/notThroughSecurityCheck.do?ts="+ new Date().getTime(),mess,
											function(res){													
												alert(res);
											},"json");
							} else {
								alert(result);
							}
						}
					})
				}
			})
			//一键撤销
			$("#allCancel").click(function(){
				if (confirm('确定要全部撤销？')) {
					$.ajax({
						type:"POST",
						url:"${ctx}/sysTask/cancelTaskAll.do",
						success:function(result){
							if(result=="succ"){
								alert("操作成功");
								//如果操作成功则跳到列表界面 
								top.location.replace("${ctx}/sysTask/listDetail.do?ts="+ new Date().getTime());						 
								// 关闭弹窗窗口
								parent.sysTaskDialog
										.close();
							}
							
						}
					})
				}
			});
		});
	</script>

	<script type="text/javascript">
		/*function nextTask(id){
					$.ajax({
						type:"POST",
						data:{id:id},
						url:"${ctx}/sysUser/userView.do",
						dataType:"json",
						success:function(result){
							if(result){
								//alert("下发成功！");
							}else{
								//alert("重试一下！");
							}
						}
					});
		}*/
		function search() {
			// 这里放包含查询条件的DIV
			var paramData = {
				page:1
			};

			seajs.use([ "component/table" ], function(uiTable) {
				$.post("${ctx}/sysTask/ajaxPageTaskUser.do",paramData,function(data){
					var table = new uiTable({
						 "con": "#tbwrap",//放table的容器
						 "data": {
							 "list": data.dataList//渲染需要的数据
						 },
						 "template": "tb_template",//渲染的模板
						 "pager": {//翻页
							 "con": "#j_pager",//翻页容器
							 "data": {
								 "currentPage": data.currentPage,//当前页
								 "pageCount": data.pageCount,
								 "rowCount": data.rowCount
							 },
							 //翻页样式
							 template: '<ul class="pagination" style="margin: 0;"><li><a title="首页" class="page_first" data-role="first" href="#">首页</a></li><li><a title="上一页" class="page_prev" href="#" data-role="prev">上一页</a></li><li class="pageNum" data-value="pageNum"><a></a></li><li><a title="下一页" class="page_next" href="#" data-role="next">下一页</a></li><li><a title="尾页" class="page_last" href="#" data-role="last">尾页</a></li></ul><div class="pageGo">共<span data-role="rowCount"></span>条 跳转到 <input  type="text" data-target="input" class="input_txt" style="width:80px;"/><a href="#" data-role="go" class="go">GO</a></div>'
						 }
					 });
					 table.getPager().bind("changePage", function (event, page, hander) {//点击翻页时
						 var paramData = {
									page:page
								};
						 $.post("${ctx}/sysTask/ajaxPageTaskUser.do",paramData,function(change){
							 table.render({//重新渲染
									list: change.dataList//传入新的渲染数据
								});
								hander({
									"currentPage": change.currentPage,
									"pageCount": change.pageCount,
									"rowCount": change.rowCount
								});
						 });
					 });
				});
			});
		}
	</script>
	<script src="${ctx}/js/lib/perfect-scrollbar.jquery.js"></script>
	<script>
	     $(function () {
		    $(".resultCon").perfectScrollbar();
		    $(".searchCon").perfectScrollbar();
			resize();
            $(window).resize(function(){
				resize();
			});			
	    });
	    function resize(){
			//获取窗口高度
			var windowheight=$(window).height();
			var leftList = windowheight-40;
			$(".searchCon").css({"height":leftList+"px"});
			$(".resultCon").css({"height":leftList-30+"px"});
			//$(".tableMain").css({"height":windowheight-40-42-131+"px"});
			//$(".table_list").css({"height":windowheight-40-42-100-85+"px"});$(".searchCon").perfectScrollbar("update");
			$(".searchCon").perfectScrollbar("update");
			$(".resultCon").perfectScrollbar("update");
		}
		function download(stime,etime,type){
			var $form = $("<form style='display:none' target='downloadframe' action='${ctx}/sysTask/ajaxPageTaskUser.do' method='post'>");
			var $dFlag = $("<input name='exportExcel' value='true'>");
			var $stime = $("<input name='startTime' value='"+stime+"'>");
			var $etime = $("<input name='endTime' value='"+etime+"'>");
			var $type = $("<input name='type' value='"+type+"'>");
			$form.append($dFlag).append($stime).append($etime).append($type);
			$("body").append($form);
			$form.submit();
			$form.remove();
		}
	</script>
	<%@ include file="/include/footer.jsp"%>
</body>
</html>
