<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:sec="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="admin/common/html/head :: Head_Premiss(~{::title},~{::link},~{::style})">

<title th:text=${title}></title>
<!-- 这儿引用单独的css link -->
<!-- Ladda for Bootstrap 3按钮加载进度插件 -->
<link rel="stylesheet" th:href="@{/static/admin/assets/js/button/ladda/ladda.min.css}">

<link rel="stylesheet" th:href="@{/static/js/bootstrap-treetable/bootstrap-treetable.min.css}">

<style type="text/css">
/**
*这里写单独的css样式
*/

</style>

</head>

<body id="listbody">
<!-- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 代码编写处 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -->

<!-- 右边内容 -->
<div class="wrap-fluid">
    <div class="container-fluid paper-wrap bevel tlbr">
        <!-- 内容 -->
        <!--标题 通用-->
        <div th:replace="admin/common/html/title :: title(${title},${parenttitle},${isMsg},${msgHTML})">
        </div>
        <!-- 结束标题 通用-->
        <div class="content-wrap">
            <!-- 结束内容 -->
            <div class="row">
                <div class="col-sm-12">
                <!-- 搜索条件 -->
                
                	 <div class="nest" id="inlineClose">
                            <div class="title-alt">
                                <h6>搜索条件</h6>
                                <div class="titleClose">
                                    <a class="gone" href="#inlineClose">
                                        <span class="entypo-cancel"></span>
                                    </a>
                                </div>
                                <div class="titleToggle">
                                    <a class="nav-toggle-alt" href="#search_div" >
                                        <span class="entypo-down-open"></span>
                                    </a>
                                </div>
                            </div>

                            <div class="body-nest" id="search_div" style="display: none">
                                <div class="form_left">
                                    <form role="form" class="form-inline">
                                        <div class="form-group">
                                            <label for="exampleInputEmail2" class="sr-only">搜索名字</label>
                                            <input type="text" name="searchText" placeholder="搜索名字"class="form-control">
                                        </div>
                                        <button onclick="$.table.search(this)" class="btn btn-success" type="button"><i class="fa fa-search"></i>&nbsp;搜索</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                	<!-- END搜索条件 -->
                    <!-- 空白页开始-->
                    <div class="nest" id="Blank_PageClose">
                        <div class="title-alt">
                            <h6>表单</h6>
                            <div class="titleClose">
                                <a class="gone" href="#Blank_PageClose">
                                    <span class="entypo-cancel"></span>
                                </a>
                            </div>
                            <div class="titleToggle">
                                <a class="nav-toggle-alt" href="#Blank_Page_Content">
                                    <span class="entypo-up-open"></span>
                                </a>
                            </div>
                        </div>
                        
                        <div class="body-nest" id="Blank_Page_Content">
                            <!-- 工具条 -->
                            <div class="btn-group hidden-xs" id="exampleTableEventsToolbar" role="group">
                            	<button onclick="add()" type="button" class="btn btn-primary">
                                    <span class="entypo-plus-squared"></span>&nbsp;&nbsp;新增
                                </button>
                               <button onclick="batRemove()" type="button" class="btn btn-info">
                                    <span class="entypo-trash"></span>&nbsp;&nbsp;删除
                               </button>
                               <button id="expandAllBtn"  type="button" class="btn btn-success">
                                    <span class="entypo-shuffle"></span>&nbsp;&nbsp;展开/折叠
                               </button>
                               
                           </div>
                            <!-- 工具条 end-->
                           <table id="demo" class="table-striped footable-res footable metro-blue" data-page-size="6">
                                   
                           </table>
                        </div>
                    </div>
                </div>
                <!-- 空白页结束 -->
            </div>
            <!-- 结束内容 -->
        </div>
    </div>
</div>
<!-- 结束右边内容 -->
<!-- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 代码编写处 END# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -->







<!-- 右侧隐藏滑块内容 -->
<div th:include="admin/common/html/rightHide :: rightHide">
    
</div>
   <!-- END 右侧隐藏滑块内容-->

<!-- 通用js -->
<div th:include="admin/common/html/js :: onload_js_Premiss">
   
</div>
<script th:src="@{/static/js/bootstrap-treetable/bootstrap-treetable.min.js}" type="text/javascript"></script>
<script type="text/javascript">
var dataUrl=window.rootPath+"/SysDepartmentController/list2";
var removeUrl=window.rootPath+"/SysDepartmentController/remove";
var createUrl=window.rootPath+"/SysDepartmentController/add";
var updateUrl=window.rootPath+"/SysDepartmentController/edit/{id}";
var exportUrl=window.rootPath+"/SysDepartmentController/export";


