@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: 49%;float: left">
                                    <label>* 档位名称填写</label>
                                    <input type="text" class="form-control required" name="ConfigName"
                                           placeholder="{{ __('auto.档位名称') }}"
                                           value="{{$info->ConfigName}}">
                                </div>

                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 控制用户输/赢</label>

                                    <select class="form-control" name="ControlType">
                                        <option value="">{{ __('auto.选择类型') }}</option>

                                        <option value="1" @if ($info->ControlType == 1)
                                        selected
                                            @endif>{{ __('auto.输') }}
                                        </option>
                                        <option value="2" @if ($info->ControlType == 2)
                                        selected
                                            @endif>{{ __('auto.赢') }}
                                        </option>
                                    </select> &nbsp;&nbsp;
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 条件1：累计咖啡额度下限</label>
                                    <input type="text" class="form-control required" name="RechargeMin" min="0"
                                           placeholder="{{ __('auto.累计咖啡额度下限') }}" value="{{$info->RechargeMin}}">

                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 条件1：累计咖啡额度上限</label>
                                    <input type="text" class="form-control required" name="RechargeMax" min="0"
                                           placeholder="{{ __('auto.累计咖啡额度上限') }}" value="{{$info->RechargeMax}}">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 条件2：累计输赢之和额度</label>
                                    <input type="text" class="form-control required" name="ScoreWin"
                                           placeholder="{{ __('auto.累计输赢之和额度') }}" min="0"
                                           value="{{$info->ScoreWin}}">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 初始概率（万分比）</label>
                                    <input type="text" class="form-control required" name="ProbBase" placeholder="{{ __('auto.初始概率') }}"
                                           min="0"
                                           value="{{$info->ProbBase}}">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 档位基准值</label>
                                    <input type="text" class="form-control required" name="ScoreBase"
                                           placeholder="{{ __('auto.档位基准值') }}" min="0"
                                           value="{{$info->ScoreBase}}">
                                </div>
                                <div class="form-group" style="width: 50%;float: left">
                                    <label>* 每个档位增加概率（万分比）</label>
                                    <input type="text" class="form-control required" name="ProbAdd"
                                           placeholder="{{ __('auto.每个档位增加概率') }}" min="0"
                                           value="{{$info->ProbAdd}}">
                                </div>
                                <div class="form-group" style="width: 60%;float: left">
                                    <label>* 增加概率上限（万分比）</label>
                                    <input type="text" class="form-control required" name="ProbMax" placeholder="{{ __('auto.增加概率上限') }}"
                                           min="0"
                                           value="{{$info->ProbMax}}">
                                </div>


                                <div class="form-group btn-move" style="width: 50%;float: left">
                                    <button type="button" onclick="commit({{$info->ID}})"
                                            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="del({{$info->ID}})"
                                            class="btn btn-sm btn-gradient-info btn-icon-text">
                                        <i class="mdi mdi-reload btn-icon-prepend"></i>
                                        {{ __('auto.删除档位') }}
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        function commit(id) {

            if (!checkForm()) {
                return false;
            }


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

            var ProbBase = data.ProbBase
            var ProbAdd = data.ProbAdd
            var ProbMax = data.ProbMax

            if (ProbBase > 10000 || ProbAdd  > 10000 || ProbMax > 10000){
                layer.msg('{{ __('auto.百分比最大值') }}10000');
                return false;
            }

            myRequest("/admin/recharge_control_config/update/" + 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 del(id) {
            myConfirm("{{ __('auto.操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/recharge_control_config/del/" + id, "post", {id}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1500)
                });
            });
        }
        function cancel() {
            parent.location.reload();
        }
    </script>
@endsection
