<!doctype html>
@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">
                        <h4 class="card-title">{{ __('auto.群控房间配置') }}</h4>



                        <form class="well form-inline margin-top-20" method="get"
                              action='/admin/group_control/room'>
                            <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->GameID}}-{{$v->SortID}}"
                                            @if(($v->GameID.'-'.$v->SortID)==$game_level) selected @endif>{{$v->RoomName}}</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/group_control/room"
                               class="btn btn-sm btn-gradient-warning btn-icon-text">{{ __('auto.清空') }}&{{ __('auto.刷新') }}</a> &nbsp;&nbsp;

                            <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="add()">
                                <i class="mdi mdi-plus btn-icon-prepend"></i>
                                {{ __('auto.增加房间配置') }}
                            </button>
                        </form>
                        <br>
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th >{{ __('auto.游戏') }}ID</th>
                                <th >{{ __('auto.场次') }}</th>
                                <th >{{ __('auto.房间名称') }}</th>
                                <th >{{ __('auto.房间赢金币上限参数') }}</th>
                                <th >{{ __('auto.房间新手保护') }}</th>
                                <th >{{ __('auto.房间控制上限参数') }}</th>
                                <th >{{ __('auto.底分参数') }}</th>
                                <th >{{ __('auto.操作') }}</th>
                            </tr>
                            </thead>
                            <tbody>

                            {{ gamesButton() }}


                            @foreach($list as $k=>$v)
                                <tr>
                                    <td>{{ $v->GameID }}</td>
                                    <td>{{ $v->SortID }}</td>
                                    <td>{{ $v->RoomName }}</td>
                                    <td>{{ $v->WinMax }}</td>
                                    <td>{{ $v->NewManProt }}</td>
                                    <td>{{ $v->ControlMax }}</td>
                                    <td>{{ $v->CellParam }}</td>
                                    <td>
                                        <button class="btn btn-sm btn-gradient-dark" onclick="edit({{$v->ID}})">{{ __('auto.修改') }}</button>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div class="box-footer clearfix">
                            {{ __('auto.总共') }} <b>{{ $list->appends([
    'kind_id'=>$kind_id,
    'gameType' => $gameType

    ])->total() }}</b>
                            {{ __('auto.条,分为') }}<b>{{ $list->lastPage() }}</b>{{ __('auto.页') }}
                            {!! $list->links() !!}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    function add() {
        var page = layer.open({
            type: 2,
            title: '{{ __('auto.添加配置') }}',
            shadeClose: true,
            offset: 't',
            shade: 0.8,
            area: ['60%', '70%'],
            content: '/admin/group_control/room_add'
        });
    }

    function edit(id) {

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

    function show(GameID, SortID) {
        layer.ready(function () {
            // 弹框代码
            var page = layer.open({

                type: 2,
                title: '{{ __('auto.查看配置') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '60%'],

                content: '/admin/group_control/show_control_config/' + GameID + '?SortID=' + SortID,

            });
        })


    }

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

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

    }

    // 更新库存
    function sync_res(obj, GameID, SortID) {

        // 库存
        var Revenue = $(obj).parents('tr').find('td').eq(3);
        var RevenueD = $(obj).parents('tr').find('td').eq(4);
        var Stock = $(obj).parents('tr').find('td').eq(6);
        var TurnOver = $(obj).parents('tr').find('td').eq(7);
        var Winlost = $(obj).parents('tr').find('td').eq(8);
        var ShaLv = $(obj).parents('tr').find('td').eq(9);
        var LostRate = $(obj).parents('tr').find('td').eq(10);
        var WinRate = $(obj).parents('tr').find('td').eq(11);

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

        myRequest("/admin/group_control/sync_res/" + GameID, "post", {SortID}, function (res) {

            layer.msg(res.msg)
            if (res.code == 200) {

                LostRateText = WinRateText = ''

                if (res.data.LostRate != '') {
                    LostRateText = `{{ __('auto.系统') }} {{ __('auto.输') }} {{ __('auto.玩家') }}` + res.data.LostRate
                }

                if (res.data.WinRate != '') {
                    WinRateText = `{{ __('auto.系统') }} {{ __('auto.赢') }} {{ __('auto.玩家') }}` + res.data.WinRate
                }


                Revenue.text(res.data.Revenue);
                RevenueD.text(res.data.RevenueD);
                Stock.text(res.data.Stock);
                TurnOver.text(res.data.TurnOver);
                Winlost.text(res.data.Winlost);
                ShaLv.text(res.data.ShaLv + '%');
                LostRate.text(LostRateText);
                WinRate.text(WinRateText);

            }

        });

    }

    function gradeChange(value) {

        myRequest("/admin/group_control/roomList", "post", {'GameID': value}, function (res) {
            var data = res.data
            var html = ''
            for (var i of data) {
                html += '<option value=' + i['GameID'] + '-' + i['SortID'] + '>' + i['RoomName'] + '</option>'
            }
            console.log(html)
            $("#game_level").html(html)
        });
    }

</script>
@endsection
