<%@ 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>
	<style type="text/css">
		img{width: 50px;height: 50px;}
	</style>
	<script type="text/javascript">
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }

            return false;
        }
        $(document).ready(function() {
            $("#name").focus();
            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);
                    }
                }
            });
            //只做查看时，禁用掉以下标签
            if('${sessionScope.state}' =='disabled'){
                $('input,textarea,select').attr('disabled','<%=session.getAttribute("state")%>');
            }else if('${sessionScope.state}' !='disabled'){
                $('input,textarea,select').removeAttr('disabled');
            }
        });
        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()
        }
	</script>
	<script type="text/javascript">
        //上传图片
        function this_upload_image_button(index){
            var length = $("#this_upload_image_div :file").length;
            var this_item_id = 'this_upload_image_'+index;
            var last_item_id = $('img[id^=this_upload_image_]:last').attr('id');
            if(length==6 && this_item_id==last_item_id){
                top.layer.alert('最多上传5张图片',{icon:0,title:'系统提示'});
                return;
            }
            $("#this_upload_file_"+index).click();
        }
        function this_upload_show_image(index){
            var obj =$("#this_upload_file_"+index)[0].files[0];
            var fileType = obj.type;
            var url ;
            if(fileType.endsWith("png")||fileType.endsWith("bmp")||fileType.endsWith("jpg")||fileType.endsWith("jpeg")){
                url = window.URL.createObjectURL(obj);
            }else {
                //需要置空
                var file = $("#this_upload_file_"+index);
                file.after(file.clone().val(""));
                file.remove();
                top.layer.alert('请上传*.png,*.bmp,*.jpg/jpeg格式的图片',{icon:0,title:'系统提示'});
                return false ;
            }
            $("#this_upload_image_"+index).attr("src",url);
            var length = $("#this_upload_image_div :file").length;
            var this_item_id = 'this_upload_image_'+index;
            var last_item_id = $('img[id^=this_upload_image_]:last').attr('id');
            if( this_item_id==last_item_id &&  length < 6 ){
                this_upload_image_append(index);
                this_add_x(index);
            }
        }
        function this_upload_image_append(index){
            var div1 = "<div id='this_upload_div_"+(index+1)+"' style='float:left;position:relative;width: 57px;height: 57px;'>";
            var img = '<img  id="this_upload_image_'+(index+1)+'" class="upload_ico" width="50px" height="50px"  onclick="this_upload_image_button('+(index+1)+')" src = "${pageContext.request.contextPath}/static/uploadify/upload_ico.png" style="cursor:pointer;"/>';
            var input = '<input id="this_upload_file_'+(index+1)+'" type="file" style="display:none;" name="this_upload_files" onChange="this_upload_show_image('+(index+1)+')" /><br>';
            var div2 = "</div>";

            $("#this_upload_image_div").append(div1+img+input+div2);
        }
        function this_close_img(index) {
            $("#this_upload_div_"+index).remove();
            var length = $("#this_upload_image_div :file").length;
            if(length == 0){
                this_add_div();
            }else if(length == 1){
                var x = $("#this_upload_image_div").find("span").text();
                if("x" != x){
                    this_add_div();
                }
            }
        }
        function this_add_x(index) {
            var span = '<span id="this_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;z-index:1;color: red;" onclick="this_close_img('+index+');">x</span>';
            $("#this_upload_image_div").find("img:eq(-2)").before(span);
        }
        function this_add_div() {
            var this_upload_div_1 =
                '<div id="this_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;" >'+
                '<img  id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.png"  onclick="this_upload_image_button(1)"/>'+
                '<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)" /><br>'+
                '</div>';
            $("#this_upload_image_div").html("").append(this_upload_div_1);
        }


	</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}/workovertimeform/workOvertimeForm/list">加班信息</a></li>
					<li><a href="${ctx}/workovertimeform/workOvertimeForm/workOvertimeTodoList">待办任务</a></li>
					<li><a href="${ctx}/workovertimeform/workOvertimeForm/workOvertimeHistoricList">已办任务</a></li>
					<shiro:hasPermission name="workovertimeform:workOvertimeForm:edit"><li class="active"><a href="${ctx}/workovertimeform/workOvertimeForm/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="workOvertimeForm" action="${ctx}/workovertimeform/workOvertimeForm/save" enctype="multipart/form-data" method="post" class="form-horizontal">
				<form:hidden path="id"/>
				<c:set var="id" value="${workOvertimeForm.id}" />
				<c:set var="ids" value="${workOvertimeForm.ids}" />
				<sys:message content="${message}"/>
				<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="startTime" name="startTime" readonly="readonly" value="<fmt:formatDate value="${workovertimeform.startTime}" 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="endTime" name="endTime" readonly="readonly" value="<fmt:formatDate value="${workovertimeform.endTime}" 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 id="longTime" name="longTime" type="text" class="form-control required" value="${workOvertimeForm.longTime}"/>
						<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">
						<form:select path="isHolidays" class="form-control ">
							<form:options items="${fns:getDictList('is_holidays')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">图片：</label>
					<div class="controls">
						<span id="this_upload_msg">请上传*.png,*.bmp,*.jpg/jpeg格式的图片</span><br>
						<div id="this_upload_image_div">
							<div id="this_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;">
								<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.png"  onclick="this_upload_image_button(1)"/>
								<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)"  class="form-control required"/><br>
							</div>
						</div>


						<span class="help-inline"></span>
					</div>
				</div>
				<c:if test="${empty id}">
					<div class="control-group">
						<label class="control-label">抄送人：</label>
						<div id="CCId" class="controls">
							<sys:treeselect id="CCId" name="CCId" value="${workOvertimeForm.CCId}" labelName="idNames" labelValue="${workOvertimeForm.idNames}"
											title="用户" url="/sys/office/treeDataAll?type=3&isAll=false" cssClass="form-control" allowClear="true" checked="true" notAllowSelectParent="true"/>
							<span class="help-inline"></span>
						</div>
					</div>
					<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="${workOvertimeForm.ida}" labelName="idNamea" labelValue="${workOvertimeForm.idNamea}"
											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>
					<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>

