<%@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 ajaxSubmitTest(procInstId) {
				setMask("panel-body");	
				var url = "${ctx}/workflow/getActInst.do?procInstId="+procInstId;
                $.ajax({
                    type: "get",
                    url: url, //Servlet请求地址
            		async: true,
                    dataType: "json",
                    success: function (data) {
    					$(".children").remove();
                    	var List = data; 
        				for(var procInst in List){
        					var timeStr = "";
        					if(parseInt(List[procInst].TIMENUM) < 1000){
        						timeStr = "耗时"+parseInt(List[procInst].TIMENUM) +"毫秒";
        					}else if(parseInt(List[procInst].TIMENUM)/1000 < 60){
        						timeStr = "耗时"+Math.round(parseInt(List[procInst].TIMENUM)/1000) +"秒";
        					}else if (parseInt(List[procInst].TIMENUM)/(1000 * 60) < 60){
        						timeStr = "耗时"+Math.round(parseInt(List[procInst].TIMENUM)/(1000 * 60)) +"分钟";
        					}else if(parseInt(List[procInst].TIMENUM)/(1000 * 60 * 60) < 24){
        						timeStr = "耗时"+Math.round(parseInt(List[procInst].TIMENUM)/(1000 * 60 * 60)) +"小时";
        					}else{
        						timeStr = "耗时"+Math.round(parseInt(List[procInst].TIMENUM)/(1000 * 60 * 60 * 24)) +"天";
        					}
        					var showContent = "";//添加内容变量
        					showContent += "<tr class='children'>";
        	                showContent += "<td style='padding-left:50px'>"+List[procInst].ACTNAME+"</td>";
        	                showContent += "<td>"+List[procInst].SENDUSERNAME+"</td>";
        	                showContent += "<td>"+List[procInst].SENDORGNAME+"</td>";
        	                showContent += "<td>"+List[procInst].STARTTIME+"</td>";
        	                showContent += "<td>"+List[procInst].ENDTIME+"</td>";
        	                showContent += "<td><span class='label label-warning'>"+timeStr+"</span></td>";
        	                showContent += "</tr>";
        	                $("#"+procInstId).after(showContent);
        				} 
    					$(".loadmask").remove();
    					$(".loadmask-msg").remove();
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(errorThrown);
                        console.info("数据请求异常 请查看控制台错误 或者检查servlet配置")
                    }
                });
            }
		</script>
	</head>
	<body>
		<%@ include file="/commons/messages.jsp"%>
		<form id="queryForm" name="queryForm" method="post" style="display: inline;" action="${ctx}/workflow/proInstDetail.do">
			<div class="panel-body" id="panel-body" style="padding:3px;">
				<div class="row">
					<div class="col-xs-12">
						<div class="table-responsive">
							<table id="sample-table-1" class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th width="200px">流程标题</th>
										<th width="140px">发起人</th>
										<th width="150px">发起部门</th>
										<th width="100px">发起时间</th>
										<th width="100px">办结时间</th>
										<th width="70px">持续时间</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") %>" id="<%=histProcInst.getProcessInstanceId()%>" onclick="ajaxSubmitTest('<%=histProcInst.getProcessInstanceId()%>')">
											<td>
												<a href="javascript:void(0);" onclick="openProcessTrackPage('${ctx}','<%=histProcInst.getId() %>');">
													<%=histProcInst.getProcTitle()%>&nbsp;
												</a>
											</td>
											<td><%=histProcInst.getStartUserName()%>&nbsp;</td>
											<td><%=histProcInst.getStarterOrgName()%>&nbsp;</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.differByTime(histProcInst.getStartTime(),histProcInst.getEndTime());%>
												<%if(histProcInst.getEndTime() != null){%>
													<span class="label label-success">耗时<%=day%>分钟</span>
												<%}%>
											</td>
										</tr>		  
									<%}} %>
								</tbody>
							</table>
							<simpletable:pageToolbar page="${page}"></simpletable:pageToolbar>
						</div>
					</div>
				</div>
			</div>
		</form>
	</body>
</html>

