@extends('admin.layout')

@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户管理</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <form method="GET" action="" accept-charset="UTF-8">

                                <div class="col-sm-8">


                                    <div class="form-group col-sm-8" >
                                        <label class="radio-inline">
                                            <input type="radio" name="role" value="-1"
                                                   @if(empty(Request::get('role')) || Request::get('role') == '-1')checked="checked" @endif/>全部
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="role" value="0"
                                                   @if(!empty(Request::get('role')) && Request::get('role') == '0')checked="checked" @endif/>普通用户
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="role" value="1"
                                                   @if(!empty(Request::get('role')) && Request::get('role') == '1')checked="checked" @endif/>生产部
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="role" value="2"
                                                   @if(!empty(Request::get('role')) && Request::get('role') == '2')checked="checked" @endif/>包装部
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="role" value="3"
                                                   @if(!empty(Request::get('role')) && Request::get('role') == '3')checked="checked" @endif/>经理
                                        </label>
                                    </div>
                                    <div class="input-group col-sm-4">
                                        <input type="text" value="{{Request::get('keyword')}}" placeholder="请输入昵称/电话"
                                               name="keyword" class="input-sm form-control">
                                        <span class="input-group-btn">
									<button type="submit" class="btn btn-sm btn-primary">搜索</button>
								</span>
                                    </div>
                                </div>
                            </form>
                        </div>

                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                            <thead>
                            <tr>
                                <th class="sorting" data-sort="id">ID</th>
                                <th class="sorting" data-sort="username"> 微信昵称 </th>
                                <th class="sorting" data-sort="avatar"> 用户头像</th>
                                <th class="sorting" data-sort="phone"> 电话</th>
                                <th class="sorting" data-sort="is_dealer"> 售后角色</th>
                                <th class="sorting" data-sort="created_at"> 加入时间</th>
                                <th width="22%">相关操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(isset($list))
                                @foreach($list as $key => $item)
                                    <tr>

                                        <td>{{ $item->id }}</td>
                                        <td>{{ $item->username }}</td>
                                        <td><img src="{{ $item->avatar }}" width="50px"/></td>
                                        <td>{{ $item->phone }}</td>
                                        <td>{{ $item->created_at }}</td>
                                        <td>{{ $item->role() }}</td>
                                        <td>
                                            @if(role('Album/User/role'))
                                                    @if($item->role !== 0)
                                                        <button onclick="window.location.href='{{ U('Album/User/role',['id'=>$item->id,'role'=>0]) }}'"
                                                                class="btn btn-default">设为普通用户
                                                        </button>
                                                    @endif

                                                    @if($item->role !== 1)
                                                        <button onclick="window.location.href='{{ U('Album/User/role',['id'=>$item->id,'role'=>1]) }}'"
                                                                class="btn btn-primary">设为生产部
                                                        </button>
                                                    @endif
                                                    @if($item->role !== 2)
                                                        <button onclick="window.location.href='{{ U('Album/User/role',['id'=>$item->id,'role'=>2]) }}'"
                                                                class="btn btn-info">设为包装部
                                                        </button>
                                                    @endif
                                                    @if($item->role !== 3)
                                                        <button onclick="window.location.href='{{ U('Album/User/role',['id'=>$item->id,'role'=>3]) }}'"
                                                                class="btn btn-success">设为经理
                                                        </button>
                                                    @endif
                                            @endif

                                        </td>
                                    </tr>
                                @endforeach
                            @endif

                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" id="DataTables_Table_0_info"
                                     role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}
                                    条，共{{ $list->lastPage() }}页，总{{ $list->total() }}条。
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                    {!! $list->setPath('')->appends(Request::all())->render() !!}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection