@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" style="width: 49%;float: left">
                                    <label>* 档位名称填写</label>
                                    <input type="text" class="form-control required" name="ConfigName"
                                           placeholder="{{ __('auto.档位名称') }}"
                                           value="">
                                </div>

                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 控制用户输/赢</label>

                                    <select class="form-control" name="ControlType">
                                        <option value="">{{ __('auto.选择类型') }}</option>

                                        <option value="1" selected>{{ __('auto.输') }}</option>
                                        <option value="2" disabled>{{ __('auto.赢') }}</option>
                                    </select> &nbsp;&nbsp;
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 条件1：累计咖啡额度下限</label>
                                    <input type="text" class="form-control required" name="RechargeMin" min="0"
                                           placeholder="{{ __('auto.累计咖啡额度下限') }}" value="">

                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 条件1：累计咖啡额度上限</label>
                                    <input type="text" class="form-control required" name="RechargeMax" min="0"
                                           placeholder="{{ __('auto.累计咖啡额度上限') }}" value="">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 条件2：累计输赢之和额度</label>
                                    <input type="text" class="form-control required" name="ScoreWin"
                                           placeholder="{{ __('auto.累计输赢之和额度') }}" min="0"
                                           value="">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 初始概率 （万分比）</label>
                                    <input type="text" class="form-control required" name="ProbBase" placeholder="{{ __('auto.初始概率') }}"
                                           min="0"
                                           value="">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 档位基准值</label>
                                    <input type="text" class="form-control required" name="ScoreBase"
                                           placeholder="{{ __('auto.档位基准值') }}" min="0"
                                           value="">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 每个档位增加概率 （万分比）</label>
                                    <input type="text" class="form-control required" name="ProbAdd"
                                           placeholder="{{ __('auto.每个档位增加概率') }}" min="0"
                                           value="">
                                </div>
                                <div class="form-group" style="width: 60%;float: left">
                                    <label>* 增加概率上限（万分比）</label>
                                    <input type="text" class="form-control required" name="ProbMax" placeholder="{{ __('auto.增加概率上限') }}"
                                           min="0"
                                           value="">
                                </div>


                                <div class="form-group btn-move" style="width: 50%;float: left">
                                    <button type="button" onclick="commit()"
                                            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>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        function commit() {

            if (!checkForm()) {
                return false;
            }


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

            // var RechargeMin = data.RechargeMin
            // var RechargeMax = data.RechargeMax
            // var ScoreWin = data.ScoreWin
            var ProbBase = data.ProbBase
            var ProbAdd = data.ProbAdd
            var ProbMax = data.ProbMax

            if (ProbBase > 10000 || ProbAdd  > 10000 || ProbMax > 10000){
                layer.msg('{{ __('auto.百分比最大值') }}10000');
                return false;
            }

            // var ScoreBase = data.ScoreBase
            //
            // if (RechargeMin < 0){
            //     layer.msg('咖啡下限不能小于0');
            //     return false;
            // }
            //
            // if (RechargeMax < 0){
            //     layer.msg('咖啡上限不能小于0');
            //     return false;
            // }

            myRequest("/admin/recharge_control_config/add", "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