var treeTable = $('#demo').bootstrapTreeTable({
    toolbar: "#demo-toolbar",//顶部工具条
    expandColumn : 3,// 在哪一列上面显示展开按钮
    url: dataUrl,// 请求后台的URL（*）
    type: 'post',
    id : "id",
    rootIdValue: '0',
    parentId: 'parentId',
    striped:true,
    columns: [
		{
		    checkbox: true
		},
		{
		    field: 'id',
		    title: '序号',
		    visible: false //隐藏
		},
		{
		    field: 'parentId',
		    visible: false, //隐藏
		    title: '父id'
		},
		{
		    field: 'deptName',
		    title: '部门名称'
		},
		{
		    field: 'leader',
		    title: '部门负责人'
		},
		{
		    field: 'phone',
		    title: '电话'
		},
		{
		    field: 'email',
		    title: '邮箱'
		},
		{
		    field: 'status',
		    title: '状态',
		    formatter: function (value, row, index) {
		        var actions = [];
		        if(value==0){
		        	 actions.push('<span class="label label-danger">关闭</span>');
		        }else if(value==1){
		        	 actions.push('<span class="label label-primary">开启</span>');
		        }
		      	return actions.join('');			    
			}
		},
		{
		    field: 'orderNum',
		    title: '排序',
		    sortable:true,//设置true为允许列可以排序
			order: 'asc' //排序顺序
		},
		{
		    title: '操作',
		    formatter: function (value, row, index) {
		        var id = row.id;
		        var actions = [];
		        if(row.id!=1){
		        	actions.push('<a class="btn btn-success btn-xs"  href="#" onclick="edit(' + row.id + ')"><i class="fa fa-edit"></i>编辑</a> ');
			        actions.push('<a class="btn btn-danger btn-xs" href="#" onclick="remove(' + row.id + ')"><i class="fa fa-remove"></i>删除</a>');
		        }
		        return actions.join('');
		    }
		}
    ],
    onAll: function(data) {
        console.log("onAll");
        return false;
    },
    onLoadSuccess: function(data) {
        console.log("onLoadSuccess");
        return false;
    },
    onLoadError: function(status) {
        console.log("onLoadError");
        return false;
    },
    onClickCell: function(field, value, row, $element) {
        console.log("onClickCell",row);
        return false;
    },
    onDblClickCell: function(field, value, row, $element) {
        console.log("onDblClickCell",row);
        return false;
    },
    onClickRow: function(row, $element) {
        console.log("onClickRow",row);
        return false;
    },
    onDblClickRow: function(row, $element) {
        console.log("onDblClickRow",row);
        return false;
    }
   
});
$("#selectBtn").click(function(){
    var selecteds = $('#demo').bootstrapTreeTable('getSelections');
    $.each(selecteds,function(_i,_item){
        console.log(_item);
    });
    alert("看console");
})

var _expandFlag_all = false;
$("#expandAllBtn").click(function(){
    if(_expandFlag_all){
        $('#demo').bootstrapTreeTable('expandAll');
    }else{
        $('#demo').bootstrapTreeTable('collapseAll');
    }
    _expandFlag_all = _expandFlag_all?false:true;
})
var _showFlag = true;
$("#showColumnBtn").click(function(){
    if(_showFlag){
        $('#demo').bootstrapTreeTable('hideColumn',"orderNum");
    }else{
        $('#demo').bootstrapTreeTable('showColumn',"orderNum");
    }
    _showFlag = _showFlag?false:true;
})
$("#destroyBtn").click(function(){
    $('#demo').bootstrapTreeTable('destroy');
})


</script>
<script type="text/javascript">

function add(){
	$.modal.open("添加部门", createUrl);
}

function batRemove(){
	
	var rows = $('#demo').bootstrapTreeTable('getSelections');
    if (rows.length == 0) {
        $.modal.alertWarning("请至少选择一条记录");
        return
    }
    $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
    	var rowid=[];
    	for ( var i in rows) {
    		rowid.push(rows[i].id);
		}
        var url = removeUrl;
        var data = {
            "ids": rowid.join()
        };
        $.operate.submit(url, "post", "json", data);
    })
}

function edit(id){
	 var url = updateUrl.replace("{id}", id);
     $.modal.open("修改权限", url);
}

function remove(id){
	
	$.modal.confirm("确定删除该条权限信息吗？", function() {
        var url = removeUrl.replace("{id}", id);
        var data = {
            "ids": id
        };
        $.operate.submit(url, "post", "json", data);
    })
}


//重写刷新方法
$.table.refresh=function() {
	$('#demo').bootstrapTreeTable("refresh",{
		url:dataUrl,
		silent:true
	});
}
</script>

</body>


</html>
