  <%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.blueland.bpm.engine.config.model.*" %>
<%@ include file="/commons/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%-- <jsp:include page="deputeUserTree.jsp" flush="false" /> --%>
<%
	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">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="overview &amp; stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/bootstrap.min.css" />
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/font-awesome.min.css" />

<!-- text fonts -->
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/ace-fonts.css" />
<!-- ace styles -->
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/ace.min.css" id="main-ace-style" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/ace-part2.min.css" />
<![endif]-->
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/ace-skins.min.css" />
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/ace-rtl.min.css" />
<!--[if lte IE 9]>
<link rel="stylesheet" href="${ctx }/resource/js/plugins/ace/css/ace-ie.min.css" />
<!-- page specific plugin styles -->
<link rel="stylesheet" href="${ctx }/resource/css/global.css" />
<script type="text/javascript" src="${ctx }/resource/js/jquery-1.8.3.min.js"></script>
<script src="<c:url value="/resource/js/common/application.js"/>" type="text/javascript"></script>
<script src="<c:url value="/resource/js/plugins/My97DatePicker/WdatePicker.js"/>" type="text/javascript"></script>	
<script src="${ctx }/resource/js/plugins/artDialog/jquery.artDialog.js?skin=blue"></script>
<script src="${ctx }/resource/js/plugins/artDialog/iframeTools.source.js"></script>
<!-- validation BEGIN-->
<link rel="stylesheet" href="${ctx }/resource/js/plugins/Validform_v5.3.2/Validform_v5.3.2/demo/css/style.css" />
<script type="text/javascript" src="${ctx }/resource/js/plugins/Validform_v5.3.2/Validform_v5.3.2_min.js"></script>
<!-- validation END-->

