@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>

                            <form class="forms-sample" id="form">
                                <div class="form-group">
                                    <h4>{{ __('auto.档位名称填写') }}</h4>
                                    <input type="text" class="form-control required" name="name" placeholder="{{ __('auto.请输入档位名称') }}">
                                </div>

                                <div>
                                    <h4>{{ __('auto.配置杀率（万分比）') }}</h4>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* 配置杀率下限（万分比）</label>
                                        <input type="text" class="form-control" name="KillRateMin" placeholder="{{ __('auto.配置杀率下限') }}">

                                    </div>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label>* 配置杀率上限（万分比）</label>
                                        <input type="text" class="form-control" name="KillRateMax" placeholder="{{ __('auto.配置杀率上限') }}">
                                    </div>

                                </div>

                                <div>
                                    <h4>{{ __('auto.平台输概率（万分比）') }}</h4>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label for="">*平台输概率（万分比）</label>
                                        <input type="text" class="form-control" name="LostRate" placeholder="{{ __('auto.平台输概率') }}"
                                               onblur="LostRateFunc()" min="0" max="10000">
                                    </div>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">

                                        {{ __('auto.换算：') }}<input type="text" class="form-control" id="LostRate_conversion"
                                                  placeholder="{{ __('auto.换算') }}"
                                                  readonly>

                                    </div>
                                </div>
                                <div>
                                    <h4>{{ __('auto.平台赢概率（万分比）') }}</h4>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* 平台赢概率（万分比）</label>
                                        <input type="text" class="form-control" name="WinRate" placeholder="{{ __('auto.平台赢概率') }}"
                                               min="0" max="10000" onblur="WinRateFunc()">
                                    </div>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 5px">

                                        {{ __('auto.换算：') }}<input type="text" class="form-control" id="WinRate_conversion"
                                                  placeholder="{{ __('auto.换算') }}"
                                                  readonly>

                                    </div>
                                </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 LostRateFunc() {
            val = $("input[name='LostRate']").val();
            $("#LostRate_conversion").val((val / 100) + '%')
        }

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

        function commit(GameID, SortID) {
            if (!checkForm()) {
                return false;
            }
            console.log(GameID)
            var data = $("#form").serializeObject();
            data.SortID = SortID

            if (parseInt(data.KillRateMin) > parseInt(data.KillRateMax)) {
                layer.msg('{{ __('auto.下限值不能大于上限') }}');
                return false;
            }

            myRequest("/admin/group_control/control_add/"+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
