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

                                    <input type="text" class="form-control required" name="Name" placeholder="{{ __('auto.请输入模板名称') }}">
                                </div>

                                <div>
                                    <label for="">
                                        {{ __('auto.配置模板（所有模板百分比）') }}
                                    </label>
                                </div>
                                @foreach($GameDataText as $gamekey=>$gamename)
                                    <div style="width: 48%;float: left">
                                        <label for="">{{$gamename}}：</label>
                                        <input type="number" class="form-control" name="{{$gamekey}}"
                                               id="{{$gamekey}}" value="{{$UserControlKind[$gamekey] ?? ''}}">
                                    </div>
                                @endforeach
                                <div style="clear: both"></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(ID) {
            if (!checkForm()) {
                return false;
            }

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

            for (var i in data) {
                if (i === 'Name') {
                    continue
                }
                if (parseInt(data[i]) < 0 || parseInt(data[i]) > 100) {
                    layer.msg('{{ __('auto.控制等级区间') }}0-100');
                    return false;
                }
            }

            myRequest("/admin/Control/ControlConfig_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