<base href="<%=basePath%>">
<style>
.ztree li span {
    line-height: 16px;
    margin-right: 2px;
    font-size: 12px;
    color: #333;
    font-family: "微软雅黑";
}
.btn-style{
	border: 1px #89a0b9 solid;
    border-radius: 4px;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%,from(#fefefe), to(#dce2e6));
    padding: 0px 15px;
    color: #000;
    font-size: 12px;
    font-family:"微软雅黑";
    letter-spacing: 4px;
	}
.btn-style:hover{
	background:#e1f0f8;
	cursor:pointer;
	}
</style>
<link rel="stylesheet"
	href="${ctx}/resource/js/plugins/zTree/css/demo.css"
	type="text/css">
<link rel="stylesheet"
	href="${ctx}/resource/js/plugins/zTree/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.core-3.4.js"></script>
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.excheck-3.4.js"></script>
<script type="text/javascript"
	src="${ctx}/resource/js/plugins/zTree/js/jquery.ztree.exedit-3.4.js"></script>
<link rel="stylesheet" href="${ctx}/resource/js/plugins/userSelect/css/usStyle/button.css" type="text/css">
<script>
	$(function(){
		//初始化委托人
		$.fn.zTree.init($("#treeObj"), createUserSetting());
	});
	function createUserSetting(){
			var setting = {
					view: {
						dblClickExpand: false,
						expandSpeed: "slow",
						selectedMulti: false
					},
					data: {  
				        simpleData: {  
				            enable : true,  
				            idKey : "id",  
				            pIdKey : "pId" ,
				            DIY:"isAccessTopMenu"
				        }  
				    },async: {
						enable: true,
						url:"${ctx}/pages/user/getUserOrgTree.do",
						autoParam:["id", "name=n","level=lv"],
				    	otherParam:{"assignTreeId":"${user.orgId}","treeLevel":"","showTreeType":"USER","filterNodeIdsStr":"${user.userId}","ischecked":"0","isCheckValue":"${existDepute.mandataryUserId}"}
					},				
					check: {
						enable: true,
						chkStyle: "radio"
					},
					callback: {
						onAsyncSuccess: onAsyncSuccess,
						onCheck:onUserCheck												
					}
				};
			return setting;
		}
	
	
	function onUserCheck(event, treeId, treeNode) {
		if(null == treeNode){
			return ;
		}	
		
		if("USER" == treeNode.type){
			$("#mandataryUserId").val(treeNode.id);
			$("#mandataryUserName").val(treeNode.name);
			return true;
		}else{
			return false;
		}
	}
	function onAsyncSuccess(event, treeId, treeNode, msg) {
		var msgArr=$.parseJSON(msg);
		
		for(var i  = 0;i<msgArr.length;i++){
			if(msgArr[i].checked){
				$("#mandataryUserId").val(msgArr[i].id);
				$("#mandataryUserName").val(msgArr[i].name);
			}
		}
		
	}
	
	function saveDepute(){
		var ischeck = checkBeforeSubmit();
		if(ischeck){
			$.post('${ctx}/depute/save.do',
					$('#editForm').serialize(),
			function(result){
				if(result.success){
					alert("保存成功！");
					art.dialog.opener.location.reload();
				}else{
					alert("保存失败！");
				}
			});
		}
	}
	
	function checkBeforeSubmit(){
		var mandataryUserId = $("#mandataryUserId").val();
		if(null == mandataryUserId || ""==mandataryUserId){
			alert("请您选择被委托人员！");
			$("#mandataryUserName").focus();
			return false;
		}
		
		return true;
	}
	
 	function resetDepute(){
 		if(confirm("您确定要重新设置委托待办吗？")){
	 		$.post('${ctx}/depute/reSetDeputeBack.do',
					$('#editForm').serialize(),
			function(result){
				if(result.success){
					alert("重置成功！");
					art.dialog.opener.location.reload();
				}else{
					alert("重置失败！");
				}
			});
 		}
 	}

</script>
<title>新增委托代办</title>
</head>
<body style="font-size: 13px;" class="white-page">
	<form action="${ctx}/depute/save.do" method="post" id="editForm">
	<input type="hidden" name="deputeUserId" value="${user.userCode}" id="deputeUserId" />
	
		<input type="hidden" name="deputeUserName" value="${user.userName}" id="deputeUserName" />
		<input type="hidden" name="deputeStatus" value="Y" id="deputeStatus" />
<%-- 		<input type="hidden" name="appId" value="${application.appId}" id="appId" /> --%>
<%-- 		<input type="hidden" name="appName" value="${application.appName}" id="appName" /> --%>
		<div class="main-container" id="main-container">
			<div id="tabs" style="border-bottom: 1px solid #e5e5e5;font-weight: bold;margin: 0px;padding: 7px 10px 5px 20px;">
  				<span  style="padding:20px;border-bottom: 2px #70c5e1 solid;padding: 0px 2px 7px 2px;font-size: 12px;font-family: &quot;微软雅黑&quot;;color: #000;">可视化流程中心->委托代办设置</span>
			</div>
			<div class="alert alert-block alert-danger" style="margin: 5px 0px 0px 20px;color: #ff0000;padding: 5px;font-size: 12px;font-family: '微软雅黑'; border: none;background: none;">
	           <i class="ace-icon fa fa-exclamation-triangle yellow"></i> <span class="yellow bolder"></span> 
	           <c:choose>
		           	<c:when test="${'' != existDepute.mandataryUserName && null != existDepute.mandataryUserName}">	
<%-- 		           		<c:choose> --%>
<%-- 		           			<c:when test="${'local' == existDepute.deputeType}">	 --%>
		           					
<%-- 								委托记录：您于<fmt:formatDate  value="${existDepute.createTime }"  pattern="yyyy年MM月dd日" />将${deputeStr }的所有流程都委托给了${existDepute.mandataryUserName }！					 --%>
<%-- 							</c:when> --%>
<%-- 							<c:otherwise> --%>
							当前委托记录：您于<lable style="font-weight:bold;"><fmt:formatDate  value="${existDepute.createTime }"  pattern="yyyy年MM月dd日" /></lable>将可视化流程中心的所有流程都委托给了<lable style="font-weight:bold;">${existDepute.mandataryUserName }</lable>！
							取消委托关系请点击重置按钮！
<%-- 							</c:otherwise> --%>
<%-- 						</c:choose> --%>
					</c:when>
					<c:otherwise>您当前暂无委托记录！</c:otherwise>
				</c:choose>
	         </div>
			<div class="panel panel-primary" style=" border: none;padding: 0px 10px 5px 20px;margin-bottom: 10px;">
			
				<div class="panel-body">
					
					<div   style="width:100%;height:250px;">
						<table class='table table-bordered form-table' border="0" cellspacing="0"
								cellpadding="0" id="myTable1" height="100%">
						
							<tr style="height:30px;background: #E4EDF6;">
								<td style="border-left:none;border-bottom:none;color: #333;padding: 5px 0px 5px 15px;font-weight:bold;font-size: 12px;color: #333;font-family: &quot;微软雅黑&quot;">被委托人选择</td>
							</tr>
							<tr>
								<td style="border-top:none;padding: 2px 0px;"><input  type="hidden" name="mandataryUserName" readonly
								value="请选择" id="mandataryUserName"/>
								<input type="hidden" name="mandataryUserId" value="" id="mandataryUserId" />
								<div id="menuContent" class="menuContent" style="height:100%;">
										<ul id="treeObj" class="ztree" style="margin: 0px 0px 0px 8px; width: 500px;height: auto;max-height: 230px;border:none;background: none;overflow:auto;"></ul>
								</div>
								</td>
							</tr>
						</table>	
					</div>
									
				</div>
				
			</div>
			
		</div>
		<div class="col-md-offset-1 col-md-9" style="text-align: center;margin-top: 20px;">
						<button id="submitButton" name="submitButton" 
						 class="btn-style" 
						type="button" onclick="saveDepute();">
							保存
						</button>
						<label style="padding: 0px 13px 0px 0px;"></label>
						<button type="button" class="btn-style"
						onclick="resetDepute();">
							重置
						</button>
					</div>
	</form>
</body>
</html>