<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>通用审批功能管理</title>
	<meta name="decorator" content="default"/>
	<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);
					}
				}
			});
            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
		});
        function selectPeople(objId,objName){
            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()
        }
        function insertTitle(tValue){
            var files = $("#attachment_file")[0].files;
            for(var i = 0;i<files.length;i++) {
                var file = files[i];
            var attachmentId = $("#id").val();
            var attachmentFlag = "5";
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workClientInfo/"+timestamp+"/"+file['name'];
            var uploadPath="http://gangwan-app.oss-cn-hangzhou.aliyuncs.com/"+storeAs;/*将这段字符串存到数据库即可*/
            var divId = "_attachment";
            $("#addFile"+divId).show();
            multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,"0");
        }}

	</script>
</head>
<body class="hideScroll">
<div class="wrapper wrapper-content">
<div class="ibox">
	<div class="ibox-title" style="height: 70px;">
		<h5>
			<ul class="nav nav-tabs">
				<li><a href="${ctx}/oaall/oaAll/list">通用审批信息</a></li>
				<li><a href="${ctx}/oaall/oaAll/leaveTodoList">待办任务</a></li>
				<li><a href="${ctx}/oaall/oaAll/leaveHistoricList">已办任务</a></li>
				<li class="active"><a href="${ctx}/oaall/oaAll/form">通用审批申请</a></li>
			</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>

		</div>--%>
	</div>

	<div class="ibox-content">
		<form:form id="inputForm" modelAttribute="oaAll" action="${ctx}/oaall/oaAll/save" method="post" class="form-horizontal">
			<form:hidden path="id"/>
			<sys:message content="${message}"/>
			<div class="control-group">
				<label class="control-label"><font color="red">*</font>申请内容：</label>
				<div class="controls">
					<textarea id="applyContent" name="applyContent" maxlength="20" class="form-control required" rows="3" aria-required="true"></textarea>
					<span class="help-inline"></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label"><font color="red">*</font>审批详情：</label>
				<div class="controls">
					<textarea id="approveDetail" name="approveDetail" maxlength="20" class="form-control required" rows="3" aria-required="true"></textarea>
					<span class="help-inline"></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">附件：</label>
				<div class="controls">
					<div style="display: inline-block">
						<div id="addFile_attachment" style="display: none">
							<span id="fileName_attachment" ></span>
							<b><span id="baifenbi_attachment" ></span></b>
							<div class="progress">
								<div id="jindutiao_attachment" class="progress-bar" style="width: 0%" aria-valuenow="0">
								</div>
							</div>
						</div>
                        <input id="attachment_file" type="file" name="attachment_file" multiple="multiple" style="display: none;" onChange="if(this.value)insertTitle(this.value);"/>
						<a id="attachment_btn" class="btn btn-info btn-xs" ><i class="fa fa-plus"></i> 添加附件</a>
						<span id="attachment_title"></span>
					</div>
					<br><br>
					<table id="upTable" class="table table-striped table-bordered table-condensed">
						<thead>
						<tr>
							<th class="hide"></th>
							<%--<th>序号</th>--%>
							<th>文件名</th>
							<th>上传人</th>
							<th>上传时间</th>
							<th width="100">操作</th>
						</tr>
						</thead>
						<tbody id="file_attachment">
						</tbody>
					</table>
					<span class="help-inline"></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">抄送人：</label>
				<div id="CCId" class="controls">
					<sys:treeselect id="CCId" name="CCId" value="${leave.CCId}" labelName="idNames" labelValue="${leave.idNames}"
									title="用户" url="/sys/office/treeDataAll?type=3&isAll=false" cssClass="form-control required" notAllowSelectParent="true" checked="true"/>
					<span class="help-inline"></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">审批人：</label>
				<div id="addida" class="controls">
					<sys:treeselectleave id="ida" name="ida" value="${leave.ida}" labelName="idNamea" labelValue="${leave.idNamea}"
										 title="用户" url="/sys/office/treeDataAll?type=3&isAll=false" cssClass="form-control" notAllowSelectParent="true"/>
					<span class="help-inline"></span>
				</div>
				<div id="showPeo" class="controls">
				</div>

			</div>
			<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>
		</form:form>
	</div>
</div>
</div>
</body>
</html>