<%@ page import="com.jeeplus.modules.sys.utils.UserUtils" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>请假管理</title>
	<meta name="decorator" content="default"/>
	<style>
		.widthClass{
			display: inline-block;
		}
		.shows .input-group{
			width: 48%!important;
		}
	</style>
	<style>
		body{
			background-color:transparent;
			filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#26FFFFFF, endColorstr=#26FFFFFF);
			color:#ffffff;
			background-color:rgba(255,255,255,0);
			height:100%;
		}
	</style>
</head>
<body>
<div class="wrapper wrapper-content">
	<sys:message content="${message}"/>
	<div class="layui-row">
		<div class="full-width fl">
			<div class="contentShadow layui-row" id="queryDiv">
				<form:form id="searchForm" modelAttribute="leaveApply" action="${ctx}/leaveapply/leaveApply/" method="post" class="form-inline">
					<%--以下三行照抄--%>
					<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
					<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
					<table:sortColumn id="orderBy" name="orderBy" value="${page.orderBy}" callback="sortOrRefresh();"/><!-- 支持排序 -->
					<div class="commonQuery">
						<div class="layui-item query athird">
							<label class="layui-form-label">姓名：</label>
							<div class="layui-input-block">
								<input  name="basicInfo.name" type="text"  maxlength="64" class=" form-control  layui-input laydate-icon"  />
								</input>
							</div>
						</div>
						<div class="layui-item query athird">
							<label class="layui-form-label">申请日期：</label>
							<div class="layui-input-block">
								<input id="beginDate" placeholder="开始时间" name="beginApplyTime" type="text" readonly="readonly" maxlength="20" class="laydate-icondate form-control layer-date layui-input laydate-icon query-group"
									   value="<fmt:formatDate value="${leaveApply.beginApplyTime}" pattern="yyyy-MM-dd"/>"/>
								</input>
								<span class="group-sep">-</span>
								<input id="endDate" placeholder="结束时间" name="endApplyTime" type="text" readonly="readonly" maxlength="20" class="laydate-icondate form-control layer-date layui-input laydate-icon query-group"
									   value="<fmt:formatDate value="${leaveApply.endApplyTime}" pattern="yyyy-MM-dd"/>"/>
								</input>
							</div>
						</div>
						<div class="layui-item athird">
							<div class="input-group">
								<a href="#" id="moresee"><i class="glyphicon glyphicon-menu-down"></i></a>
								<button id="searchReset" class="fixed-btn searchReset fr" onclick="resetSearch()">重置</button>
								<button id="searchQuery" class="fixed-btn searchQuery fr" onclick="search()">查询</button>
							</div>
						</div>
						<div style="    clear:both;"></div>
					</div>
					<div id="moresees" style="clear:both;display:none;">
						<div class="layui-item query athird ">
							<label class="layui-form-label">状态：</label>
							<div class="layui-input-block">
								<form:select path="status" class=" form-control  simple-select">
									<form:option value="" label=""/>
									<form:options items="${fns:getDictList('leave_audit')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
								</form:select>
							</div>
						</div>
						<div style="clear:both;"></div>
					</div>
				</form:form>
			</div>
		</div>

		<div class="full-width fl">
			<div class="contentShadow layui-form contentDetails">
				<div class="nav-btns">
					<%--此处按钮样式包括 nav-btn-add nav-btn-refresh nav-btn-import nav-btn-export nav-btn-query nav-btn-reset--%>
					<shiro:hasPermission name="leaveapply:leaveApply:add">
						<a href="javascript:void(0)" onclick="openDialogAdd('新增请假', '${ctx}/leaveapply/leaveApply/form?tabId=1','95%','95%')" class="nav-btn nav-btn-add" ><i class="fa fa-plus"></i>&nbsp;添加</a>
					</shiro:hasPermission>
					<button class="nav-btn nav-btn-refresh" data-toggle="tooltip" data-placement="left" onclick="sortOrRefresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i>&nbsp;刷新</button>
					<div style="clear: both;"></div>
				</div>
				<table class="oa-table layui-table" id="contentTable"></table>

				<!-- 分页代码 -->
				<table:page page="${page}"></table:page>
				<div style="clear: both;"></div>
			</div>
		</div>
	</div>
	<div id="changewidth"></div>
