@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    用户数据
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">用户数据</a></li>
                        <li class="breadcrumb-item active" aria-current="page">用户数据</li>
                    </ol>
                </nav>
            </div>

            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">

                            @if ($user_tab != '')
                                <div>
                                    <a href="#" onclick="javascript:history.back(-1);">返回到上一页</a>
                                </div>
                            @endif

                            <h4 class="card-title">用户数据</h4>
                            <form class="well form-inline margin-top-20" method="post" action='/admin/global/userlist'>
                                <div>
                                    @csrf
                                    <spen style="padding-left: 10px" >会员ID：</spen>
                                    <input class="form-control" type="text" name="GameID" id="GameID" value="{{$GameID}}" >
                                    <spen style="padding-left: 10px" >手机号：</spen>
                                    <input class="form-control" type="text" name="RegisterMobile" id="RegisterMobile" value="{{$RegisterMobile}}" >
                                    <spen style="padding-left: 10px" >上级ID：</spen>
                                    <input class="form-control" type="text" name="SpreaderID" id="SpreaderID" value="{{$SpreaderID}}" >
                                    <spen style="padding-left: 10px" >昵称：</spen>
                                    <input class="form-control" type="text" name="Compellation" id="Compellation" value="{{$Compellation}}">
                                    <spen style="padding-left: 10px" >注册时间：</spen>
                                    <input type="datetime-local"  step="01" name="start_time" id="start_time" class="form-control" value="{{$start_time}}" onclick="start_times()"/>
                                    <input type="datetime-local"  step="01" name="end_time" id='end_time' class="form-control" value="{{$end_time}}" onclick="end_times()"/><br>
                                    <spen style="padding-left: 10px" >渠道名称：</spen>
{{--                                    <input class="form-control" type="text" name="mobile" value="暂时无法使用"  disabled>--}}
                                    <select class="form-control" name="channel" value="{{$channel}}" style="color: black">
                                        <option value="">全部渠道</option>
                                        @foreach($channels as $key=>$val)
                                        <option value="{{$val}}" @if (  $channel == $val )
                                            selected
                                        @endif>{{$val}}</option>
                                        @endforeach

                                    </select> &nbsp;&nbsp;

                                    <input type="hidden" name="user_tab" value="{{$user_tab}}">
                                    <spen style="padding-left: 10px" >当前在线状态：</spen>
                                    <input class="form-control" type="text" name="mobile" value="暂时无法使用"  disabled>
                                    <spen style="padding-left: 10px" >VIP筛选：</spen>

                                    <select class="form-control" name="vip" value="{{$vip}}" style="color: black">
                                        <option value="">请选择</option>
                                        @for($i=1;$i<=6;$i++)
                                            @if($vip==$i)
                                                <option value="{{$i}}" selected>VIP {{$i}}</option>
                                            @else
                                                <option value="{{$i}}" >VIP {{$i}}</option>
                                            @endif

                                        @endfor
                                    </select> &nbsp;&nbsp;
                                    <spen style="padding-left: 10px" >账号筛选：</spen>

                                    <select class="form-control" name="accounts_type" value="{{$accounts_type}}" style="color: black">
                                        <option value="">请选择</option>
                                        @foreach($WebLogonTimes as $key=>$val)
                                            @if($accounts_type==$key)
                                                <option value="{{$key}}" selected>{{$val}}</option>
                                            @else
                                                <option value="{{$key}}" >{{$val}}</option>
                                            @endif

                                        @endforeach
                                    </select> &nbsp;&nbsp;

                                    <spen style="padding-left: 10px" >包名筛选：</spen>

                                    <select class="form-control" name="PackgeName" value="{{$PackgeName}}" style="color: black">
                                        <option value="">请选择</option>
                                       @foreach($ChannelPackageName as $val)
                                            @if($PackgeName==$val)
                                                <option value="{{$val}}" selected>{{$val}}</option>
                                            @else
                                                <option value="{{$val}}" >{{$val}}</option>
                                            @endif

                                        @endforeach
                                    </select> &nbsp;&nbsp;

                                    <a href="/admin/global/userlist" class="btn btn-sm btn-gradient-warning btn-icon-text">清空</a>
                                    <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="搜索"/>&nbsp;&nbsp;
                                    <br>

                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="1" onclick="search(1)" @isset($obj['checked1']) checked @endisset>游戏中
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="2" onclick="search(2)" @isset($obj['checked2']) checked @endisset>未实名
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="3" onclick="search(3)" @isset($obj['checked3']) checked @endisset>无手机号
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="4" onclick="search(4)" @isset($obj['checked4']) checked @endisset>同IP
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="5" onclick="search(5)" @isset($obj['checked5']) checked @endisset>无渠道
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="6" onclick="search(6)" @isset($obj['checked6']) checked @endisset>未充值
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="7" onclick="search(7)" @isset($obj['checked7']) checked @endisset>无上级
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="8" onclick="search(8)" @isset($obj['checked8']) checked @endisset>封号中
                                    <input class="form-control" type="checkbox" name="obj" id="radio" value="9" onclick="search(9)" @isset($obj['checked9']) checked @endisset>官方账号

                                    <a href="/admin/global/userlist?excel=1
                                    &GameID={{$GameID}}
                                        &RegisterMobile={{$RegisterMobile}}
                                        &SpreaderID={{$SpreaderID}}
                                        &Compellation={{$Compellation}}
                                        &start_time={{$start_time}}
                                        &end_time={{$end_time}}
                                        &vip={{$vip}}
                                        &channel={{$channel}}"
                                       class="btn btn-sm btn-gradient-light btn-icon-text">导出</a>
                                    @if (!session()->has('hidden'))
                                        <input type="button" onclick="ban(1)" class="btn btn-sm btn-gradient-dark btn-icon-text" value="批量封号"/>&nbsp;&nbsp;
                                        <input type="button" onclick="ban(2)" class="btn btn-sm btn-gradient-dark btn-icon-text" value="批量解封"/>&nbsp;&nbsp;
                                    @endif
                                </div>


                            </form>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="6%">
                                        <center>
                                            <button type="button" id="quan" onclick="checkbox()" class="btn btn-sm btn-gradient-primary btn-icon-text">
                                                全选/全不选
                                            </button>
                                        </center>
                                    </th>
                                    <th width="6%">会员ID</th>
                                    <th width="4%">昵称</th>
                                    <th width="6%">手机号</th>
                                    <th width="6%">IP</th>
                                    <th width="9%">
                                        <div class="sort_money">
                                            金豆余额
                                            <svg t="1611284352657" class="icon2" onclick="sort_money_func(this,'asc')"
                                                 viewBox="0 0 1024 1024" version="1.1"
                                                 xmlns="http://www.w3.org/2000/svg" p-id="4118" width="14">
                                                <path
                                                    d="M541.866667 285.866667l345.6 345.6c17.066667 17.066667 17.066667 42.666667 0 59.733333-8.533333 8.533333-19.2 12.8-29.866667 12.8H168.533333c-23.466667 0-42.666667-19.2-42.666666-42.666667 0-10.666667 4.266667-21.333333 12.8-29.866666l343.466666-345.6c17.066667-17.066667 42.666667-17.066667 59.733334 0z"
                                                    p-id="4119" fill="#707072">

                                                </path>
                                            </svg>

                                            <svg t="1611283709864" class="icon1" onclick="sort_money_func(this,'desc')"
                                                 viewBox="0 0 1024 1024" version="1.1"
                                                 xmlns="http://www.w3.org/2000/svg" p-id="3148" width="14">
                                                <path
                                                    d="M482.133333 738.133333L136.533333 392.533333c-17.066667-17.066667-17.066667-42.666667 0-59.733333 8.533333-8.533333 19.2-12.8 29.866667-12.8h689.066667c23.466667 0 42.666667 19.2 42.666666 42.666667 0 10.666667-4.266667 21.333333-12.8 29.866666L541.866667 738.133333c-17.066667 17.066667-42.666667 17.066667-59.733334 0z"
                                                    p-id="3149" fill="#707071">

                                                </path>
                                            </svg>
                                        </div>

                                    </th>
                                    <th width="6%">上级ID</th>
                                    <th width="6%">VIP等级</th>
                                    <th width="6%">当前在线状态</th>
                                    <th width="6%">注册日期</th>
                                    <th width="6%">渠道名称</th>
                                    <th width="6%">包名</th>
                                    <th width="6%">账号</th>
                                    <th width="8%">账号状态</th>
                                    <th width="6%">设置</th>
                                </tr>
                                </thead>
                                <tbody class="search_checkbox">
                                @foreach($list as $k=>$item)
                                    <tr>
                                        <td>
                                            <input class="form-control" type="checkbox" name="checkbox" id="{{$item->UserID}}"  value="" >
                                        </td>
                                        <td>
                                            <a href="/admin/global/id_find?UserID={{$item->UserID}}">
                                                {{$item->GameID}}
                                            </a>
                                        </td>
                                        <td>{{$item->NickName}}</td>
                                        <td>{{$item->PhoneNum}}</td>
                                        <td>
                                            <p>{{$item->RegisterIP}}</p>
                                            <p>{{$item->ipAddress}}</p>
                                        </td>
                                        <td>{{$item->Score}}</td>
                                        <td>{{$item->ain_GameID}}</td>
                                        <td>{{$item->MemberOrder}}</td>
                                        {{--                                        <td>无法统计</td>--}}

                                        <td>
                                            @if($item->ServerName != null)
                                                游戏中({{$item->ServerName}})
                                            @else
                                                离线
                                            @endif
                                        </td>

                                        <td>{{ date('Y-m-d H:i:s',strtotime($item->RegisterDate))}}</td>
                                        <td>{{$item->Channel}}</td>
                                        <td>{{$item->PackgeName}}</td>
                                        <td>
                                           @if ($item->WebLogonTimes == 2 || !empty($item->PhoneNum) )
                                                手机号
                                            @elseif($item->WebLogonTimes == 0)
                                                facebook
                                            @elseif($item->WebLogonTimes == 1)
                                                游客
                                            @endif
                                        </td>
                                        <td>{!! $item->Nullity !!}</td>
                                        <td>
                                        @if (empty(hidden()) || hidden() == 'general_administrator')

                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="update({{$item->UserID}})">
                                                修改
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                        @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix" id = "pages">
                                总共 <b>{{ $list->appends([
                                        'list'=>$list,
                                        'UserID'=>$UserID,
                                        'RegisterMobile'=>$RegisterMobile,
                                        'SpreaderID'=>$SpreaderID,
                                        'Compellation'=>$Compellation,
                                        'start_time'=>$start_time,
                                        'end_time'=>$end_time,
                                        'vip'=>$vip,
                                        'accounts_type' => $accounts_type,
                                        'build_str' => $build_str,
                                        'Score' => $Score,
                                        'user_tab' => $user_tab,
                                        'channel' => $channel,
                                        'PackgeName'=>$PackgeName
                                    ])->total() }}</b> 条,分为<b>{{ $list->lastPage() }}</b>页
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var search_arr = [];
        var search_arr1 = [];
        var first_str = '';



        function start_times() {

            getFormat('00', '00', '00');

            document.getElementById("start_time").value = format
        }

        function end_times() {
            getFormat('23', '59', '59');
            document.getElementById("end_time").value = format
        }


        function update(id){
            var page = layer.open({
                type: 2,
                title: '修改配置',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/global/user_update?id='+id
            });
        }
        function del(id){
            myConfirm("删除操作不可逆,是否继续?",function(){
                myRequest("/admin/accusation/del/"+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }
        function checkbox(){
            var num=document.getElementsByName('checkbox');
            for(var i=0;i<num.length;i++){
                if(num[i].checked){
                    num[i].checked=false;
                }else{
                    num[i].checked=true;
                }
            }
        }
        function ban(ban){
            //1封号 2解封
            var num=document.getElementsByName('checkbox');
            var str='';
            for(var i=0;i<num.length;i++){
                if(num[i].checked){
                    str=str+num[i].id+',';
                }
            }
            if (str==''){
                alert('请选择要操作的数据');return false;
            }
            var id=str.substr(0,str.length-1);
            myConfirm("是否继续账户操作?",function(){
                myRequest("/admin/global/ban","post",{id:id,ban:ban},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
            return false;
        }
        /*   function rad(obj){
               location.href='/admin/global/userlist?obj='+obj;
           }*/

        function search(value) {
            var start_time   = $("#start_time").val();
            var end_time   = $("#end_time").val();


            if (localStorage.getItem('search') === ''){
                localStorage.setItem('search',value)
            }else {
                if (localStorage.getItem('search') !== null){
                    first_str += localStorage.getItem('search') + ','
                }

            }

            var sub_str = first_str.indexOf(value)
            if (sub_str < 0){
                first_str += value + ','
            }else {
                localStorage.removeItem("search");
                first_str = first_str.replace(value+',','')
            }

            search_arr = first_str.split(',')

            $.ajax({
                type:"get",
                url:"/admin/global/userlist",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data:{search:search_arr,start_time:start_time,end_time:end_time},
                success:function(msg){
                    if(msg){
                        $(".main-panel").html(msg)
                    }
                }
            })

            return false;

        }
        function sort_money_func(obj, val) {

            if (val == 'asc') {
                $(".sort_money svg:eq(1)").children('path').attr('fill', '#707071');
                $(obj).children('path').attr('fill', 'red')

            } else {
                $(obj).children('path').attr('fill', 'red')
                $(".sort_money svg:eq(0)").children('path').attr('fill', '#707071');
            }

            $.ajax({
                type: "post",
                url: "/admin/global/userlist",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: {Score: val},
                success: function (msg) {

                    if (msg) {
                        $(".main-panel").html(msg)

                    }
                }
            })
        }

    </script>
@endsection
