@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>{{ __('auto.控制概率（0-100）') }}</label>
                                    <input type="number" class="form-control required"
                                           value="{{$Probability ?? '0'}}" name="Probability" min="0" max="100">
                                </div>

                                <div style="clear: both"></div>
                                <br>
                                <div class="form-group">
                                    <label>{{ __('auto.备注信息') }}</label>
                                    <textarea id="Remarks" name="Remarks" class="form-control"
                                              rows="3"></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 commit(id) {

            if (!checkForm()) {
                return false;
            }
            var data = $("#form").serializeObject();
            // 概率校验 0-100
            var prob = parseFloat(data.Probability || 0);
            if (isNaN(prob) || prob < 0 || prob > 100) {
                layer.msg('概率必须在0-100之间');
                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
