{template "header.html"}

{php echo \Phpcmf\Service::L('Field')->get('select')->get_select_search_code();}
<div class="right-card-box">
    <form class="form-horizontal" role="form" id="myform">
        {dr_form_hidden()}
        <div class="bootstrap-table bootstrap-table2">
            <div id="toolbar" class="toolbar">

                {if $ci->_is_admin_auth('edit')}
                <label style="min-width: 200px;margin-left: 0px;">
                    <select name="groupid[]" class="bs-select form-control"  multiple="multiple"  data-actions-box="true">
                        {loop $group $t}
                        <option value="{$t.id}">{dr_lang($t.name)}</option>
                        {/loop}
                    </select>
                </label><label style="margin-left: -5px;"><button type="button" onclick="dr_ajax_option('{dr_url('member/menu/group_add')}', '{dr_lang('你确定要这样操作吗？')}', 1)" class="btn green btn-sm"> <i class="fa fa-edit"></i> {dr_lang('批量划分用户组可见权限')}</button></label>


                <label style="min-width: 200px;margin-left: 0px;">
                    <select name="clientid[]" class="bs-select form-control"  multiple="multiple"  data-actions-box="true">
                        {loop $client $i $t}
                        <option value="{$i}">{dr_lang($t)}</option>
                        {/loop}
                    </select>
                </label><label style="margin-left: -5px;"><button type="button" onclick="dr_ajax_option('{dr_url('member/menu/client_add')}', '{dr_lang('你确定要这样操作吗？')}', 1)" class="btn yellow btn-sm"> <i class="fa fa-edit"></i> {dr_lang('批量划分终端可见权限')}</button></label>


                {if dr_count($ci->site_info) > 1}
                <label style="min-width: 200px;margin-left: 0px;">
                    <select name="siteid[]" class="bs-select form-control"  multiple="multiple"  data-actions-box="true">
                        {loop $ci->site_info $t}
                        <option value="{$t.SITE_ID}">{$t.SITE_NAME}</option>
                        {/loop}
                    </select>
                </label><label style="margin-left: -5px;"><button type="button" onclick="dr_ajax_option('{dr_url('member/menu/site_add')}', '{dr_lang('你确定要这样操作吗？')}', 1)" class="btn blue btn-sm"> <i class="fa fa-edit"></i> {dr_lang('批量划分站点可见权限')}</button></label>

                {/if}
                {/if}
            </div>
        </div>
        <div class="table-scrollable">
            <table class="table table-striped table-bordered table-hover table-checkable dataTable">
                <thead>
                <tr class="heading">
                    {if $ci->_is_admin_auth('del')}
                    <th class="myselect">
                        <label class="mt-table mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                            <input type="checkbox" class="group-checkable" data-set=".checkboxes" />
                            <span></span>
                        </label>
                    </th>
                    {/if}
                    <th class="hidden-mobile" width="70" style="text-align:center"> {dr_lang('排序')} </th>
                    <th class="hidden-mobile" width="60" style="text-align:center"> {dr_lang('可见')} </th>
                    <th width="250"> {dr_lang('名称')} </th>
                    <th style="text-align:center" width="80">
                        {if $ci->_is_admin_auth('add')}<a href="javascript:dr_iframe('add', '{dr_url('member/menu/add', ['pid'=>0])}');" class="btn btn-xs blue"> <i class="fa fa-plus"></i> {dr_lang('添加')} </a>{/if}
                    </th>
                    <th> {dr_lang('用户组划分(默认全部组)')} </th>
                    <th> {dr_lang('终端划分')} </th>
                    {if dr_count($ci->site_info) > 1}
                    <th> {dr_lang('站点划分')} </th>
                    {/if}
                </tr>
                </thead>
                <tbody>
                {php $top=[];}
                {loop $data $t}
                {php $t.pid == 0 && $top[] = $t.id; $t.group = dr_string2array($t.group);$t.site = dr_string2array($t.site);$t.client = dr_string2array($t.client);}
                {php $menu_level = $t['pid'] == 0 ? 1 : (dr_in_array($t['pid'], (array)$top) ? 2 : 3); }
                {php $menu_top_id = $t['pid'] == 0 ? $t['id'] : (dr_in_array($t['pid'], (array)$top) ? $t['pid'] : $t['tid']); }
                <tr class="odd gradeX {if $menu_level==1}menu-row-top{else}menu-row-child menu-row-top-{$menu_top_id}{/if}" id="dr_row_{$t.id}" data-top-id="{$menu_top_id}" data-level="{$menu_level}">
                    {if $ci->_is_admin_auth('del')}
                    <td class="myselect">
                        <label class="mt-table mt-table mt-checkbox mt-checkbox-single mt-checkbox-outline">
                            <input type="checkbox" class="checkboxes checkboxes{$t.tid} checkboxes{$t.pid} group-checkable" data-set=".checkboxes{$t.id}"  name="ids[]" value="{$t.id}" />
                            <span></span>
                        </label>
                    </td>
                    {/if}
                    <td class="hidden-mobile" style="text-align:center"> <input type="text" onblur="dr_ajax_save(this.value, '{dr_url('member/menu/save_edit', ['id'=>$t.id])}', 'displayorder')" value="{$t.displayorder}" class="displayorder form-control input-sm input-inline input-mini"> </td>
                    <td class="hidden-mobile" style="text-align:center">
                        <a href="javascript:;" onclick="dr_ajax_open_close(this, '{dr_url('member/menu/use_edit', ['id'=>$t.id])}', 1);" class="badge badge-{if $t.hidden}no{else}yes{/if}"><i class="fa fa-{if $t.hidden}times{else}check{/if}"></i></a>
                    </td>
                    <td>
                        {if $menu_level==1}<a href="javascript:;" class="menu-tree-toggle" data-top-id="{$t.id}"><i class="fa fa-caret-right"></i></a>{/if}
                        {$t.spacer} <a href="javascript:dr_iframe('edit', '{dr_url('member/menu/edit', ['id'=>$t.id])}');"><i class="{$t.icon}"></i> {dr_lang($t.name)}</a>
                    </td>
                    <td style="text-align:center">
                        {if $ci->_is_admin_auth('add') && $t.pid == 0}<a href="javascript:dr_iframe('add', '{dr_url('member/menu/add', ['pid'=>$t.id])}', '', '{if @in_array($t.pid, $top)}500px{/if}');" class="btn btn-xs blue"> <i class="fa fa-plus"></i> {dr_lang('添加')} </a>{/if}
                    </td>
                    <td>
                        {if !$t.group}<label><a title="{dr_lang('全部')}" class="btn btn-xs dark" style="background-color:#3fa9e4;border-color:#3fa9e4"> {dr_lang('全部')} </a></label>{/if}
                        {loop $t.group $b $gid}
                        <label id="dr_row_{$t.id}_{$gid}"><a href="javascript:dr_delete('{$t.id}', '{$gid}');" class="btn btn-xs {if $color[$b]}{$color[$b]}{else}default{/if}">{$group[$gid]['name']} <i class="fa fa-times"></i> </a></label>
                        {/loop}
                    </td>
                    <td>
                        {if !$t.client}<label><a title="{dr_lang('全部')}" class="btn btn-xs dark" style="background-color:#3fa9e4;border-color:#3fa9e4"> {dr_lang('全部')} </a></label>{/if}
                        {php $b=0;}
                        {loop $t.client $gid}
                        <label id="dr_client_{$t.id}_{$gid}"><a href="javascript:dr_client_delete('{$t.id}', '{$gid}');" class="btn btn-xs {if $color[$b]}{$color[$b]}{else}default{/if}">{$client[$gid]} <i class="fa fa-times"></i> </a></label>
                        {php $b++;}
                        {/loop}
                    </td>
                    {if dr_count($ci->site_info) > 1}
                    <td>
                        {if !$t.site}<label><a title="{dr_lang('全部')}" class="btn btn-xs dark" style="background-color:#3fa9e4;border-color:#3fa9e4"> {dr_lang('全部')} </a></label>{/if}
                        {loop $t.site $b $sid}
                        <label id="dr_site_{$t.id}_{$sid}"><a href="javascript:dr_site_delete('{$t.id}', '{$sid}');" class="btn btn-xs {if $color[$b]}{$color[$b]}{else}default{/if}">{$ci->site_info[$sid]['SITE_NAME']} <i class="fa fa-times"></i> </a></label>
                        {/loop}
                    </td>
                    {/if}
                </tr>
                {/loop}
                </tbody>
            </table>
        </div>

    </form>
