<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", -10);
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@include file="/WEB-INF/views/base.jsp"%>
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>组织架构</title>

<link href="${cssPath }/bootstrap.min.css" rel="stylesheet">
<link href="${fontAwsPath }/css/font-awesome.css" rel="stylesheet">

<!-- Data Tables -->
<link href="${cssPath }/plugins/dataTables/dataTables.bootstrap.css"
	rel="stylesheet">
<link href="${cssPath }/plugins/dataTables/dataTables.responsive.css"
	rel="stylesheet">
<link
	href="${cssPath }/plugins/dataTables/dataTables.tableTools.min.css"
	rel="stylesheet">

<link href="${cssPath }/animate.css" rel="stylesheet">
<link href="${cssPath }/style.css" rel="stylesheet">
<link
	href="${cssPath }/plugins/sweetalert/sweetalert.css"
	rel="stylesheet">
	
</head>
<body class="pace-done">
	<input type="hidden" id="basePath" value="<%=basePath%>">
	<div id="wrapper">

		<jsp:include page="../menu.jsp"></jsp:include>

		<div id="page-wrapper" class="gray-bg">
			<jsp:include page="../head.jsp"></jsp:include>
			<jsp:include page="../pageNav.jsp"></jsp:include>

			<div class="wrapper wrapper-content animated fadeInRight">
				<div class="row">


					<form action="${pageContext.request.contextPath}/sysDepartment/getDepartmentList"  id="submit_form"
						method="post">
						<div class="ibox-content m-b-sm border-bottom">
							<div class="row">
								<div class="col-sm-6">
									<div class="form-group">
										<label class="control-label" for="search">部门名称</label> <select
											class="form-control" id="depname" name="departmentid"
											style="width: 100%">
											<option value="-1">请选择</option>
											<c:forEach items="${sysDepartmentlist}" var="s">
												<option value="${s.departmentid }">${s.depname }</option>
												<c:forEach items="${s.childSysDepartment}" var="s1" >
													<option value="${s1.departmentid }"> ${s1.depname }</option>
												</c:forEach>
											</c:forEach>
										</select> <input type="hidden" id="pageNo" name="pageNo" value="1">
									</div>
								</div>
								<div class="col-sm-6">
									<div class="form-group">
										<label class="control-label" for="search">查询</label>
										<button type="submit"
											class="btn btn-w-m btn-success form-control">
											<i class="fa fa-search"></i>&nbsp;&nbsp;查询
										</button>
									</div>
								</div>
							</div>
						</div>
					</form>

						
					<div class="ibox float-e-margins">
									<div class="ibox-title">
										<a href="${pageContext.request.contextPath}/sysDepartment/getVerification"
											class="btn btn-w-m btn-primary"><i
											class="fa fa-plus-square"></i>&nbsp;&nbsp;新增</a>

									</div>
									<div class="ibox-content" id="PartialMenuListPage">

										<table id="MenuTable" class="table table-hover">
											<thead>
												<tr>
													<th>部门名称</th>
													<th>部门编码</th>
													<th>排序</th>
													<th>操作</th>
												</tr>
											</thead>
											<tbody>
												<c:forEach items="${list.dataList}" var="u" varStatus="v">
													<tr class="table_${u.parentid }">
													<td><span onclick="MeunClick(this,${u.departmentid })" menuid="${u.departmentid }"
												class="Meunbut" style="margin-left:${u.level *20}px;">
												<i class="fa fa-minus-square" style="margin-right: 10px;"></i>${u.depname}</span></td>
														<td>${u.depcode }</td>
														<td>${u.deptrolecode}</td>
														<td>
															<div class="dropdown">
																<a data-toggle="dropdown" class="dropdown-toggle"
																	href="#"> <span class="text-muted text-xs block">操作
																		<b class="caret"></b>
																</span>
																</a>

																<ul class="dropdown-menu animated fadeInRight m-t-xs">
																	<li><a href="${pageContext.request.contextPath}/sysDepartment/getSelectdepartment?depid=${u.depid}">编辑</a></li>
																	<li><a href="javascript:void(0)"
																		onclick="Delete('${u.depid}');">删除</a></li>
																</ul>
															</div>
														</td>
													</tr>
												</c:forEach>

											</tbody>
										</table>

										<%@include file="/WEB-INF/views/page.jsp"%>
									</div>
					</div>

				</div>
			</div>
		</div>
	</div>
<%@include file="/WEB-INF/views/common_base_script.jsp"%>
	<script type="text/javascript">
		//部门折叠
		function MeunClick(obj, id) {
		    var icon = $(obj).children().attr("class");
		    if (icon == "fa fa-minus-square") {
		        $(obj).children().attr("class", "fa fa-plus-square")
		    } else {
		        $(obj).children().attr("class", "fa fa-minus-square")
		    }
		    $("#MenuTable .table_" + id).fadeToggle();
		
		    $("#MenuTable .table_" + id).each(function (i, v) {
		        var menuid = $(v).find("span").attr("menuid");
		        $(v).find("span").find("i").attr("class", "fa fa-plus-square");
		        $("#MenuTable .table_" + menuid).hide();
		    });
		}
		//删除
		function Delete(Id){
			 swal({
		            title: "系统提示",
		            text: "确认要删除吗？",
		            type: "warning",
		            showCancelButton: true,
		            confirmButtonColor: "#DD6B55",
		            confirmButtonText: "确定",
		            cancelButtonText: "取消",
		            closeOnConfirm: false
		        },function () {
		            $.post("getDeleteDepartment", { depid: Id }, function (data) {
		            	debugger;
		                if (data.pm==false) {
		                    swal("删除失败!", "该部门有下有职位！", "error");
		                } else {
		                    swal("删除成功!", "删除完成！", "success");
		                    window.location.reload();
		                }
		            })
		        });
	/* 	 		var bathPath = $("#basePath").val();
			$.ajax({
				type : 'POST',
				async : false,
				url : bathPath + 'sysDepartment/getDeleteDepartment.json',
				data : {'depid' : Id },
				dataType : 'json',
				success : function(data){
					if(data.pm==false){
						//提醒用户
						alert("父菜单下面有子菜单不能删除，请删除子菜单后重试！");
						//toastr['error']('删除失败!',"父菜单下面有子菜单不能删除，请删除子菜单后重试！")
					}else{
						alert("删除成功");
						}
				}
			})  */

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