@extends('admin.master')

@section('top')
    <div class="top-breadcrumb">
        <h5>用户设置</h5>
    </div>
@endsection

@section('ordersearch')
    <div class="order-search mb-10">
        <div class="clearfix">
            <div class="top-btn-group pull-left">
                @if(config('managerLang') == config('setting.lang'))
                    <a href="{{ url('admin/team/user/create') }}" class="btn btn-primary">
                        <i class="iconfont icon-plus"></i><span>添加成员</span>
                    </a>
                @endif
            </div>
            <div class="pull-right">
                {!! Form::model($where, ['method'=>'get', 'class'=>'form-inline', 'id' => 'form-select']) !!}
                <div class="form-group pr-10">
                    {!! Form::text('wd', null, ['class'=>'form-control len wd-search', 'id'=>'kw', 'placeholder'=>'请输入姓名/邮箱/手机号']) !!}
                </div>
                <div class="form-group pr-10">
                    {!! Form::select('team_id', ['' => '选择分类'] + $team, null, ['id'=>'pidCate', 'class'=>'form-control']) !!}
                </div>
                <button type="submit" class="btn btn-primary">
                    <i class="iconfont icon-sousuo2"></i>
                </button>
                <button class="btn btn-default ml-10 toggleUser">显示禁用成员</button>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
@endsection

@section('content')
    {!! Form::open(['route' => 'admin.team.user.index', 'method' => 'post', 'class'=>'form-ajax']) !!}
    <table class="table table-hover">
        <thead>
        <tr>
            <th>头像</th>
            <th>用户名</th>
            <th>姓名</th>
            <th>职位</th>
            <th>邮箱</th>
            <th>手机号</th>
            <th>团队</th>
            <th>状态</th>
            <th class="text-center">操作</th>
        </tr>
        </thead>
        <tbody>
        @if(!$users->isEmpty())
            @foreach ($users as $value)
                <tr>
                    <td>
                        @if(!empty($value->icon))
                            <a href="{{ $value->icon }}" class="img" target="_blank">
                                <img src="{{ $value->present()->icons('38*38') }}" class="user-img-list">
                            </a>
                        @else
                            <span class="changegray">暂无图片</span>
                        @endif
                    </td>
                    <td>{{ $value->username }}</td>
                    <td>{{ $value->name }}</td>
                    <td>{{ $value->position }}</td>
                    <td>{{ $value->email }}</td>
                    <td>{{ $value->phone ? $value->phone : '---' }}</td>
                    <td>{{$value->is_team}}</td>
                    <td>
                        @if($value->status == 1)
                            <span class="changegreen">启用</span>
                        @else
                            <span class="changegray">禁用</span>
                        @endif
                    <td>
                        <div class="toolbar">
                            <a href="{{ route('admin.team.user.edit', $value->id) }}" class="btn-link">修改</a>
                            <span class="text-explode ">|</span>
                            <a href="javascript:void(0);" class="btn-link changeStatus" data-id="{{$value->id}}" data-status="{{$value->status}}">{{ $value['status'] == 1 ? '禁用' : '启用'}}</a>
                        </div>
                    </td>
                </tr>
            @endforeach
            <tr class="footer">
                <td class="text-left" colspan="9">
                    <div class="foot-wrap">
                        @if(!empty($users->render()))
                            <div class="pull-right">
                                <div class="pagination-info">共有{{ $products->total() }}条</div>
                                <div class="pagination-info" style="padding-left: 0">
                                    <select id="perPage" class="form-control autosize selectpicker show-tick" name="perPage" form="form-select">
                                        <option {{ $users->perPage() == 20 ? 'selected': ''}} value="20">20条/页</option>
                                        <option {{ $users->perPage() == 30 ? 'selected': ''}} value="30">30条/页</option>
                                        <option {{ $users->perPage() == 50 ? 'selected': ''}} value="50">50条/页</option>
                                        <option {{ $users->perPage() == 100 ? 'selected': ''}} value="100">100条/页</option>
                                    </select>
                                </div>
                                {!! $users->appends($where)->render() !!}
                            </div>
                        @endif
                    </div>
                </td>
            </tr>
        @endif
        </tbody>
    </table>
    @if($users->isEmpty())
        <div class="nodata-wrap">
            <div class="notice-null"><span class="inline-block">暂无数据</span></div>
        </div>
    @endif

    {!! Form::close() !!}
@endsection

@section('notice')
@endsection

@section('foot')
    <script type="text/javascript">
        const search  = window.location.search
        if (search.indexOf('status=2') > -1) {
            $('.toggleUser').text('显示启用成员')
        } else {
            $('.toggleUser').text('显示禁用成员')
        }
        $(".toggleUser").click(function (e) {
            e.preventDefault()
            var href = window.location.href
            var status = ''
            if (search.length > 0) {
                if (search.indexOf('status') > -1) {
                    if (search.indexOf('status=1') > -1) {
                        href = href.replace(/([?&])status=1/, '$1status=2')
                    } else {
                        href = href.replace(/([?&])status=2/, '$1status=1')
                    }
                    window.location.href = href
                } else {
                    status = '&status=2'
                }
            } else {
                status = '?status=2'
            }
            window.location.href = href + status
        })
        var HOME_URL = "{{ url('/') }}";
        $(".changeStatus").click(function () {
            const id = $(this).attr('data-id')
            const status = $(this).attr('data-status')
            var str = status == 1 ? 2 : 1
            const url = HOME_URL + '/admin/team/user/'+id+'/status'
            $.post(url, {status: str}, function (res) {
                if (res.code == 200) {
                    swal({
                        title: "",
                        text: '状态修改成功',
                        type: "success",
                        timer: 1000,
                    });
                } else {
                    swal({
                        title: "",
                        text: '状态修改失败请重试',
                        type: "error",
                        timer: 1000,
                    });
                }
                setTimeout(function () {
                    window.location.reload()
                }, 1100)
            })
        })
    </script>
@endsection
