<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>备用金申请管理</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/layer-v2.3/laydate/laydate.js"></script>
	<script type="text/javascript">
		var validateForm;
		function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $("#inputForm").submit();
			  return true;
		  }
	
		  return false;
		}
		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
                    var len = $("#showPeo span").length;
                    if(len<=0){
                        parent.layer.msg("请选择审批人!",{icon:5});
                        return false;
                    }
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});

        function selectPeople(objId,objName){
            var currentUser = '${fns:getUser().id}';
            if(currentUser==objId){
                parent.layer.msg("不能选择自己为审批人!",{icon:5});
                return false;
            }
            var showPeo = $("#showPeo").html();
            var len = $("#showPeo span").length;
            if(len > 4){
                parent.layer.msg("最多添加5个审批人",{icon:5});
                return;
            }
            var arr = [];
            var a = $("#showPeo span").each(function(){
                var dataId = $(this).attr("data-id");
                arr.push(dataId)
            })
            if(arr.indexOf(objId) != -1){
                parent.layer.msg("该审批人已被选择，不能重复选择！！！",{icon:5})
                return ;
            }
            showPeo = showPeo + '<span class="badge badge-success fontSpan" data-id="'+objId+'">'+objName+'&nbsp;&nbsp;&nbsp;' +
                '<i onclick=deletePeo(this) class="fa fa-close"></i><input type="hidden" name=adds['+len+'] value="'+objId+'"></span>';
            $("#showPeo").html(showPeo)
        }
        function deletePeo(obj){
            $(obj).parent().remove()
        }
	</script>
</head>
<body class="gray-bg">

<div class="wrapper wrapper-content">
	<div class="ibox">
		<c:if test="${sessionScope.state!='disabled'}">
			<div class="ibox-title" style="height: 70px;">
				<h5>
					<ul class="nav nav-tabs">
						<li><a href="${ctx}/workpettycash/workPettyCash/list">备用金申请信息</a></li>
						<li><a href="${ctx}/workpettycash/workPettyCash/workPettyCashTodoList">待办任务</a></li>
						<li><a href="${ctx}/workpettycash/workPettyCash/workPettyCashHistoricList">已办任务</a></li>
						<shiro:hasPermission name="workpettycash:workPettyCash:edit"><li class="active"><a href="${ctx}/workpettycash/workPettyCash/form?ids=0">备用金申请</a></li></shiro:hasPermission>
					</ul>
				</h5>
				<%--<div class="ibox-tools">
					<a class="collapse-link">
						<i class="fa fa-chevron-up"></i>
					</a>
					<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
						<i class="fa fa-wrench"></i>
					</a>
					<ul class="dropdown-menu dropdown-user">
						<li><a href="javascript:void(0)">选项1</a>
						</li>
						<li><a href="javascript:void(0)">选项2</a>
						</li>
					</ul>
					<a class="close-link">
						<i class="fa fa-times"></i>
					</a>
				</div>--%>
			</div>
		</c:if>
		<div class="ibox-content">
			<form:form id="inputForm" modelAttribute="workPettyCash" action="${ctx}/workpettycash/workPettyCash/save" method="post" class="form-horizontal">
				<form:hidden path="id"/>
				<c:set var="id" value="${workPettyCash.id}" />
				<c:set var="ids" value="${workPettyCash.ids}" />
				<sys:message content="${message}"/>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>申请人：</label>
					<div class="controls">
						<input id="applicantName" name="applicantName" type="text" style="width: 240px;" class="form-control required"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">申请部门：</label>
					<div class="controls">
						<sys:treeselect id="applicantOffice" name="applicantOffice.id" value="${workPettyCash.applicantOffice.id}" labelName="applicantOffice.name" labelValue="${workPettyCash.applicantOfficeName}"
										title="部门" url="/sys/office/treeDataAll?type=2" cssClass="form-control" allowClear="true" notAllowSelectParent="true"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>事由：</label>
					<div class="controls">
						<form:textarea path="reason" class="form-control required" rows="3" maxlength="20"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>申请金额(元)：</label>
					<div class="controls">
						<input id="amount" name="amount" type="text" class="form-control required number" value="${workPettyCash.amount}"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>使用日期：</label>
					<div class="controls">
						<input class="form-control layer-date laydate-icon required" id="useDate" name="useDate" readonly="readonly" value="<fmt:formatDate value="${workPettyCash.useDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>归还日期：</label>
					<div class="controls">
						<input class="form-control layer-date laydate-icon required" id="returnDate" name="returnDate" readonly="readonly" value="<fmt:formatDate value="${workPettyCash.returnDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">出纳：</label>
					<div class="controls">
						<input id="casherName" name="casherName" type="text" style="width: 240px;" class="form-control"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">备注：</label>
					<div class="controls">
						<form:textarea path="remarks" class="form-control" rows="3" maxlength="20"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<c:if test="${empty id}">
					<div class="control-group">
						<label class="control-label"><font color="red">*</font>审批人：</label>
						<div id="addida" class="controls">
							<sys:treeselectleave id="ida" name="ida" value="" labelName="" labelValue=""
											title="审批人" url="/sys/office/treeDataAll?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
							<span class="help-inline"></span>
						</div>
						<div id="showPeo" class="controls">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"><font color="red">*</font>抄送人：</label>
						<div id="CCid" class="controls">
							<sys:treeselect id="CCid" name="CCid" value="" labelName="" labelValue=""
											title="抄送人" url="/sys/office/treeDataAll?type=3&isAll=false" cssClass="form-control required" allowClear="true" checked="true" notAllowSelectParent="true"/>
							<span class="help-inline"></span>
						</div>
					</div>
					<c:if test="${not empty ids}">
						<div class="form-actions">
							<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
							<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
						</div>
					</c:if>
				</c:if>
			</form:form>
		</div>
	</div>
</div>
<%
	session.removeAttribute("state");
%>

</body>
</html>