<%@page import="org.activiti.engine.repository.ProcessDefinition"%>
<%@page import="org.activiti.engine.impl.persistence.entity.*"%>
<%@page import="org.activiti.engine.repository.Deployment"%>
<%@page import="com.blueland.bpm.engine.config.model.*"%>
<%@page import="com.blueland.bpm.common.page.*"%>
<%@page import="com.blueland.bpm.common.util.*"%>
<%@page import="java.util.*"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/simpletable" prefix="simpletable"%>
<%@ include file="/commons/taglibs.jsp"%>
<%
	String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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>
<%@ include file="/commons/meta.jsp"%>
<base href="<%=basePath%>">
<title>待办列表</title>
	<link href="${ctx_js_plugins}/simpletable/simpletable.css" type="text/css" rel="stylesheet">
	<script type="text/javascript" src="${ctx_js_plugins}/simpletable/simpletable.js"></script>


<script type="text/javascript">
		$(document).ready(function() {
			// 分页需要依赖的初始化动作
			window.simpleTable = new SimpleTable('queryForm','${page.thisPageNumber}','${page.pageSize}','${pageRequest.sortColumns}');
			
		});
		function updateProcessComment(url){
			var procInstId=getOneProcInstId();
			if(!procInstId){
				return;
			}
			showDiaLog(url+"?procInstId="+procInstId,"修改流转意见",'1024px','550px');
		}
		
		function getOneProcInstId(){
			var chk_value =[]; 
			var processInstanceId="";
			$("input[name='items']:radio:checked").each(function(){ 
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一条流程数据！");
				return;
			}else{
				var items=chk_value[0].split("=");
				for(var i=0;i<items.length;i++){
					if(items[0]=="processInstanceId"){
						processInstanceId=items[1];
						break;
					}
				}
				
			}
			return processInstanceId;
		}
		
		function processAction(myUrl,title){
			var chk_value =[]; 
			var processInstanceId="";
			$("input[name='items']:radio:checked").each(function(){ 
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一条流程数据！");
				return;
			}else{
				var items=chk_value[0].split("=");
				for(var i=0;i<items.length;i++){
					if(items[0]=="processInstanceId"){
						processInstanceId=items[1];
					}
				}
				
			}
			if (confirm(title)) {
			jQuery.ajax({
				url: myUrl,
				data: { "processInstanceId": processInstanceId,"isHistory": true},
				type: "POST",
				success: function(resp)
				{
					alert(resp);
					window.location.reload();
				}
			});
			}
		}
		
		function updateProcessTime(url){
			var procInstId=getOneProcInstId();
			if(!procInstId){
				return;
			}
			showDiaLog(url+"?procInstId="+procInstId,"修改流转时间",'1200px','550px');
		}
		function delProcessRoam(url){
			var procInstId=getOneProcInstId();
			if(!procInstId){
				return;
			}
			showDiaLog(url+"?procInstId="+procInstId,"修改流程环节",'1400px','550px');
		}
		function processRestore(myUrl,title){
			var chk_value =[]; 
			var processInstanceId="";
			$("input[name='items']:radio:checked").each(function(){
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一条流程数据！");
				return;
			}else{
				var items=chk_value[0].split("=");
				for(var i=0;i<items.length;i++){
					if(items[0]=="processInstanceId"){
						processInstanceId=items[1];
					}
				}
				
			}
			if (confirm(title)) {
				jQuery.ajax({
					url: myUrl,
					data: {"processInstanceId":processInstanceId},
				    dataType: "json", //表示返回值类型，不必须
					type: "POST",
					success: function(resp)
					{
						if(resp.flag){
							alert("操作成功!");
							window.location.href=window.location.href
						}else{
							alert(resp.msg);
						}
					}
				});
			}
		}
		
		
		
	</script>
</head>
<body>
	<%@ include file="/commons/messages.jsp"%>
	<form id="queryForm" name="queryForm"
		action="${ctx}/procInstMgr/historyList.do" method="post"
		style="display: inline;">
		<div class="main-container" id="main-container">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h8>流程历史管理</h8>
				</div>
				<div class="panel-body">
					<div class="form-group well well-sm" style="margin-bottom: 2px;">

						<table border="0" cellspacing="0" cellpadding="0"
							class="table-search">
							<tr>
								<!-- <td>流程定义Key：</td>		
						<td>
							<input value="${query.processDefKey}" id="processDefKey" name="processDefKey" />
						</td>
						 -->
						<td>流程定义名称：</td>		
						<td>
							<input value="${query.processDefName}" id="processDefName" name="processDefName" />
						</td>
						<td>流程标题：</td>		
						<td>
							<input value="${query.title}" id="title" name="title" />
						</td>
						<td>流程实例ID：</td>		
						<td>
							<input value="${query.processInstanceId}" id="processInstanceId" name="processInstanceId" />
						</td>
						
							
								<td>
									<button type="submit" class="btn btn-xs btn-primary">查&nbsp;&nbsp;询
									<i class="ace-icon fa fa-search bigger-110"></i>
									</button>

								</td>	
					</tr>
					
							<tr>
						<td>创建人：</td>		
						<td>
							<input value="${query.userId}" id=userId name="userId" />
						</td>	
						
						<td>流程状态：</td>		
						<td>
							<select name="procState">
								<option value="">请选择</option>
								<option value="5" ${query.procState==5?"selected":""}>正常</option>
								<option value="3" ${query.procState==3?"selected":""}>作废</option>
							</select>
						</td>
						
					</tr>
					</tr>
							<tr>
								<td colspan="4">
									
									<button type="button" class="btn btn-xs btn-danger"
										onclick="processAction('${ctx}/procInstMgr/delete.do','您确认要删除该流程吗？删除流程后数据将无法恢复！');">
										删&nbsp;&nbsp;除
										<i class="ace-icon fa fa-trash-o bigger-110"></i></button>
									
									<button type="button" onclick="updateProcessComment('${ctx}/taskMgr/updateProcessCommentView.do');" class="btn btn-xs btn-primary">
										修改流转意见
										<i class="ace-icon fa fa-pencil-square-o bigger-110"></i>
									</button>
									<c:if test="${ebpmAdmin}">
									<button type="button" onclick="updateProcessTime('${ctx}/procInstMgr/updateProcessTimeView.do');" class="btn btn-xs btn-primary">
										修改流转时间
										<i class="ace-icon fa fa-pencil-square-o bigger-110"></i>
									</button>
									<button type="button" onclick="delProcessRoam('${ctx}/procInstMgr/delProcessRoamView.do');" class="btn btn-xs btn-primary">
											修改流程环节
										<i class="ace-icon fa fa-pencil-square-o bigger-110"></i>
									</button>
									</c:if>
									<button type="button" onclick="processRestore('${ctx}/procInstMgr/processRestore.do','您确认要恢复该流程吗？');" class="btn btn-xs btn-primary">
										流程恢复
										<i class="ace-icon fa fa-pencil-square-o bigger-110"></i>
									</button>						
									
								</td>
							</tr>

						</table>
					</div>
					<div class="row">
						<div class="col-xs-12" >
							<div class="table-responsive">
								<div style="width: 100%;overflow: auto;">
								<table   style=" width: inherit;max-width: 600%;table-layout: fixed;" id="sample-table-1"
									class="table table-striped table-bordered table-hover">
									<thead>
										<tr>
											<th style="width: 20px"></th>
											<th style="width: 150px;">流程定义名称</th>
											<th>流程标题</th>
											<th>流程实例ID</th>
											<th>创建人</th>
											<th style="width: 100px">发起时间</th>
											<th style="width: 100px">结束时间</th>
											<th style="width: 90px">持续时间</th>
											<th style="width: 90px">状态</th>
										</tr>
									</thead>
									<tbody>

										<%
											Page mypage = (Page) request.getAttribute("page");
											List<HistoricProcessInstanceEntity> histProcInsts = mypage
													.getResult();

											if (histProcInsts != null) {
												for (int i = 0; i < histProcInsts.size(); i++) {
													HistoricProcessInstanceEntity histProcInst = (HistoricProcessInstanceEntity) histProcInsts
															.get(i);
										%>
										<tr class="<%=((i + 1) % 2 == 0 ? "odd" : "even")%>">
											<td>
												<input type="radio" name="items" value="processInstanceId=<%=histProcInst.getId()%>">
											</td>
											<td class="td" title="<%=histProcInst.getProcessDefinitionName()%>&nbsp;">
												<%=histProcInst.getProcessDefinitionName()%>
											</td>
											<td class="td" title="<%=histProcInst.getProcTitle()%>&nbsp;">
												<a href="javascript:void(0);" onclick="openProcessTrackPage('${ctx}','<%=histProcInst.getId() %>');">
													<%=histProcInst.getProcTitle()%>&nbsp;
												</a>
											</td>
											<td class="td" title="<%=histProcInst.getId()%>"><%=histProcInst.getId()%></td>
											<td class="td">
												<%if(null != histProcInst.getStartUserName()){ %>
													<%=histProcInst.getStartUserName()%>(<%=histProcInst.getStartUserId()%>)
												<%}else{ %>
													<%=histProcInst.getStartUserId()%>
												<%} %>
											</td>
											<td class="td" title="<%=DateUtil.convertDateToString(histProcInst.getStartTime())%>">
												<%=DateUtil.convertDateToString(histProcInst.getStartTime())%>
											</td>
											<td class="td" title="<%=DateUtil.convertDateToString(histProcInst.getEndTime())%>">
												<%=DateUtil.convertDateToString(histProcInst.getEndTime())%>
											</td>
							
								<td>
									<span class="label label-default">耗时<%=com.blueland.bpm.manage.web.ProcessInstanceController.differByDay(histProcInst.getStartTime(),histProcInst.getEndTime())%>天</span>
								</td>
											<td>
												<%
													if (histProcInst.getProcState() == 5) {
												%><span class="label label-success">正常</span>
												<%
													} else if (histProcInst.getProcState() == 3) {
												%> <span
												class="label label-danger">作废</span> <%
 	}
 %>
											</td>
										</tr>
										<%
											}
											}
										%>
									</tbody>
								</table>
								</div>
					<simpletable:pageToolbar page="${page}">
					</simpletable:pageToolbar>
				</div>
				<!-- /.table-responsive -->
			</div>
			<!-- /span -->
		</div>
		</div>
		</div>

		</div>
	</form>
</body>
</html>

