@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="quota_min" placeholder="{{ __('auto.下限值') }}">
                                    </div>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label>* 上限值</label>
                                        <input type="text" class="form-control" name="quota_max" placeholder="{{ __('auto.上限值') }}">

                                    </div>
                                </div>

                                <div>
                                    <label for=""><h4>{{ __('auto.下级每次生效增长额度') }}</h4></label> <br>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label>{{ __('auto.下限值') }}</label>
                                        <input type="text" class="form-control" name="level_quota_min" placeholder="{{ __('auto.下级每次生效增长额度') }}"
                                               id="quota">
                                    </div>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* 上限值</label>
                                        <input type="text" class="form-control" name="level_quota_max" placeholder="{{ __('auto.下级每次生效增长额度') }}"
                                               id="multiple">
                                    </div>
                                </div>

                                <div>
                                    <h4>{{ __('auto.下级每次生效人数要求') }}</h4>
                                    <input type="text" class="form-control required" name="level_quota_number" placeholder="{{ __('auto.下级每次生效人数要求') }}">
                                </div>

                                <br>
                                <div>
                                    <label for=""><h4>{{ __('auto.下下级每次生效增长额度') }}</h4></label> <br>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label>{{ __('auto.下限值') }}</label>
                                        <input type="text" class="form-control" name="two_level_quota_min" placeholder="{{ __('auto.下下级每次生效增长额度') }}"
                                               id="quota">
                                    </div>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* 上限值</label>
                                        <input type="text" class="form-control" name="two_level_quota_max" placeholder="{{ __('auto.下下级每次生效增长额度') }}"
                                               id="multiple">
                                    </div>
                                </div>

                                <div>
                                    <h4>{{ __('auto.下下级每次生效人数要求') }}</h4>
                                    <input type="text" class="form-control required" name="two_level_quota_number" placeholder="{{ __('auto.下下级每次生效人数要求') }}">
                                </div>

                                <br>
                                <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>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


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

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

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

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

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

            myRequest("/admin/extension/register_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
