@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: 48%;float: left">
                                    <label>{{ __('auto.控制金额') }}</label>
                                    <input type="number" class="form-control required"
                                           value="{{$ControlScore ?? '0'}}" name="ControlScore">

                                </div>

                                <div class="form-group" style="width: 48%;float: right">
                                    <label for="">{{ __('auto.控制概率请选择使用模板：') }}</label>
                                    <select name="Template" id="Template" class="form-control"
                                            onchange="gradeChange(this.options[this.options.selectedIndex].value)">
                                        <option value="">{{ __('auto.请选择模板') }}</option>
                                        @foreach($list as $val)
                                            <option value="{{$val->ID}}"
                                                    @if($TempID==$val->ID) selected @endif>{{$val->Name}}</option>
                                        @endforeach
                                    </select>
                                    <button class="btn-sm btn btn-gradient-dark"
                                            onclick="ControlConfigFunc();return false;">{{ __('auto.配置模板') }}
                                    </button>
                                </div>

                                <div >
                                    <label for="">{{ __('auto.当前生效概率：') }}</label> <br>
                                @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>

                                <div style="clear: both"></div>
                                <br>
                                <div class="form-group" style="">
                                    <label>{{ __('auto.备注信息') }}</label>
                                    <textarea id="Remarks" name="Remarks" class="form-control"
                                              rows="3">{{$info->Remarks ?? ''}}</textarea>

                                </div>

                                <input type="hidden" name="UserID" value="{{$UserID ?? ''}}">

                                <br><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>
                                <button type="button" onclick="cancel_dk({{$UserID}})"
                                        class="btn btn-sm btn-google btn-icon-text">
                                    {{ __('auto.取消单控') }}
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        function add(KindID, TpBaiGear) {
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.修改配置') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '60%'],
                content: '/admin/Control/ControlConfigGear?KindID=' + KindID,
                btn: '{{ __('auto.确定') }}',
                yes: function (index, layero) {
                    var obj = $(layero).find("iframe")[0].contentWindow; //obj可以调用子页面的任何方法
                    Value = obj.gearVal()
                    layer.close(index);
                    $('#' + TpBaiGear).html('')
                    html = ''
                    var arr = Value.split(',');
                    for (var i in arr) {
                        val = parseInt(arr[i])

                        if (val > 0) {
                            html += '<input type="radio" name=' + TpBaiGear + ' value="' + val + '">' + val + '&nbsp;&nbsp;';
                        }
                    }

                    $('#' + TpBaiGear).append(html)

                    myRequest("/admin/Control/ControlConfigGearAdd", "post", {Value, KindID}, function (res) {

                    });
                }
            });

        }

        function gradeChange(ID) {
            myRequest('/admin/Control/gradeChange/' + ID, 'post', {}, function (response) {
                data = response.data
                @foreach($GameDataText as $gamekey=>$gamename)
                $('#{{$gamekey}}').val(data.{{$gamekey}})
                @endforeach

            })
        }

        function ControlConfigFunc() {

            var page = layer.open({
                type: 2,
                title: '{{ __('auto.修改配置') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/Control/ControlConfig',
                end: function () {
                    myRequest("/admin/Control/getConfig", "post", {}, function (res) {
                        var data = res.data
                        var html = ''
                        for (var i of data) {
                            html += '<option value=' + i['ID'] + '>' + i['Name'] + '</option>'
                        }

                        $("#Template").html(html)
                    });
                }
            });

        }

        function commit(id) {

            if (!checkForm()) {
                return false;
            }
            var data = $("#form").serializeObject();
            var verifyData = $("#form").serializeArray();
            for (let val of verifyData) {
                var name = val.name;
                if (name != 'ControlScore' && name != 'Template' && name != 'UserID' && name != 'Remarks' && name != 'ABBaiGear' && name != 'TpBaiGear') {
                    if (val.value == '' || parseInt(val.value) < 0 || parseInt(val.value) > 100) {
                        layer.msg('{{ __('auto.控制等级区间') }}0-100');
                        return false;
                    }
                }
            }

            if (data.Template == '' && (data.TP || data.TPAK47 || data.TPJOKER || data.Rummy5 || data.Rummy2) == '') {
                layer.msg('{{ __('auto.概率没有配置,无法提交') }}');
                return false;
            }

            myConfirm("{{ __('auto.操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/global/dk_userlist_edit", "post", data, function (res) {
                    layer.msg(res.msg)
                    if (res.code == 200) {
                        setTimeout(function () {
                            // parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1500)
                    }
                });
            })
        }

        function cancel_dk(id) {
            console.log(id)
            myConfirm("{{ __('auto.取消单控操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/global/cancel_dk", "post", {id}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        // parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }, 1500)
                });
            });
        }


        function cancel() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }


    </script>
@endsection
