@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">
                                    <h4>{{ __('auto.档位名称填写') }}</h4>
                                    <input type="text" class="form-control required" name="Name" value="{{$info->Name}}"  >
                                </div>


                                <div style="width: 48%;float: left">
                                    <label for="">*咖啡额度最小值：</label>
                                    <input type="number" class="form-control" name="ChargeMin" min="0" value="{{$info->ChargeMin}}">
                                </div>

                                <div style="width: 48%;float: right">
                                    <label for="">*咖啡额度最大值：</label>
                                    <input type="number" class="form-control" name="ChargeMax" min="0" value="{{$info->ChargeMax}}">

                                </div>

                                <div style="width: 48%;float: left">
                                    <label for="">*每日最大累计返利上限：</label>
                                    <input type="number" class="form-control" name="BetMax" min="0"  value="{{$info->BetMax}}">

                                </div>
                                <div style="clear: both"></div>
                                <br>
                                <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>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        function commit(ID) {
            if (!checkForm()) {
                return false;
            }

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


            if (parseInt(data.ChargeMax)  < parseInt(data.ChargeMin)){
                layer.msg('{{ __('auto.咖啡最大值不能小于最小值') }}');
                return false;
            }


            if (parseInt(data.ChargeMax) < 0 || parseInt(data.ChargeMin < 0)){
                layer.msg('{{ __('auto.咖啡金额不能小于') }}0');
                return false;
            }

            if (parseInt(data.BetMax < 0 )){
                layer.msg('{{ __('auto.每日最大累计返利上限不能小于') }}0');
                return false;
            }

            myRequest("/admin/return_water/gear_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 cancel() {
            parent.location.reload();
        }
    </script>
@endsection
