<link href="<?= STATIC_URL ?>/ui/js/plugins/jquery-orgchart-master/jquery.orgchart.css" rel="stylesheet">
<link href="<?= STATIC_URL ?>/ui/css/plugins/jsTree/style.min.css" rel="stylesheet">
<style>
    div.orgChart div.node {
        padding: 5px;
        width: auto;;
        height: auto;
    }
    .node a{
        line-height:40px;
        margin:0px;
        color:#333;
    }
    .jstree-open > .jstree-anchor > .fa-folder:before {
        content: "\f07c";
    }

    .jstree-default .jstree-icon.none {
        width: 0;
    }

</style>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title">名下代理</h4>
</div>

<div class="modal-body">

    <div id="jstree" <?php  if (count($list) < 6) { echo 'style="display:none;"'; } else { echo 'style="padding-top:20px;"'; } ?> >
        <ul id="organisation">
            <li class="jstree-open">
                <a><?= !empty($member['name']) ? $member['name'] : '' ?></a>

                <?php if (!empty($list)) : ?>
                    <ul>
                        <?php foreach ($list as $k => $v) : ?>
                            <li ibId="<?= $v['id'] ?>" class="jstree-open">
                                <a href="/admin/ib/view?id=<?= $v['id'] ?>"><?= $v['name'] ?></a>

                                <?php if (!empty($v['sub'])) : ?>
                                    <ul>
                                        <?php foreach ($v['sub'] as $k2 => $v2) : ?>
                                            <li ibId="<?= $v2['id'] ?>" class="jstree-open">
                                                <a href="/admin/ib/view?id=<?= $v2['id'] ?>"><?= $v2['name'] ?></a>

                                                <?php if (!empty($v2['sub'])) : ?>
                                                    <ul>
                                                        <?php foreach ($v2['sub'] as $k3 => $v3) : ?>
                                                            <li ibId="<?= $v3['id'] ?>" class="jstree-open">
                                                                <a href="/admin/ib/view?id=<?= $v3['id'] ?>"><?= $v3['name'] ?></a>

                                                                <?php if (!empty($v3['sub'])) : ?>
                                                                    <ul>
                                                                        <?php foreach ($v3['sub'] as $k4 => $v4) : ?>
                                                                            <li ibId="<?= $v4['id'] ?>" class="jstree-open">
                                                                                <a href="/admin/ib/view?id=<?= $v4['id'] ?>"><?= $v4['name'] ?></a>

                                                                                <?php if (!empty($v4['sub'])) : ?>
                                                                                    <ul>
                                                                                        <?php foreach ($v4['sub'] as $k5 => $v5) : ?>
                                                                                            <li ibId="<?= $v5['id'] ?>" class="jstree-open">
                                                                                                <a href="/admin/ib/view?id=<?= $v5['id'] ?>"><?= $v5['name'] ?></a>

                                                                                                <?php if (!empty($v5['sub'])) : ?>
                                                                                                    <ul>
                                                                                                        <?php foreach ($v5['sub'] as $k6 => $v6) : ?>
                                                                                                            <li ibId="<?= $v6['id'] ?>" class="jstree-open">
                                                                                                                <a href="/admin/ib/view?id=<?= $v6['id'] ?>"><?= $v6['name'] ?></a>

                                                                                                                <?php if (!empty($v6['sub'])) : ?>
                                                                                                                    <ul>
                                                                                                                        <?php foreach ($v6['sub'] as $k7 => $v7) : ?>
                                                                                                                            <li ibId="<?= $v7['id'] ?>" class="jstree-open">
                                                                                                                                <a href="/admin/ib/view?id=<?= $v7['id'] ?>"><?= $v7['name'] ?></a>

                                                                                                                                <?php if (!empty($v7['sub'])) : ?>
                                                                                                                                    <ul>
                                                                                                                                        <?php foreach ($v7['sub'] as $k8 => $v8) : ?>
                                                                                                                                            <li ibId="<?= $v8['id'] ?>" class="jstree-open">
                                                                                                                                                <a href="/admin/ib/view?id=<?= $v8['id'] ?>"><?= $v8['name'] ?></a>

                                                                                                                                                <?php if (!empty($v8['sub'])) : ?>
                                                                                                                                                    <ul>
                                                                                                                                                        <?php foreach ($v8['sub'] as $k9 => $v9) : ?>
                                                                                                                                                            <li ibId="<?= $v9['id'] ?>" class="jstree-open">
                                                                                                                                                                <a href="/admin/ib/view?id=<?= $v9['id'] ?>"><?= $v9['name'] ?></a>
                                                                                                                                                            </li>
                                                                                                                                                        <?php endforeach; ?>
                                                                                                                                                    </ul>
                                                                                                                                                <?php endif; ?>

                                                                                                                                            </li>
                                                                                                                                        <?php endforeach; ?>
                                                                                                                                    </ul>
                                                                                                                                <?php endif; ?>

                                                                                                                            </li>
                                                                                                                        <?php endforeach; ?>
                                                                                                                    </ul>
                                                                                                                <?php endif; ?>

                                                                                                            </li>
                                                                                                        <?php endforeach; ?>
                                                                                                    </ul>
                                                                                                <?php endif; ?>

                                                                                            </li>
                                                                                        <?php endforeach; ?>
                                                                                    </ul>
                                                                                <?php endif; ?>

                                                                            </li>
                                                                        <?php endforeach; ?>
                                                                    </ul>
                                                                <?php endif; ?>

                                                            </li>
                                                        <?php endforeach; ?>
                                                    </ul>
                                                <?php endif; ?>

                                            </li>
                                        <?php endforeach; ?>
                                    </ul>
                                <?php endif; ?>

                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>

            </li>
        </ul>
    </div>
    
    <div id="main"></div>
</div>

<div class="modal-footer">
    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
</div>

<script src="<?= STATIC_URL ?>/ui/js/plugins/jquery-orgchart-master/jquery.orgchart.min.js"></script>
<script src="<?= STATIC_URL ?>/ui/js/plugins/jsTree/jstree.min.js"></script>

<script>
$(function() {
    <?php if (count($list) < 6) : ?>
    $("#organisation").orgChart({container: $("#main")});
    <?php else: ?>
    $('#jstree').jstree({
        'core' : {
            'check_callback' : true
        },
        'plugins' : [ 'types', 'dnd' ],
        'types' : {
            'default' : {
                'icon' : 'fa fa-folder'
            },
            'html' : {
                'icon' : 'fa fa-file-code-o'
            },
            'svg' : {
                'icon' : 'fa fa-file-picture-o'
            },
            'css' : {
                'icon' : 'fa fa-file-code-o'
            },
            'img' : {
                'icon' : 'fa fa-file-image-o'
            },
            'js' : {
                'icon' : 'fa fa-file-text-o'
            }
        }
    }).bind('click.jstree',function(event){
        var eventNodeName = event.target.nodeName;
        if (eventNodeName == 'INS') {
            return;
        } else if (eventNodeName == 'A') {
            var $subject = $(event.target).parent();
            if ($subject.find('ul').length > 0) {
            } else {
                //选择的id值
                var ibId=$(event.target).parents('li').attr('ibId');
                location.href="/admin/ib/view?id="+ibId;
            }
        }
    });
    <?php endif; ?>
});
</script>



