<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.blueland.bpm.engine.core.model.*,org.activiti.engine.task.Comment,org.apache.commons.lang3.StringUtils,com.blueland.bpm.common.util.DateUtil,java.util.*"%>
<%@ include file="/commons/taglibs.jsp"%>
<jsp:include page="/commons/userOrgTreeMore.jsp" flush="true" />
<%
	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">
<%@ include file="/commons/meta.jsp"%>
<base href="<%=basePath%>">
<title>更新流程审批时间</title>
<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>
<script>
	function processAction(myUrl,title,id){
		var chk_value =[]; 
		var processInstanceId="";
		var list = new Array();
		$("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++){
				var model = {};
				model.actInstId = chk_value[i];
				if($("#"+chk_value[i]+"_finishTime").val()){
					model.finishTime = this.stringToDate($("#"+chk_value[i]+"_finishTime").val())
				}
				model.sendUserId = $("#"+chk_value[i]+"_sendUserId").val();
				model.sendUserName = $("#"+chk_value[i]+"_sendUserName").val();
				model.senderOrgId = $("#"+chk_value[i]+"_senderOrgId").val();
				model.senderOrgName = $("#"+chk_value[i]+"_senderOrgName").val();
				model.actState = $("#"+chk_value[i]+"_actState").val();
				if($("#"+chk_value[i]+"_createTime").val()){
					model.createTime = this.stringToDate($("#"+chk_value[i]+"_createTime").val())
				}else{
					alert("环节发送时间不能为空，请核查接收时间数据！");
					return;
				}
				list.push(model);
			}
		}
		console.log(JSON.stringify(chk_value))
		console.log(JSON.stringify(list))
		setMask("widget-box");
		if (confirm(title)) {
			jQuery.ajax({
				url: myUrl,
				data: JSON.stringify(list),
			    dataType: "json", //表示返回值类型，不必须
			    contentType : 'application/json;charset=utf-8', //设置请求头信息
				type: "POST",
				success: function(resp)
				{
					if(resp){
						alert("操作成功!");
						window.location.href=window.location.href
					}else{
						alert("操作失败！");
						$("#widget-box").unmask();
					}
				}
			});
		}else{
			$("#widget-box").unmask();
		}
	}
	
	
	function stringToDate(str){
	    var tempStrs = str.split(" ");
	    var dateStrs = tempStrs[0].split("-");
	    var year = parseInt(dateStrs[0], 10);
	    var month = parseInt(dateStrs[1], 10) - 1;
	    var day = parseInt(dateStrs[2], 10);
	    var timeStrs = tempStrs[1].split(":");
	    var hour = parseInt(timeStrs [0], 10);
	    var minute = parseInt(timeStrs[1], 10);
	    var second = parseInt(timeStrs[2], 10);
	    var date = new Date(year, month, day, hour, minute, second);
	    return date;
	}
	
	function updateProcessTime(myUrl,title,id){
		if($("#startTime").val()==""){
			alert("流程发起时间不能为空，请核查发起时间数据！");
			return;
		}
		setMask("widget-box");
		if (confirm(title)) {
			jQuery.ajax({
				url: myUrl,
				data: {"procInstId":$("#procInstId").val(),"createTime":$("#startTime").val(),"endTime":$("#endTime").val()},
			    dataType: "json", //表示返回值类型，不必须
				type: "POST",
				success: function(resp)
				{
					if(resp){
						alert("操作成功!");
						window.location.href=window.location.href
					}else{
						alert("操作失败！");
						$("#widget-box").unmask();
					}
				}
			});
		}else{
			$("#widget-box").unmask();
		}
	}
	function getUserFunOnDbClick(name,value,orgId,orgName,id) {
		$("#"+id+"_sendUserName").val(name);
		$("#"+id+"_sendUserId").val(value);
		$("#"+id+"_senderOrgId").val(orgId);
		$("#"+id+"_senderOrgName").val(orgName);
		//$("#deputeUserId").val(value);
	}
