<%@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>
	<script language="javascript" type="text/javascript" src="${ctx}/resource/js/plugins/My97DatePicker/WdatePicker.js"></script>
	<link href="${ctx}/resource/js/plugins/loadmask/jquery.loadmask.css" rel="stylesheet" type="text/css" />
	<script type='text/javascript' src='${ctx}/resource/js/plugins/loadmask/jquery.loadmask.js'></script>
	<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 =[];
			$("input[name='items']:checkbox:checked").each(function(){
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一条流程数据！");
				return;
			}else if(chk_value.length>1){
				alert("请选择一条流程数据！");
				return;
			}
			return chk_value[0];
		}
		function processAction(myUrl,title,id){

			var chk_value =[];
			var processInstanceId="";
			$("input[name='items']:checkbox:checked").each(function(){
				chk_value.push($(this).val());
			})
			if(chk_value.length==0){
				alert("请选择一条流程数据！");
				return;
			}else{
				for(var i=0;i<chk_value.length;i++){
					processInstanceId+=chk_value[i]+";";
				}
			}
			setMask("main-container");
			if (confirm(title)) {
				jQuery.ajax({
					url: myUrl,
					data: { "processInstanceId": processInstanceId},
					type: "POST",
					success: function(resp)
					{
						alert(resp);
						window.location.reload();
					}
				});
			}else{
				$("#main-container").unmask();
			}
		}
		function openSysDialog(ctx){
			var height1 = window.parent.document.documentElement.clientHeight;
			var height = (parseInt(height1)-45)+"px";
			showDiaLog(ctx,'流程配置','1400px',height);
		}
		function query(){
			setMask("main-container");
			document.getElementById("queryForm").submit();
		}
	</script>
</head>
<body>
<%@ include file="/commons/messages.jsp"%>
<form id="queryForm" name="queryForm" method="post" style="display: inline;" action="${ctx}/sysMgr/sysProcessInstList.do">
	<div class="main-container" id="main-container">
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h8>流程实例查询</h8>
			</div>
			<div class="panel-body" id="panel-body" style="padding:3px;">
				<div class="well well-sm" style="margin-bottom: 2px;">

					<table border="0" cellspacing="0" cellpadding="0"
						   class="table-search">
						<tr>
							<td>应用名称：</td>
							<td>
								<select name="appId">
									<option value="">--请选择--</option>
									<c:forEach items="${applicationList}" var="item">
										<option ${params.appId==item.appId?"selected":""} value="${item.appId }">${item.appName}</option>
									</c:forEach>
								</select>
							</td>
							<td>流程标题：</td>
							<td><input value="${params.title}" id="title" name="title" /></td>
							<td>流程实例ID：</td>
							<td><input value="${params.processInstanceId}" id="processInstanceId" name="processInstanceId" /></td>
							<c:if test="${params.toProcState == null || params.toProcState == ''}">
								<td>流程状态：</td>
								<td>
									<select name="procState">
										<option value="">--请选择--</option>
										<option ${params.procState=="1"?"selected":""} value="1">运行中</option>
										<option ${params.procState=="3"?"selected":""} value="3">作废</option>
										<option ${params.procState=="5"?"selected":""} value="5">已办结</option>
									</select>
								</td>
							</c:if>
							<c:if test="${params.toProcState != null && params.toProcState != ''}">
								<input value="${params.toProcState}" type="hidden" id="toProcState" name="toProcState" />
							</c:if>
							<td>
								<button type="submit" onclick="query()"class="btn btn-xs btn-primary">
									查询<i class="ace-icon fa fa-search bigger-110"></i>
								</button>
							</td>
						</tr>
						<tr>
							<td>创建人：</td>
							<td><input value="${params.userId}" id="userId" name="userId" /></td>
							<c:if test="${params.toSearchYear == null || params.toSearchYear == ''}">
								<td>创建年度：</td>
								<td><input value="${params.searchYear}" id="searchYear" name="searchYear" onClick="WdatePicker({dateFmt:'yyyy'})" autocomplete="off"/></td>
								<td>创建月份：</td>
								<td><input value="${params.searchMouth}" id="searchMouth" name="searchMouth" onClick="WdatePicker({dateFmt:'MM'})" autocomplete="off"/></td>
							</c:if>
							<td>流程定义名称：</td>
							<td>
								<input value="${params.processDefName}" id="processDefName" name="processDefName" />
							</td>

						</tr>
						<tr>
							<td colspan="6">
								<button type="button" id="cancel" onclick="processAction('${ctx}/procInstMgr/cancel.do','您确认要作废该流程吗？作废后的流程可在流程历史管理中查询到！',this.id);" class="btn btn-xs btn-danger">
									作废<i class="ace-icon fa fa-trash-o bigger-110"></i>
								</button>
								<c:if test="${isBpmAdmin}">
									<button type="button" id="delete" onclick="processAction('${ctx}/procInstMgr/delete.do','您确认要删除该流程吗？删除流程后数据将无法恢复！',this.id);" class="btn btn-xs btn-inverse">
										删除<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>
							</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"><input type="checkbox" onclick="setAllCheckboxState('items',this.checked)"></th>
										<th style="width: 150px">应用名称</th>
										<th>流程标题</th>
										<th style="width: 150px;">流程定义</th>
										<th>流程实例ID</th>
										<th style="width: 110px">流程状态</th>
										<th style="width: 150px">发起时间</th>
										<th style="width: 150px">办结时间</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="checkbox" name="items" value="<%=histProcInst.getId()%>"></td>
										<td class="td" title="<%=histProcInst.getTenantId()%>&nbsp;"><%=histProcInst.getTenantId()%>&nbsp;</td>
										<td class="td">
											<a href="javascript:void(0);" onclick="openProcessTrackPage('${ctx}','<%=histProcInst.getId() %>');">
												<%=histProcInst.getProcTitle()%>&nbsp;
											</a>
										</td>
										<td class="td">
											<a href="javascript:void(0);" onclick="openSysDialog('${ctx}/procDefMgr/config.do?procDefId=<%=histProcInst.getProcessDefinitionId() %>');">
												<%=histProcInst.getProcessDefinitionName()%>&nbsp;
											</a>
										</td>
										<td class="td" title="<%=histProcInst.getId()%>"><%=histProcInst.getId()%>&nbsp;</td>
										<td>
											<%if(histProcInst.getProcState()==1){%>
											<span class="label label-success">运行中</span>
											<%}else if(histProcInst.getProcState()==3){%>
											<span class="label label-warning">作废</span>
											<%}else if(histProcInst.getProcState()==5){%>
											<span class="label label-danger">已办结</span>
											<%}%>
										</td>
										<td><%=DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss", histProcInst.getStartTime()) %></td>
										<td><%=DateUtil.convertDateToString("yyyy-MM-dd HH:mm:ss", histProcInst.getEndTime()) %></td>
										<td>
											<%String day=com.blueland.bpm.manage.web.ProcessInstanceController.differByDay(histProcInst.getStartTime(),histProcInst.getEndTime());%>
											<%if(day == "" || day == null){%>

											<%}else if(Integer.parseInt(day)<=3){%>
											<span class="label label-success">耗时<%=day%>天</span>
											<%}else if(Integer.parseInt(day)<=10){%>
											<span class="label label-warning">耗时<%=day%>天</span>
											<%}else if(Integer.parseInt(day)>10){%>
											<span class="label label-danger">耗时<%=day%>天</span>
											<%}%>
										</td>
									</tr>
									<%}} %>
									</tbody>
								</table>
							</div>
							<simpletable:pageToolbar page="${page}"></simpletable:pageToolbar>

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

