<!DOCTYPE html>
<html>

@include('admin.common_bak.commonMedia')

<body>

<!--====================================================
                         MAIN NAVBAR
======================================================-->
@include('admin.common_bak.header')

<!--====================================================
                        PAGE CONTENT
======================================================-->
<div class="page-content d-flex align-items-stretch">

    <!--***** SIDE NAVBAR *****-->
    @include('admin.common_bak.left')

    <div class="content-inner chart-cont">

        <div class="card form">
            <div class="card-header">
                <h3><i class="fa fa-user-circle"></i> 管理员列表</h3>
            </div>
            <br>

            <!--***** CONTENT *****-->
            <div class="row ml20">
                <xblock>
                    <button class="btn btn-primary" onclick="x_admin_show('/web/role_add')">
                        添加
                    </button>
                    <span class="x-right" >共有数据：{{$count}} 条</span>
                </xblock>

                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th style="width: 70px;">角色名</th>
                        <th>拥有权限规则</th>
                        <th style="width: 70px;">描述</th>
                        <th style="width: 70px;">操作</th>
                    </thead>
                    <tbody>
                    @if(count($roles)>0)
                        @foreach($roles as $key=> $v)
                            <tr class="<?php if($key%2==0) echo 'table-success';?>">
                                <td>{{$v['id']}}</td>
                                <td>{{$v['name']}}</td>
                                <td>
                                    @foreach($v['bs'] as $per)
                                        {{$per['name']}}，
                                    @endforeach
                                </td>
                                <td>{{$v['description']}}</td>

                                <td class="td-manage">
                                    <a title="编辑"   href="/web/role_edit/{{$v["id"]}}">
                                        <i class="iconfont">&#xe609;</i>
                                    </a>
                                    {{--<a title="删除" onclick="member_del(this,'{{$v["id"]}}')" href="javascript:;">--}}
                                    {{--<i class="layui-icon">&#xe640;</i>--}}
                                    {{--</a>--}}
                                </td>
                            </tr>
                        @endforeach
                    @else
                        <tr>
                            <td  colspan="6" style="text-align:center">暂无数据</td>
                        </tr>
                    @endif
                    </tbody>
                </table>

                {{--<div class="page">--}}
                {{--<div>--}}
                {{--{{$roles->appends(['start_time'=>$start_time,'end_time'=>$end_time,'name'=>$name])->links()}}--}}
                {{--</div>--}}
                {{--</div>--}}
            </div>
        </div>


    </div>
</div>

<!--Global Javascript -->
@include('admin.common_bak.foot')

<!--Core Javascript -->
<link rel="stylesheet" href="{{ asset('xadmin/extra/jqueryConfirm/css/jquery-confirm.css')}}">
<script src="{{ asset('xadmin/extra/jqueryConfirm/js/jquery-confirm.min.js')}}"></script>

<script src="{{ asset('xadmin/extra/toast/js/toast.js')}}"></script>
{{--<link rel="stylesheet" href="{{ asset('xadmin/extra/toast/css/toast.css')}}">--}}

<script src="{{ asset('xadmin/js/jquery.validate.js')}}"></script>

<script type="text/javascript">
    function x_admin_show(url){
        window.location.href = url;

        // window.open(url);
    }

    function member_del(row,id){


        $.confirm({
            // confirmButtonClass: 'btn-info',
            // cancelButtonClass: 'btn-info',
            cancelButtonClass: 'btn-info',
            confirmButtonClass: 'btn-danger',


            confirm: function () {
                fetch_response('DELETE',"/web/member/"+id).then(function (res) {
                    $('body').toast({
                        position:'fixed',
                        content:res.msg,
                        duration:1000,
                        top:'50%'
                    });
                    setTimeout(function () {
                        window.location.href='/web/member';
                    },2000)
                })

            },
            cancel: function () {
                $.alert('cancel triggered!');
            }
        });
    }


    function member_stop(obj,id){

        var title = $(obj).attr('title');
        var opts = new FormData();
        opts.append('_token', "{{csrf_token()}}")
        $.confirm({
            // confirmButtonClass: 'btn-info',
            // cancelButtonClass: 'btn-info',
            cancelButtonClass: 'btn-info',
            confirmButtonClass: 'btn-danger',
            content:'确认要'+title+'吗？',
            confirmButton:'确认',
            cancelButton:'取消',

            confirm: function () {



                if(title == '停用'){
                    //发异步把用户状态进行更改
                    opts.append('id',id);
                    opts.append('status',0);
                    fetch_response('POST','/web/member/disable',opts).then(function(res){
                        if(res.code == 200){
                            $(obj).attr('title','启用')
                            $(obj).find('i').html('&#xe79e;');
                            $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                            // layer.msg('已停用!',{icon: 5,time:1000},function(){
                            //     window.location.reload();
                            // });

                            $('body').toast({
                                position: 'fixed',
                                content: '已停用',
                                duration: 1000,
                                top: '50%'
                            });
                            setTimeout(function () {
                                window.location.href = '/web/member';
                            }, 2000)


                        }else{
                            $('body').toast({
                                position: 'fixed',
                                content: res.msg,
                                duration: 1000,
                                top: '50%'
                            });
                        }
                    });
                }else{
                    opts.append('id',id);
                    opts.append('status',1);
                    fetch_response('POST','/web/member/disable',opts).then(function(res){
                        if(res.code == 200){
                            $(obj).attr('title','停用')
                            $(obj).find('i').html('&#xe689;');

                            $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                            // layer.msg('已启用!',{icon: 6,time:1000},function(){
                            //     window.location.reload();
                            // });

                            $('body').toast({
                                position: 'fixed',
                                content: '已启用',
                                duration: 1000,
                                top: '50%'
                            });
                            setTimeout(function () {
                                window.location.href = '/web/member';
                            }, 2000)
                        }else{
                            $('body').toast({
                                position: 'fixed',
                                content: res.msg,
                                duration: 1000,
                                top: '50%'
                            });
                        }
                    });

                }


                // fetch_response('DELETE',"/web/member/"+id).then(function (res) {
                //     $('body').toast({
                //         position:'fixed',
                //         content:res.msg,
                //         duration:1000,
                //         top:'50%'
                //     });
                //     setTimeout(function () {
                //         window.location.href='/web/member';
                //     },2000)
                // })

            },
            // cancel: function () {
            //     $.alert('cancel triggered!');
            // }
        });

    }

</script>

</body>

</html>