@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">
                                    <label for=""><h4>{{ __('auto.开关设置') }}</h4></label> <br>
                                    <label> <input type="radio" name="status" id="optionsRadios2" value="1" @if ($config->status == 1)
                                        checked
                                            @endif> {{ __('auto.开启') }}</label>
                                    <label> <input type="radio" name="status" id="optionsRadios2" value="2" @if ($config->status == 2)
                                        checked
                                            @endif> {{ __('auto.关闭') }}</label>
                                </div>
                                <div class="form-group">
                                    <label for=""><h4>{{ __('auto.人工审核是否启用默认代付方') }}</h4></label>
                                    <input type="radio" value="1" name="limit_manual_review_show"
                                           @if ($config->limit_manual_review_show == 1)
                                           checked
                                        @endif> {{ __('auto.开启') }}
                                    <input type="radio" value="0" name="limit_manual_review_show"
                                           @if ($config->limit_manual_review_show == 0)
                                           checked
                                        @endif> {{ __('auto.关闭') }}
                                </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 ($config->agent == $val->config_value)
                                                checked
                                                    @endif>

                                                {{$val->name}}
                                            </label>
                                        </div>
                                    @endforeach
                                </div>
                                <button type="button" onclick="commit({{ $config->channel }})"
                                        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(id) {
            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/channel/withdrawal_config/"+id, "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
