@extends('layouts.admin')
@section('content')
    <!--左侧菜单栏-->

@include('admin.left-sidebar')

    <!-- 内容 -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                首页
                <small> </small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{{ url('/')}}"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">用户管理</a></li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="content">
            <!-- Default box -->
            <div class="box">
                <div class="box-header">
                    <div class="row">
                        <div class="col-sm-11">
                            <h3 class="box-title">用户列表</h3>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-11"></div>
                        <div class="col-sm-1">
                            @if($user->role>4)
                                <a href="{{ url('/user/create') }}">
                                    <button class="btn btn-block btn-primary btn-sm">
                                        <i class="fa fa-plus"> 新增</i>
                                    </button>
                                </a>
                                @endif
                        </div>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                        <div class="row">
                            <div class="col-sm-6"></div>
                            <div class="col-sm-6"></div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="example2" class="table table-bordered table-hover dataTable" role="grid" aria-describedby="example2_info">
                                    <thead>
                                    <tr role="row">
                                        <th>ID</th>
                                        <th>登录名</th>
                                        <th>职位</th>
                                        <th>单位</th>
                                        <th>操作</th>

                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($data as $list)
                                    <tr role="row" class="odd">
                                        <td>{{ $list->id }}</td>
                                        <td>{{ $list->name }}</td>
                                        <td>{{ $list->job_name }}</td>
                                        <td>{{ $list->department }}</td>
                                        <td>
                                            @if($user->role > 4)
                                                <a href="{{ url('/user/'.$list->id.'/edit') }}" class="btn btn-primary btn-sm">
                                                    <i class="fa fa-pencil"></i> 编辑</a>
                                                @if($list->display == 1)
                                                    <a href="javascript:;" onclick="del_user({{ $list->id }})" class="btn btn-danger btn-sm article-delete">
                                                        <i  class="fa fa-close"></i> 停用</a>
                                                @else
                                                    <a href="javascript:;" onclick="start({{ $list->id }})" class="btn btn-success btn-sm article-delete">
                                                        <i  class="fa fa-check"></i> 启用</a>
                                                @endif
                                                @else
                                                您的权限不足
                                            @endif
                                        </td>
                                    </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-5">
                                <div class="dataTables_info" id="example2_info" role="status" aria-live="polite">显示 0 - 20 总计  </div>
                            </div>
                            <div class="col-sm-7">
                                <div class="dataTables_paginate paging_simple_numbers" id="example2_paginate">
                                    <ul class="pagination">
                                        {{ $data->links() }}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

<script>
    function del_user(user_id){
        layer.confirm('确定要停用这个用户吗？',{
            btn:['确定','取消']
        },function(){
            $.post('{{ url('/user/ting') }}/'+user_id,{
                '_token' :'{{ csrf_token() }}'
            },function(data){
                if(data.status == 1){
                    location.href = location.href;
                    layer.alert(data.msg, {icon: 6});
                }else {
                    layer.alert(data.msg, {icon: 5});
                }
            });
        },function(){

        });
    }

    function start(user_id){
        layer.confirm('确定要启用这个用户吗？',{
            btn:['确定','取消']
        },function(){
            $.post('{{ url('/user/start') }}/'+user_id,{
                '_token' :'{{ csrf_token() }}'
            },function(data){
                if(data.status == 1){
                    location.href = location.href;
                    layer.alert(data.msg, {icon: 6});
                }else {
                    layer.alert(data.msg, {icon: 5});
                }
            });
        },function(){

        });
    }

</script>

@endsection