<%@ 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"%>
<%
	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>
	var checkAct={};
	var createTime="";
	function delProcessAction(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];
				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 setProcessActInfo(prevActInstId,prevActDefName,sendUserId,sendUserName,sendOrgId,sendOrgName,prevActDefId,createTime){
		this.checkAct={};
		$('#addTd').remove();
		this.checkAct.prevActInstId=prevActInstId;
		this.checkAct.prevActDefName=prevActDefName;
		this.checkAct.sendUserId=sendUserId;
		this.checkAct.sendUserName=sendUserName;
		this.checkAct.senderOrgId=sendOrgId;
		this.checkAct.senderOrgName=sendOrgName;
		this.checkAct.prevActDefId=prevActDefId;
		this.checkAct.createTime= this.stringToDate(createTime);
		this.createTime=createTime;
		this.addTr()
	}
	function addTr(){
		var trHtml= "<tr class='odd' id='addTd'>";
		trHtml=trHtml+"<td><input type='text' id='actInstId' name='actInstId' value=''></td>";
		trHtml=trHtml+"<td>"+checkAct.prevActDefName+"</td>";
		trHtml=trHtml+"<td>"+checkAct.sendUserName+"</td>";
		trHtml=trHtml+"<td> "+createTime+"</td>"
		trHtml=trHtml+"</tr>";

		$("#delTable tbody").append(trHtml);
	}
	function updateFun(myUrl,title){
		var list = new Array();
		if(this.checkAct.prevActInstId!=undefined){
			this.checkAct.actInstId = $("#actInstId").val();
			if(this.checkAct.actInstId==null||this.checkAct.actInstId==""){
				alert("指定环节实例ID不能为空");
				return;
			}else{
				list.push(this.checkAct);
				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();
				}
			}

		}else{
			alert("请选择要修改的环节！");
		}

	}
</script>
<body style="background-color: white;">

<form action="${ctx}/procInstMgr/delProcessRoamView.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="delProcessAction('${ctx}/procInstMgr/delActInst.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 >环节实例ID</th>
								<th >流程标题</th>
								<th >执行人</th>
								<th >当前环节</th>
								<th >发送人</th>
								<th style="width: 150px">发送时间</th>
								<th style="width: 150px">处理时间</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>
									<td class="td" title="${item.actInstId}">
										<a style="cursor: pointer" onclick="setProcessActInfo('${item.actInstId}','${item.actDefName}','${item.receiverUserId}',
												'${item.receiverUserName}','${item.receiverOrgId}','${item.receiverOrgName}','${item.actDefId}','<fmt:formatDate value="${item.finishTime}" pattern='yyyy-MM-dd HH:mm:ss'/>')">
												${item.actInstId}
										</a>
									</td>
									<td class="td" title="${item.procTitle}">${item.procTitle}&nbsp;</td>
									<td class="td" title="${item.receiverUserName}">${item.receiverUserName}&nbsp;</td>
									<td class="td" title="${item.actDefName}">${item.actDefName}&nbsp;</td>
									<td>${item.sendUserName}</td>
									<td>
										<fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
									</td>
									<td>
										<fmt:formatDate value="${item.finishTime}" pattern="yyyy-MM-dd HH:mm:ss"/>

									</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">修改环节，基于上表选中的环节实例ID的执行数据修改指定环节的发送数据</span>
		<input style='float: right' type="button" class="btn btn-sm btn-primary" id="submitButton" onclick="updateFun('${ctx}/procInstMgr/updateActInst.do','您确认修改该环节吗？');" value="修改" />
		<div class="widget-body">
			<div class="row">
				<div class="col-xs-12">
					<div class="table-responsive">
						<table
								style="max-width: 600%;table-layout: fixed;"
								class="table table-striped table-bordered table-hover" id="delTable">
							<thead>
							<tr>
								<!-- 排序时为th增加sortColumn即可,new SimpleTable('sortColumns')会为tableHeader自动增加排序功能; -->
								<th >指定环节实例ID</th>
								<th >发送环节</th>
								<!-- <th width="100px">流程实例ID</th> -->
								<th >发送人</th>
								<th style="width: 150px">发送时间</th>
							</tr>
							</thead>
							<tbody>
							<tr></tr>

							</tbody>
						</table>
					</div>
					<!-- /.table-responsive -->
				</div>
				<!-- /span -->
			</div>
		</div>
	</div>
</form>
</body>
</html>