<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	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>
   	<%@include file="/WEB-INF/views/common_base_css.jsp"%>
</head>

<body>
	<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>
        	
        	<input type="hidden" id="pageNo"  name="pageNo" value="1" >
            <!-- 页面 主题内容  开始-->
	        <div class="wrapper wrapper-content animated fadeInRight">
	        <div class="row">
	            <!-- 查询条件 开始 -->
	            <div class="ibox-content m-b-sm border-bottom">
			        <div class="row" id="row_tab_1">
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="dictname">名称</label>
			                    <input type="text" id="dictname" name="dictname"  class="form-control">
			                </div>
			            </div>
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="employeeNo">分组</label>
			                    <select class="form-control" id="namespace" name="namespace">
									<option  value="">请选择</option>
									<c:forEach items="${categroyList}" var="u">
										<option value="${u.dictvalue }">${u.dictname}</option>
									</c:forEach>
								</select>
			                </div>
			            </div>
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="search">查询</label>
			                    <button onclick="query()" class="btn btn-w-m btn-success form-control"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
			                </div>
			            </div>
			        </div>
			        <div class="row" id="row_tab_2" style="display:none">
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="dictname1">类别名称</label>
			                    <input type="text" id="dictname1" name="dictname1"  class="form-control">
			                </div>
			            </div>
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="dictvalue1">类别值</label>
			                    <input type="text" id="dictvalue1" name="dictvalue1"   class="form-control">
			                </div>
			            </div>
			            <div class="col-sm-4">
			                <div class="form-group">
			                    <label class="control-label" for="search">查询</label>
			                    <button onclick="query2()" class="btn btn-w-m btn-success form-control"><i class="fa fa-search"></i>&nbsp;&nbsp;查询</button>
			                </div>
			            </div>
			        </div>
				</div>
	            <!-- 查询条件 结束 -->
	            
	            <!-- 用户列表开始 -->

	           
	            
			
				<div class="ibox float-e-margins">
					<div class="ibox-title">
					<form action="dictionaryAdd" method="post" id="dictionaryAdd">	
						<input type="hidden" id="currentTab" name="currentTab" value="${currentTab }" >
				        <a href="javascript:void(0)" class="btn btn-w-m btn-primary submitform"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;
				        <span id="addDictionary">新增常量</span></a>
				    </form> 
				    </div>
				    <div class="ibox-content" >
						<div class="tabs-container">
                        <ul class="nav nav-tabs">
                            <li id="tab1" class="active changeTab"><a data-toggle="tab" href="#tab-1"> <i class="fa fa-laptop"></i>字典常量</a></li>
                            <li id="tab2" class="changeTab"><a data-toggle="tab" href="#tab-2"><i class="fa fa-desktop"></i>字典分组</a></li>
                        </ul>
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane active">
                                <div class="panel-body" id="UserListPartial">
                                	
                                </div>
                            </div>
                            <div id="tab-2" class="tab-pane">
                                <div class="panel-body" id="UserListPartial2">
                                    
                                </div>
                            </div>
                        </div>
                    </div>
				    </div>
				</div>     
				     
	            <!-- 用户列表结束 -->
			</div>
	        
	        </div>
	        <!-- 页面主题内容 结束 -->
        </div>
    </div>


    <!-- Mainly scripts -->
    <%@include file="/WEB-INF/views/common_base_script.jsp"%>
        <script>
            $(document).ready(function () {
                $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green',
                });
                var currentTab = $("#currentTab").val();
                if(currentTab == "tab1"){
                	$("#tab1").addClass("active");
                	$("#tab2").removeClass("active");
                	$("#tab-1").addClass("active");
                	$("#tab-2").removeClass("active");
                	$("#row_tab_1").show();
                	$("#row_tab_2").hide();
                } else {
                	$("#tab2").addClass("active");
                	$("#tab1").removeClass("active");
                	$("#tab-2").addClass("active");
                	$("#tab-1").removeClass("active");
                	$("#row_tab_2").show();
                	$("#row_tab_1").hide();
                }
                $(".changeTab").click(function(){
                	var id = $(this).attr("id");
                	if(id=="tab1"){
                		$("#addDictionary").html("新增常量");
                		$("#currentTab").val("tab1");
                		$("#row_tab_1").show();
                		$("#row_tab_2").hide();
                	} else {
                		$("#addDictionary").html("新增分组");
                		$("#currentTab").val("tab2");
                		$("#row_tab_2").show();
                		$("#row_tab_1").hide();
                	}	
                });
                $(".submitform").click(function(){
                	$(this).parent().submit();
                });
                $("body").delegate('.op_enable', 'click', function(){
                	var dictid = $(this).attr("dictid");
                	var $this = $(this);
                	var basePath = "<%=basePath %>";
                	$.ajax({
						type : 'POST',
						async : false,
						url : basePath + 'sysDictionary/updateDictionaryEnable.json',
						data : {'dictid' : dictid },
						dataType : 'json',
						success : function(data){
							if(data.success){
								//操作成功, 当前用户已经 冻结
								if(data.userStatus) {
									$this.html("激活");
									$(".const_status_"+dictid).find("i").attr("class", "fa fa-minus text-danger");
								} else {
									$this.html("反激活");
									$(".const_status_"+dictid).find("i").attr("class", "fa fa-check text-navy");
								}
							} else {
								//提醒用户操作失败
								CommonUtils.toastMsg(3, "操作失败", 2);
								//toastr['error']('操作失败');
							}
						}, 
						error : function(XMLHttpRequest, textStatus, errorThrown) {
							//提醒用户操作失败
							CommonUtils.toastMsg(3, "操作失败", 2);
						}
					})
                });
                initData();
                initData2();
            });
            
            var basePath = "<%=basePath %>";
            function initData(){
	            var pageNo = $("#pageNo").val();
	            var dictname = $("#dictname").val();
	            var namespace = $("#namespace").val();
				//第一次加载数据
				$.ajax({
					type : 'POST',
					async : false,
					url : basePath + 'sysDictionary/initDicitionaryDataList',
					data : {'pageNo' : pageNo, 'dictname':dictname, 'namespace':namespace  },
					dataType : 'html',
					success : function(data){
						$("#UserListPartial").html(data);
					}
				})
            }
            
            function initData2(){
	            var pageNo = $("#pageNo").val();
	            var dictname = $("#dictname1").val();
	            var dictvalue = $("#dictvalue1").val();
				//第一次加载数据
				$.ajax({
					type : 'POST',
					async : false,
					url : basePath + 'sysDictionary/initDataList',
					data : {'pageNo' : pageNo, 'dictname':dictname, 'dictvalue':dictvalue },
					dataType : 'html',
					success : function(data){
						$("#UserListPartial2").html(data);
					}
				})
            }
        	
        	function query(){
        		$("#pageNo").val("1");
        		initData();
        	}
        	
        	function query2(){
        		$("#pageNo").val("1");
        		initData2();
        	}
        </script>     
        
</body>

</html>