@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="row">
                <div class="col-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">{{ __('auto.档位配置界面') }}</h4>

                            {{ __('auto.请编辑游戏配置：') }}{{$name??''}}
                            <br>
                            <br>
                            <form class="forms-sample" id="form">


                                <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                    <label>* 反水额度（万分比）</label>
                                    <input type="text" class="form-control" name="Rate" placeholder="{{ __('auto.反水额度') }}" value="{{$Rate}}"
                                           onblur="RateFunc()">

                                </div>
                                <div class="form-group" style="width: 50%;float: left;margin-left: 5px">

                                    {{ __('auto.换算：') }}<input type="text" class="form-control" id="Rate"
                                              placeholder="{{ __('auto.换算') }}" value="{{$Rate / 100}} %"
                                              readonly>

                                </div>

                                <button type="button" onclick="commit('{{$GameID}}','{{$SortID}}')"
                                        class="btn btn-sm btn-gradient-primary btn-icon-text">
                                    <i class="mdi mdi-file-check btn-icon-prepend"></i>
                                    {{ __('auto.提交') }}
                                </button>
                                <button type="button" onclick="cancel()"
                                        class="btn btn-sm btn-gradient-warning btn-icon-text">
                                    <i class="mdi mdi-reload btn-icon-prepend"></i>
                                    {{ __('auto.取消') }}
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        // 换算
        function RateFunc() {
            val = $("input[name='Rate']").val();
            $("#Rate").val((val / 100) + '%')
        }

        function commit(GameID, SortID) {
            if (!checkForm()) {
                return false;
            }

            var data = $("#form").serializeObject();

            if (data.Rate < 0) {
                layer.msg('{{ __('auto.最小值') }}0');
                return false;
            }

            data.SortID = SortID

            myRequest("/admin/return_water/update/" + GameID, "post", data, function (res) {
                if (res.code == '200') {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1500)
                } else {
                    layer.msg(res.msg)
                }
            });
        }

        function cancel() {
            parent.location.reload();
        }
    </script>
@endsection
