<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/'}">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/js/vendor/zTree3/css/metroStyle/metroStyle.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/common.css" media="all">
    <style>
        .active {border-left: 5px;border-right: 5px;border-top: 0px;border-bottom: 0px;border-style: solid;border-color: #009688;}
    </style>
</head>
<body>
<div class="layui-anim layui-anim-fadein">
    <div class="layui-card">
        <table id="tableTemplateBox" class="layui-table" style="margin: 0;"></table>
        <script id="tableTemplate" type="text/html">
            <tbody style="text-align: center;">
            {{# for(var i = 0, item; item = d.data[i++];) { }}
            <tr>
                {{# if(item.menuId === d.selectedMenuId) { }}
                <td><div id="{{item.menuId}}Box" class="active"><a id="{{item.menuId}}" class="menu-name" href="javascript:void(0);">{{i}}.{{item.menuName}}</a></div></td>
                {{# } }}
                {{# if(item.menuId != d.selectedMenuId) { }}
                <td><div id="{{item.menuId}}Box"><a id="{{item.menuId}}" class="menu-name" href="javascript:void(0);">{{i}}.{{item.menuName}}</a></div></td>
                {{# } }}
            </tr>
            {{# } }}
            </tbody>
        </script>
    </div>
</div>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
    var common;
    layui.config({
        base: 'assets/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'laytpl', 'ztree', 'common'], function() {
        common = layui.common;
        var $ = layui.$;
        var $win = $(window);
        var laytpl = layui.laytpl;
        var selectedMenuId = top.restAjax.params(window.location.href).menuId;
        top.dialog.dialogData.menuId = selectedMenuId;

        // 初始化IFrame
        function initData() {
            top.restAjax.get(top.restAjax.path('api/menu/list/0', []), {}, null, function(code, data) {
                laytpl(document.getElementById('tableTemplate').innerHTML).render({
                    selectedMenuId: selectedMenuId,
                    data: data
                }, function(html){
                    document.getElementById('tableTemplateBox').innerHTML = html;
                });
            }, function(code, data) {
                top.dialog.msg(data.msg);
            })
        }
        // 初始化大小
        function initSize() {
            $('#leftTreeWrap').css({
                height: $win.height() - 30,
                overflow: 'auto'
            });
            $('#listContentWrap').css({
                height: $win.height() - 50,
            });
        }

        initSize();
        initData();

        $(document).on('click', '.menu-name', function() {
            $('.active').removeClass('active');
            if(top.dialog.dialogData.menuId == this.id) {
                top.dialog.dialogData.menuId = null;
            } else {
                $('#'+ this.id +'Box').addClass('active');
                top.dialog.dialogData.menuId = this.id;
            }

        })
    });
</script>
</body>
</html>