@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <style type="text/css">
        .table th {
            padding: 0.5375rem;
            vertical-align: top;
            border-top: 1px solid #ebedf2;
        }
    </style>
    <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">
                            <h4 class="card-title">{{ __('auto.游戏配置修改') }}</h4>
                            <form class="well form-inline margin-top-20" method="get" action='/admin/gold/gameconfig'>
                                <span style="padding-left: 5px">{{ __('auto.游戏：') }}</span>
                                <select class="form-control" name="kind_id" value="{{$kind_id}}" id="select"
                                        onchange="gradeChange(this.options[this.options.selectedIndex].value)">
                                    <option value="">{{ __('auto.选择游戏') }}</option>
                                    @foreach($game_name as $k=>$v)
                                        <option value="{{$k}}" @if($k==$kind_id) selected @endif >{{$v}}</option>
                                    @endforeach
                                </select>
                                <span style="padding-left: 5px">{{ __('auto.房间：') }}</span>
                                <select class="form-control" name="game_level" value="" id="game_level">
                                    <option value="">{{ __('auto.选择房间') }}</option>
                                    @foreach($room_list as $k=>$v)
                                        <option value="{{$v->ServerID}}"
                                                @if($v->ServerID==$game_level) selected @endif>{{$v->ServerName}}</option>
                                    @endforeach
                                </select> &nbsp;&nbsp;
                                <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="{{ __('auto.搜索') }}"/>&nbsp;&nbsp;
                                <a href="/admin/gold/gameconfig" class="btn btn-sm btn-gradient-warning btn-icon-text">{{ __('auto.清空') }}</a>
                            </form>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th width="6%">{{ __('auto.游戏') }}ID</th>
                                    <th width="6%">{{ __('auto.房间状态') }}</th>
                                    <th width="6%">{{ __('auto.游戏名称') }}</th>
                                    <th width="6%">{{ __('auto.房间累计税收') }}</th>
                                    <th width="6%">{{ __('auto.房间累计暗税') }}</th>
                                    <th width="6%">{{ __('auto.游戏房间') }}</th>
                                    <th width="6%">{{ __('auto.游戏库存') }}</th>

                                    <th width="6%">{{ __('auto.当前触发概率') }}</th>
                                    <th width="6%">{{ __('auto.档位基准值') }}</th>
                                    <th width="6%">{{ __('auto.系统赢初始概率') }}</th>
                                    <th width="6%">{{ __('auto.系统输初始概率') }}</th>
                                    <th width="6%">{{ __('auto.系统赢增加概率/档位') }}</th>
                                    <th width="6%">{{ __('auto.系统赢增加概率上限') }}</th>
                                    <th width="6%">{{ __('auto.系统输增加概率/档位') }}</th>
                                    <th width="6%">{{ __('auto.系统输增加概率上限') }}</th>

                                    <th width="10%">{{ __('auto.操作') }}</th>
                                </tr>
                                </thead>
                                <tbody>

                                {{ gamesButton('/admin/gold/gameconfig') }}


                                @foreach($list as $k=>$v)
                                    <tr>
                                        <td>{{ $v->KindID }}</td>
                                        <td>
                                            @if ($v->Nullity == 1)
                                                <span style="color: red">{{ __('auto.关闭') }}</span>
                                            @else
                                                <span style="color: #0bb20c">{{ __('auto.开启') }}</span>
                                            @endif
                                        </td>
                                        <td>{{ $v->KindName }}</td>
                                        <td>{{ $v->Revenue}}</td>
                                        <td>{{ $v->darkRevenue}}</td>
                                        <td>{{ $v->ServerName }}</td>
                                        <td id="stock">{{ $v->RoomStock }}</td>
                                        <td>
                                            @if ($v->RoomStock < 0 and $v->gailv != '')
                                                {{ __('auto.系统') }} <span style="color: red">{{ __('auto.赢') }}</span> {{ __('auto.玩家') }}
                                                {{$v->gailv}}%
                                            @elseif($v->RoomStock > 0 and $v->gailv != '')
                                                {{ __('auto.系统') }} <span style="color: green">{{ __('auto.输') }}</span> {{ __('auto.玩家') }}
                                                {{$v->gailv}}%
                                            @endif
                                        </td>
                                        <td>{{ $v->BaseScore}}</td>
                                        <td>{{ $v->WinInitPercent}}</td>
                                        <td>{{ $v->LostInitPercent}}</td>
                                        <td>{{ $v->WinBasePercent}}</td>
                                        <td>{{ $v->WinMaxPercent}}</td>
                                        <td>{{ $v->LostBasePercent}}</td>
                                        <td>{{ $v->LostMaxPercent}}</td>
                                        <td>
{{--                                            @if (empty(hidden()) || hidden() == 'general_administrator')--}}

{{--                                                <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text"--}}
{{--                                                        onclick="edit({{ $v->gi_ServerID }})">--}}
{{--                                                    {{ __('auto.修改') }}--}}
{{--                                                </button>--}}
{{--                                            @endif--}}
                                            {{--                                            <button type="button" class="btn btn-sm btn-facebook btn-icon-text"--}}
                                            {{--                                                    onclick="show({{$v->gi_ServerID}})">--}}
                                            {{--                                                {{ __('auto.查配置') }}--}}
                                            {{--                                            </button>--}}
                                            <button type="button" class="btn btn-sm btn-facebook btn-icon-text"
                                                    onclick="sync_stock(this,{{$v->gi_ServerID}})">
                                                {{ __('auto.更新库存') }}
                                            </button>
                                            @if (empty(hidden()) || hidden() == 'general_administrator')
                                                <button type="button"
                                                        class="btn btn-sm btn-gradient-danger btn-icon-text"
                                                        onclick="update_stock({{$v->gi_ServerID}})">
                                                    {{ __('auto.修改库存') }}
                                                </button>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                {{ __('auto.总共') }} <b>{{ $list->appends([
    'kind_id'=>$kind_id,
    'gameType' => $gameType,
    'game_level' => $game_level
    ])->total() }}</b>
                                {{ __('auto.条,分为') }}<b>{{ $list->lastPage() }}</b>{{ __('auto.页') }}
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

        function edit(id) {
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.配置修改') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '60%'],
                content: '/admin/gold/gameconfig/update/' + id
            });
        }

        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
            });
        }

        // 修改库存
        function update_stock(serverID) {

            var page = layer.open({
                type: 2,
                title: '{{ __('auto.修改库存') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['50%', '80%'],
                content: '/admin/gold/update_stock/' + serverID
            });

        }

        // 更新库存
        function sync_stock(obj, serverID) {

            // 库存
            var stock = $(obj).parents('tr').find('td').eq(6);
            // 税收
            // var revenue = $(obj).parents('tr').find('td').eq(3);

            myRequest("/admin/gold/sync_stock/" + serverID, "post", {}, function (res) {

                layer.msg(res.msg)
                if (res.code == 200) {
                    stock.text(res.data.data.stock);
                    // revenue.text(res.data.data.revenue);
                }

            });

        }

        function gradeChange(value) {

            myRequest("/admin/gold/roomlist", "post", {'GameID': value}, function (res) {
                // layer.msg(res.msg)
                var data = res.data
                var html = ''
                for (var i of data) {
                    html += '<option value=' + i['ServerID'] + '>' + i['ServerName'] + '</option>'
                }
                $("#game_level").html(html)
            });
        }

    </script>
@endsection