</div>
<style>
    .menu-tree-toggle { display: inline-block; width: 14px; margin-right: 2px; color: #666; text-decoration: none; }
    .menu-tree-toggle:hover { color: #333; }
</style>
<script type="text/javascript">
    $(function () {
        $('.menu-row-top').each(function () {
            var topId = $(this).find('.menu-tree-toggle').data('top-id');
            var $rows = $('.menu-row-top-' + topId);
            if (!$rows.length) {
                $(this).find('.menu-tree-toggle').hide();
            } else {
                $rows.hide();
            }
        });
        $(document).on('click', '.menu-tree-toggle', function (e) {
            e.preventDefault();
            e.stopPropagation();
            var topId = $(this).data('top-id');
            var $icon = $(this).find('i');
            var $rows = $('.menu-row-top-' + topId);
            if ($icon.hasClass('fa-caret-down')) {
                $icon.removeClass('fa-caret-down').addClass('fa-caret-right');
                $rows.hide();
            } else {
                $icon.removeClass('fa-caret-right').addClass('fa-caret-down');
                $rows.show();
            }
        });
    });

    function dr_delete(id, gid) {
        {if !$ci->_is_admin_auth('del')}
        dr_tips(0, '{dr_lang('无权限删除')}');
        return;
        {/if}
            var index = layer.load(2, {
                shade: [0.3,'#fff'], //0.1透明度的白色背景
                time: 10000
            });
            $.ajax({
                type: "GET",
                cache: false,
                url: '{dr_url('member/menu/group_del')}&id='+id+'&gid='+gid,
            dataType: "json",
            success: function (json) {
            layer.close(index);
            if (json.code == 1) {
                $('#dr_row_'+id+'_'+gid).hide();
                dr_tips(1, json.msg);
            } else {
                dr_tips(0, json.msg);
            }
        },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, this, thrownError);;
            }
        });
        }
        function dr_client_delete(id, sid) {
                    {if !$ci->_is_admin_auth('del')}
                    dr_tips(0, '{dr_lang('无权限删除')}');
                    return;
                    {/if}
                        var index = layer.load(2, {
                            shade: [0.3,'#fff'], //0.1透明度的白色背景
                            time: 10000
                        });
                        $.ajax({
                            type: "GET",
                            cache: false,
                            url: '{dr_url('member/menu/client_del')}&id='+id+'&sid='+sid,
                        dataType: "json",
                        success: function (json) {
                        layer.close(index);
                        if (json.code == 1) {
                            $('#dr_client_'+id+'_'+sid).hide();
                            dr_tips(1, json.msg);
                        } else {
                            dr_tips(0, json.msg);
                        }
                    },
                        error: function(HttpRequest, ajaxOptions, thrownError) {
                            dr_ajax_alert_error(HttpRequest, this, thrownError);;
                        }
                    });
                    }
                    function dr_site_delete(id, sid) {
                                {if !$ci->_is_admin_auth('del')}
                                dr_tips(0, '{dr_lang('无权限删除')}');
                                return;
                                {/if}
                                    var index = layer.load(2, {
                                        shade: [0.3,'#fff'], //0.1透明度的白色背景
                                        time: 10000
                                    });
                                    $.ajax({
                                        type: "GET",
                                        cache: false,
                                        url: '{dr_url('member/menu/site_del')}&id='+id+'&sid='+sid,
                                    dataType: "json",
                                    success: function (json) {
                                    layer.close(index);
                                    if (json.code == 1) {
                                        $('#dr_site_'+id+'_'+sid).hide();
                                        dr_tips(1, json.msg);
                                    } else {
                                        dr_tips(0, json.msg);
                                    }
                                },
                                    error: function(HttpRequest, ajaxOptions, thrownError) {
                                        dr_ajax_alert_error(HttpRequest, this, thrownError);;
                                    }
                                });
                                }
</script>
{template "footer.html"}