@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>
                    {{ __('auto.无感维护开关') }}
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">{{ __('auto.无感维护开关') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('auto.用户数据') }}</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <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">
                                                {{ __('auto.全选/全不选') }}
                                            </button>
                                        </center>
                                    </th>
                                    <th width="10%">{{ __('auto.游戏房间名称') }}</th>
                                    <th width="4%">{{ __('auto.状态') }}</th>
                                    <th width="6%">{{ __('auto.当前房间人数') }}</th>
                                    <th width="8%">{{ __('auto.设置') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                <button class="btn btn-sm btn-gradient-dark" onclick="switch_more('on')">{{ __('auto.批量开启') }}</button> &nbsp;&nbsp;&nbsp;
                                <button class="btn btn-sm btn-gradient-dark" onclick="switch_more('off')">{{ __('auto.批量关闭') }}</button>

                                @foreach($list as $k=>$v)

                                    <tr>
                                        <td>
                                            <input class="form-control" type="checkbox" name="checkbox"
                                                   id="{{$v->ServerID}}" value="">
                                        </td>
                                        <td>{{$v->ServerName}}</td>
                                        <td>
                                            @if ($v->Nullity == 1)
                                                {{ __('auto.关闭') }}
                                            @else
                                                {{ __('auto.开启') }}
                                            @endif
                                        </td>
                                        <td>{{$v->game_count}}</td>


                                        <td>

                                            @if ($v->Nullity == 1)
                                                <button type="button" class="btn btn-sm btn-success btn-icon-text"
                                                        onclick="update({{$v->ServerID}},'on')">
                                                    {{ __('auto.开启') }}
                                                </button>
                                            @else
                                                <button type="button" class="btn btn-sm btn-danger btn-icon-text"
                                                        onclick="update({{$v->ServerID}},'off')">
                                                    {{ __('auto.关闭') }}
                                                </button>

                                            @endif

                                            <button type="button" class="btn btn-sm btn-facebook btn-icon-text"
                                                    onclick="show({{$v->ServerID}})">
                                                {{ __('auto.查配置') }}
                                            </button>
                                        </td>
                                    </tr>
                                @endforeach

                                </tbody>
                            </table>
                            @empty($list)
                                <td>{{ __('auto.暂无数据') }}</td>
                            @endempty
                        </div>

                    </div>

                </div>

            </div>
        </div>
    </div>
    <script>
        function switch_more(type) {

            var num = document.getElementsByName('checkbox');
            var serverID = '';
            for (var i = 0; i < num.length; i++) {
                if (num[i].checked) {
                    serverID = serverID + num[i].id + ',';
                }
            }
            if (serverID == '') {
                layer.msg('{{ __('auto.请选择要操作的数据') }}');
                return false;
            }

            myConfirm("{{ __('auto.删除操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/global/game_room_switch", "post", {serverID, type}, 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 update(serverID, type) {
            myConfirm("{{ __('auto.是否继续') }}?", function () {
                myRequest("/admin/global/game_room_switch", "post", {serverID, type}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            });
        }

        function show(value) {
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.查看配置') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '60%'],
                content: '/admin/global/show_config/' + value
            });
        }

    </script>
@endsection