</div>
<script src="${ctxStatic}/layer-v2.3/layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use('table', function(){
        layui.table.render({
            limit:${ page.pageSize }
            ,elem: '#contentTable'
            ,page: false
            ,cols: [[
                {field:'index',align:'center', title: '序号',width:40}
                ,{field:'no',align:'center',sort: true, minWidth:120,title: '请假编号', templet:function(d){
                        var xml = "<a class=\"attention-info\" href=\"javascript:void(0)\" onclick=\"openDialogView('查看请假', '${ctx}/leaveapply/leaveApply/view?id=" + d.id + "','95%','95%')\">" +
                            "<span title=" + d.no + ">" + d.no + "</span></a>";
                        return xml;
                    }},
                {field:'name',align:'center', width:120, title: '姓名',templet:function(d){
                        return "<span title='"+ d.name +"'>" + d.name + "</span>";
                    }}
                ,{field:'number',align:'center',width:120, title: '工号',templet:function(d){
                        return "<span title='"+ d.number +"'>" + d.number + "</span>";
                    }}
                ,{field:'office',align:'center',width:200, title: '部门',templet:function(d){
                        return "<span title='"+ d.office +"'>" + d.office + "</span>";
                    }}
                ,{field:'job',align:'center',width:150, title: '职级',templet:function(d){
                        return "<span title='"+ d.job +"'>" + d.job + "</span>";
                    }}
                ,{field:'applyTime', align:'center',width:100,title: '申请日期'}
                ,{field:'longTime',align:'center',width:100, title: '请假时长',templet:function(d){
                        return "<span title='"+ d.longTime +"'>" + d.longTime + "</span>";
                    }}
                ,{field:'status',align:'center',width:100, title: '申请状态',templet:function(d){
                        var st = getAuditLeaveState(d.status);
                        if(st.action)
                            var xml = "<span onclick=\"openDialogView('流程追踪', '${ctx}/leaveapply/leaveApply/getProcess?id=" + d.id + "','95%','95%')\" class=\"status-label status-label-" + st.label + "\" >" + st.status + "</span>";
                        else
                            var xml = "<span style=\"cursor:default;\" class=\"status-label status-label-" + st.label + "\" >" + st.status + "</span>";
                        return xml;
                    }}
                ,{align:'caozuo',align:'center',title:"操作",width:160,templet:function(d){
                        var xml = "";
                        if(d.canedit != undefined && d.canedit == "1"){
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('修改请假', '${ctx}/leaveapply/leaveApply/form?id=" + d.id+"','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>修改</a>"
                        }
                        if(d.canmodify != undefined && d.canmodify =="1"){
                            xml+="<a href=\"#\" onclick=\"openDialog('修改请假', '${ctx}/leaveapply/leaveApply/modify?id=" + d.id + "','95%', '95%','','重新申请,关闭')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i> 修改</a>";
                        }
                        if(d.candelete != undefined && d.candelete == "1"){
                            xml +="<a href=\"${ctx}/leaveapply/leaveApply/delete?id=" + d.id+"\" onclick=\"return confirmx('确认要删除该请假吗？', this.href)\"   class=\"op-btn op-btn-delete\"><i class=\"fa fa-trash\"></i> 删除</a>";
                        }
                        if(d.cancancel != undefined && d.cancancel =="1"){
                            xml+="<a href=\"${ctx}/leaveapply/leaveApply/revoke?id=" + d.id + "&processInstanceId=" + d.procId + "\" onclick=\"return confirmx('确认要撤回该请假申请吗？', this.href)\" class=\"op-btn op-btn-cancel\" ><i class=\"glyphicon glyphicon-share-alt\"></i> 撤回</a>";
                        }
                        if(d.canback != undefined && d.canback =="1"){
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('续假申请', '${ctx}/leaveapply/leaveApply/form?id=" + d.id+"&tabId=2','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>续假</a>";
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('销假申请', '${ctx}/leaveapply/leaveApply/view?id=" + d.id+"&flat=1','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>销假</a>"
                        }
                        if(d.xiaojiazhong != undefined && d.xiaojiazhong =="1"){
                            xml+="<a href=\"${ctx}/leaveapply/leaveApply/revokeBack?id=" + d.id + "&processInstanceId=" + d.procId + "\" onclick=\"return confirmx('确认要撤回该销假申请吗？', this.href)\" class=\"op-btn op-btn-cancel\" ><i class=\"glyphicon glyphicon-share-alt\"></i> 销假撤回</a>";
                        }
                        if(d.canedit1 != undefined && d.canedit1 =="1"){
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('续假申请', '${ctx}/leaveapply/leaveApply/form?id=" + d.id+"&tabId=2','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>续假</a>";
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('修改销假', '${ctx}/leaveapply/leaveApply/view?id=" + d.id+"&flat=1','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>销假</a>"
                        }
                        if(d.canmodify1 != undefined && d.canmodify1 =="1"){
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('续假申请', '${ctx}/leaveapply/leaveApply/form?id=" + d.id+"&tabId=2','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>续假</a>";
                            xml+="<a href=\"#\" onclick=\"openDialog('修改销假', '${ctx}/leaveapply/leaveApply/modify?id=" + d.id + "','95%', '95%','','重新申请,关闭')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i> 销假</a>";
                        }
                        if(d.xujiazhong != undefined && d.xujiazhong =="1"){
                            xml+="<a href=\"${ctx}/leaveapply/leaveApply/revokeExtend?id=" + d.id + "&processInstanceId=" + d.procId + "\" onclick=\"return confirmx('确认要撤回该续假申请吗？', this.href)\" class=\"op-btn op-btn-cancel\" ><i class=\"glyphicon glyphicon-share-alt\"></i> 续假撤回</a>";
                        }
                        if(d.canedit2 != undefined && d.canedit2 =="1"){
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('修改续假', '${ctx}/leaveapply/leaveApply/form?id=" + d.id+"&tabId=2','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>续假</a>"
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('销假申请', '${ctx}/leaveapply/leaveApply/view?id=" + d.id+"&flat=1','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>销假</a>"
                        }
                        if(d.canmodify2 != undefined && d.canmodify2 =="1"){
                            xml+="<a href=\"#\" onclick=\"openDialog('修改续假', '${ctx}/leaveapply/leaveApply/modify?id=" + d.id + "','95%', '95%','','重新申请,关闭')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i> 续假</a>";
                            xml +="<a href=\"javascript:void(0)\" onclick=\"openDialog('销假申请', '${ctx}/leaveapply/leaveApply/view?id=" + d.id+"&flat=1','95%','95%')\" class=\"op-btn op-btn-edit\" ><i class=\"fa fa-edit\"></i>销假</a>"
                        }
                        return xml;
                    }}
            ]]
            ,data: [
                <c:if test="${ not empty page.list}">
                <c:forEach items="${page.list}" var="leaveApply" varStatus="index">
                <c:if test="${index.index != 0}">,</c:if>
                {
                    "index":"${index.index+1}",
                    "id":"${leaveApply.id}"
                    ,"no":"${leaveApply.no}"
                    ,"name":"${leaveApply.basicInfo.name}"
                    ,"number":"${leaveApply.basicInfo.no}"
                    ,"office":"${leaveApply.basicInfo.office.name}"
                    ,"job":"${leaveApply.basicInfo.jobGrade.name}"
                    ,"applyTime":"<fmt:formatDate value="${leaveApply.applyTime}" pattern="yyyy-MM-dd"/>"
                    ,"longTime":"${leaveApply.longTime}"
                    ,"status":"${leaveApply.status}"
                    ,"procId":"${leaveApply.processInstanceId}"
                    <c:if test="${flag == '1' or fns:getUser().id == leaveApply.createBy.id}">
                    ,"canedit":<c:choose><c:when test="${leaveApply.status == 1 or leaveApply.status == 3}">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"canmodify":<c:choose><c:when test="${leaveApply.status == 4}">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"candelete":<c:choose><c:when test="${leaveApply.status == 1 or leaveApply.status == 3 or leaveApply.status == 4}">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"cancancel":<c:choose><c:when test="${leaveApply.status == 2}">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"canback":<c:choose><c:when test="${leaveApply.status == 5 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"xiaojiazhong":<c:choose><c:when test="${leaveApply.status == 6 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"canedit1":<c:choose><c:when test="${leaveApply.status == 7 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"canmodify1":<c:choose><c:when test="${leaveApply.status == 9 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"xujiazhong":<c:choose><c:when test="${leaveApply.status == 10 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"canedit2":<c:choose><c:when test="${leaveApply.status == 11 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    ,"canmodify2":<c:choose><c:when test="${leaveApply.status == 12 }">"1"</c:when><c:otherwise>"0"</c:otherwise></c:choose>
                    </c:if>
                }
                </c:forEach>
                </c:if>
            ]
        });

    })
    resizeListTable();
</script>
<script>
    resizeListWindow1();
    $(window).resize(function(){
        resizeListWindow1();
    });
</script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#cus_name").show();
        $("#cus_name").siblings().hide();
        //搜索框收放
        $('#moresee').click(function(){
            if($('#moresees').is(':visible'))
            {
                $('#moresees').slideUp(0,resizeListWindow1);
                $('#moresee i').removeClass("glyphicon glyphicon-menu-up").addClass("glyphicon glyphicon-menu-down");
            }else{
                $('#moresees').slideDown(0,resizeListWindow1);
                $('#moresee i').removeClass("glyphicon glyphicon-menu-down").addClass("glyphicon glyphicon-menu-up");
            }
        });

        laydate.render({
            elem: '#beginDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
            format: 'yyyy-MM-dd',
            type : 'date'
        });

        laydate.render({
            elem: '#endDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
            format: 'yyyy-MM-dd',
            type : 'date'
        });

    });
    function switchInput(obj){
        $("#"+obj).show();
        $("#"+obj).siblings().hide();
    }

    function openDialogremodify(title,url,width,height,target){

        if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
            width='auto';
            height='auto';
        }else{//如果是PC端，根据用户设置的width和height显示。

        }
        top.layer.open({
            type: 2,
            area: [width, height],
            title: title,
            skin: 'two-btns',
            maxmin: true, //开启最大化最小化按钮
            content: url ,
            btn: ['重新申请','关闭'],
            yes: function(index, layero){
                var body = top.layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe;
                if(target){
                    top_iframe = target;//如果指定了iframe，则在改frame中跳转
                }else{
                    top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                }
                inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                if(iframeWin.contentWindow.doSubmit() ){
                    top.layer.close(index);//关闭对话框。
                    //setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                }

            }

        });
    }
    function openDialogAdd(title,url,width,height,target) {
        $.ajax({
            type:'post',
            url:'${ctx}/leaveapply/leaveApply/addApply',
            success:function(data){
                if(data==0){

                    if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {//如果是移动端，就使用自适应大小弹窗
                        width = 'auto';
                        height = 'auto';
                    } else {//如果是PC端，根据用户设置的width和height显示。
                    }
                    top.layer.open({
                        type: 2,
                        area: [width, height],
                        title: title,
                        maxmin: true, //开启最大化最小化按钮
                        content: url,
                        skin: 'three-btns',
                        btn: ['送审', '暂存', '关闭'],
                        btn1: function(index, layero){
                            var body = top.layer.getChildFrame('body', index);
                            var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            var inputForm = body.find('#inputForm');
                            var top_iframe;
                            if(target){
                                top_iframe = target;//如果指定了iframe，则在改frame中跳转
                            }else{
                                top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                            }
                            inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                            if(iframeWin.contentWindow.doSubmit(1) ){
                                // top.layer.close(index);//关闭对话框。
                                setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                            }
                        },
                        btn2:function(index,layero){
                            var body = top.layer.getChildFrame('body', index);
                            var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            var inputForm = body.find('#inputForm');
                            var top_iframe;
                            if(target){
                                top_iframe = target;//如果指定了iframe，则在改frame中跳转
                            }else{
                                top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                            }
                            inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                            if(iframeWin.contentWindow.doSubmit(2) ){
                                // top.layer.close(index);//关闭对话框。
                                setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                            }else {
                                return false;
                            }
                        },
                        btn3: function (index) {
                        }
                    });
                }else if(data==1){
                    parent.layer.msg("存在未销假的请假记录，销假后才能添加!",{icon:1});
				}else if(data==-1){
                    parent.layer.msg("人员档案信息不存在无操作权限!",{icon:1});
                }
           }
        })
    }

</script>
</body>
</html>