</script>
<body class="white-page">

	<form action="${ctx}/procInstMgr/updateProcessTimeView.do" method="post" id="myform">
		<div class="widget-box" id="widget-box">
			<%
				List<ProcessLogModel> processComments = (List) request.getAttribute("processComments");
			%>
			<input type="hidden" id="procInstId" name="procInstId" value="${procInstId}"></input>
			
			<span style="float:left;line-height:  33px;padding:0 0 0 10px">修改环节时间，备注：上一环节处理时间与下一环节发送时间一致</span>
			<input style='float: right;' type="button" class="btn btn-sm btn-primary" id="submitButton" onclick="processAction('${ctx}/procInstMgr/updateActInstTime.do','您确认修改勾选节点流程对应时间吗？',this.id);" value="保 存" />
			
			
			<!-- <input style='float: right;' type="button" class="btn btn-sm btn-primary" value="关 闭" onclick="art.dialog.close();" /> -->

			<div class="widget-body">
				<div class="row">
					<div class="col-xs-12">
						<div class="table-responsive">
							<table  style="max-width: 600%;table-layout: fixed;" id="sample-table-1"
								class="table table-striped table-bordered table-hover">
								<thead>
								  <tr>
									<!-- 排序时为th增加sortColumn即可,new SimpleTable('sortColumns')会为tableHeader自动增加排序功能; -->
									<th style="width:20px;"><input type="checkbox" onclick="setAllCheckboxState('items',this.checked)"></th>
									<th style="width: 150px">流程定义名称</th>
									<th>流程标题</th>
									<th style="width: 100px">执行人</th>
									<th style="width: 120px">当前环节</th>
									<th >发送人</th>
									<th >发送时间</th>
									<th >处理时间</th>
								  </tr>
								</thead>
								<tbody>
								 <c:forEach items="${allActivityInstance}" var="item" varStatus="status">
								 <tr class="${status.count % 2 == 0 ? 'odd' : 'even'}">
									<td><input type="checkbox" name="items" value="${item.actInstId}"></td>	
									<input type="hidden" id="${item.actInstId}_actState" name="${item.actInstId}_actState" value="${item.actState}"/></td>
									<td>${item.procDefName}&nbsp;</td>
									<td class="td" title="${item.procTitle}&nbsp;">${item.procTitle}&nbsp;</td>
									<td>${item.receiverUserName}&nbsp;</td>
									<td>${item.actDefName}&nbsp;</td>
									<%-- <td>${item.sendUserName}</td> --%>
									<td style="width: 100px"><input type="text" id="${item.actInstId}_sendUserName" name="${item.actInstId}_sendUserName" value="${item.sendUserName}" style="margin-right: 2px;height:25px;" onclick="showUserOrg('getUserFun','','','USER','${item.actInstId}','${item.actInstId}_sendUserName'); return false;" readonly />
										<input type="hidden" id="${item.actInstId}_sendUserId" name="${item.actInstId}_sendUserId" value="${item.sendUserId}"/></td>
										<input type="hidden" id="${item.actInstId}_senderOrgId" name="${item.actInstId}_senderOrgId" value="${item.senderOrgId}"/></td>
										<input type="hidden" id="${item.actInstId}_senderOrgName" name="${item.actInstId}_senderOrgName" value="${item.senderOrgName}"/></td>
									<td style="width: 100px">
										<input  class="input" value="<fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="${item.actInstId}_createTime" name="${item.actInstId}_createTime"   />					
									</td>
									<td style="width: 100px">
										<input  class="input"  value="<fmt:formatDate value="${item.finishTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="${item.actInstId}_finishTime" name="${item.actInstId}_finishTime"   />
									</td>
								  </tr>		
								 </c:forEach>  
								</tbody>
							</table>
						</div>
						<!-- /.table-responsive -->
					</div>
					<!-- /span -->
				</div>
			</div>
			<br />
			<br />
			<span style="float:left;line-height:  33px;padding:0 0 0 10px">修改流程时间</span>
			<input style="float:right" type="button" class="btn btn-sm btn-primary" id="submitButton" onclick="updateProcessTime('${ctx}/procInstMgr/updateProcessTime.do','您确认修改'+'${historicProcessInstance.procTitle}'+'时间么？',this.id);" value="保 存" />
			<div class="widget-body">
				<div class="row">
					<div class="col-xs-12">
						<div class="table-responsive">
							<table id="sample-table-1"
								   style="max-width: 600%;table-layout: fixed;"
								class="table table-striped table-bordered table-hover">
								<thead>
								  <tr>
									<!-- 排序时为th增加sortColumn即可,new SimpleTable('sortColumns')会为tableHeader自动增加排序功能; -->
									<th >流程定义名称</th>
									<th >流程标题</th>
									<!-- <th width="100px">流程实例ID</th> -->
									<th style="width: 100px">创建人</th>
									<th >发起时间</th>
									<th >结束时间</th>
								  </tr>
								</thead>
								<tbody>
								
								 <tr class="odd">
									<td class="td" title="${historicProcessInstance.processDefinitionName}">${historicProcessInstance.processDefinitionName}</td>
									<td class="td" title="${historicProcessInstance.procTitle}">${historicProcessInstance.procTitle}</td>
									<%-- <td>${historicProcessInstance.id}</td> --%>
									<td>${historicProcessInstance.startUserName}</td>
									<td style="width: 150px">
										<input  class="input"  value="<fmt:formatDate value="${historicProcessInstance.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="startTime" name="startTime"   />
									</td>
									<td style="width: 150px">
										<input  class="input" value="<fmt:formatDate value="${historicProcessInstance.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="endTime" name="endTime"   />
									</td>
								  </tr>
								  
								</tbody>
							</table>
						</div>
						<!-- /.table-responsive -->
					</div>
					<!-- /span -->
				</div>
			</div>
		</div>
	</form>
</body>
</html>