@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.请输入菜单名称') }}" value="3">
                                </div>

                                <div>
                                    <label for="recharge">
                                        <input type="checkbox" name="recharge_checkbox" id="recharge" checked>
                                        {{ __('auto.累计咖啡额度范围设置') }}
                                    </label>
                                    <br>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* 下限值</label>
                                        <input type="text" class="form-control" name="recharge_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="recharge_max" placeholder="{{ __('auto.上限值') }}">

                                    </div>
                                </div>

                                <div>
                                    <label for="draw">
                                        <input type="checkbox" name="draw_checkbox" id="draw" checked>
                                        {{ __('auto.单个玩家可免审核茶叶额度') }}
                                    </label> <br>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label> <input type="radio" name="type" id="optionsRadios2" value="1" checked>
                                            {{ __('auto.固定额度') }}</label>
                                        <input type="text" class="form-control" name="quota" placeholder="{{ __('auto.固定额度') }}" value="0"
                                               id="quota">
                                    </div>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* <input type="radio" name="type" id="optionsRadios2" value="2" >
                                            {{ __('auto.固定倍数') }}</label>
                                        <input type="text" class="form-control" name="multiple" placeholder="{{ __('auto.固定倍数') }}"
                                               id="multiple">
                                    </div>
                                </div>

                                <div>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label> <input type="checkbox" name="draw_gt_recharge_checkbox"  checked>
                                            {{ __('auto.茶叶大于咖啡，设置超过值：') }}</label>
                                        <input type="text" class="form-control" name="draw_gt_recharge" placeholder="{{ __('auto.茶叶大于咖啡') }}"
                                               id="quota" value="0">
                                    </div>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* <input type="checkbox" name="draw_total_checkbox"  checked>
                                            {{ __('auto.茶叶总额超过，设置超过值：') }}</label>
                                        <input type="text" class="form-control" name="draw_total" placeholder="{{ __('auto.茶叶总额超过') }}"
                                               id="multiple" value="0">
                                    </div>
                                </div>

                                <div>
                                    <div class="form-group" style="width: 50%;float: left;margin-left: 5px">
                                        <label> <input type="checkbox" name="draw_bi_checkbox"   checked>
                                            {{ __('auto.单日茶叶笔数超过，设置超过值：') }}</label>
                                        <input type="text" class="form-control" name="draw_bi" placeholder="{{ __('auto.单日茶叶笔数超过') }}"
                                               id="quota" value="0">
                                    </div>
                                    <div class="form-group" style="width: 48%;float: left;margin-left: 3px">
                                        <label>* <input type="checkbox" name="game_time_checkbox"  checked>
                                            {{ __('auto.总游戏时长低于，设置值（小时）：') }}</label>
                                        <input type="text" class="form-control" name="game_time" placeholder="{{ __('auto.总游戏时长低于') }}"
                                               id="multiple" value="0">
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label for=""><h4>{{ __('auto.每日申请总额度设置') }}</h4></label> <br>
                                    <label for="nickname">
                                        {{ __('auto.当前每日累计消耗额度/每日总额度：') }}
                                    </label>
                                    {{ __('auto.添加') }} / {{ __('auto.减少额度') }}<input type="text" class="form-control required" name="total_quota"
                                                    placeholder="{{ __('auto.每日总额度设置') }}" value="1">
                                </div>
                                <div class="form-group">
                                    <label for=""><h4>{{ __('auto.开关设置') }}</h4></label> <br>
                                    <label> <input type="radio" name="status" id="optionsRadios2" value="1" checked> {{ __('auto.开启') }}</label>
                                    <label> <input type="radio" name="status" id="optionsRadios2" value="2"> {{ __('auto.关闭') }}</label>
                                </div>
                                <div style="margin-top: 10px">
                                    <span>{{ __('auto.请选择一个代付方') }}</span>
                                    @foreach($agent as $val)
                                        <div class="radio">
                                            <label>
                                                <input type="radio" value="{{$val->config_value}}" name="agent" @if ($loop->first)
                                                    checked
                                                @endif>
                                                {{$val->name}}
                                            </label>
                                        </div>
                                    @endforeach
                                </div>
                                <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 (! data.draw_bi_checkbox){
                data.draw_bi = 0
            }

            if (! data.draw_gt_recharge_checkbox){
                data.draw_gt_recharge = 0
            }
            if (! data.draw_total_checkbox){
                data.draw_total = 0
            }
            if (! data.game_time_checkbox){
                data.game_time = 0
            }
            if (! data.recharge_checkbox){
                data.recharge_max = 0
                data.recharge_min = 0
            }
            if (! data.draw_checkbox){
                data.type = 0
            }

            let type = data.type

            if (type == 1 && data.quota == '') {
                layer.msg('{{ __('auto.固定额度不能为空') }}');
                return false;
            }
            if (type == 2 && data.multiple == '') {
                layer.msg('{{ __('auto.固定倍数不能为空') }}');
                return false;
            }

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

            if (data.quota != '' && (data.quota < 0 || data.quota > 1000000)) {
                layer.msg('{{ __('auto.固定额度区间为') }}0-1000000');
                return false;
            }

            if (data.multiple != '' && (data.multiple < 1 || data.multiple > 100)) {
                layer.msg('{{ __('auto.固定倍数区间为') }}1-100');
                return false;
            }

            if (data.multiple != '' && type == 2) {
                data.quota = data.multiple
            }

            myRequest("/admin/withdrawal/exempt_review_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
