@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">修改保护配置</h4>

                            <form class="forms-sample" id="form">

                                <div class="form-group">
                                    <h4>提充比小于（%）</h4>
                                    <input type="number" class="form-control required" name="TradeRateMax"
                                           placeholder="提充比小于（%）" value="{{ $info->TradeRateMax }}">
                                </div>
                                <div class="form-group">
                                    <h4>流水/充值比例上限值参数</h4>
                                    <input type="number" class="form-control required" name="TurnoverRechargeRatio"
                                           placeholder="流水/充值比例上限值参数" value="{{ $info->TurnoverRechargeRatio }}">
                                </div>
                                <div class="form-group">
                                    <h4>单笔充值金额/持有下限参数</h4>
                                    <input type="number" class="form-control required" name="RechargeGoldRatio"
                                           placeholder="单笔充值金额/持有下限参数" value="{{ $info->RechargeGoldRatio }}">
                                </div>
                                <div class="form-group">
                                    <h4>大奖上限百分比</h4>
                                    <input type="number" class="form-control required" name="RewardMaxPercent"
                                           placeholder="大奖上限百分比" value="{{ $info->RewardMaxPercent }}">
                                </div>
                                <div class="form-group">
                                    <h4>大奖下限百分比</h4>
                                    <input type="number" class="form-control required" name="RewardMinPercent"
                                           placeholder="大奖下限百分比" value="{{ $info->RewardMinPercent }}">
                                </div>

                                <div class="form-group">
                                    <h4>最小充值</h4>
                                    <input type="number" class="form-control required" name="RechargeMin"
                                           placeholder="最小充值" value="{{ $info->RechargeMin }}">
                                </div>
                                <div class="form-group">
                                    <h4>最大充值</h4>
                                    <input type="number" class="form-control required" name="RechargeMax"
                                           placeholder="最大充值" value="{{ $info->RechargeMax }}">
                                </div>
                                <div class="form-group">
                                    <h4>充值金额计算方式</h4>
                                    <select class="form-control" name="RechargeCalModel">
                                        <option value="0" @if($info->RechargeCalModel == 0) selected @endif>单笔</option>
                                        <option value="1" @if($info->RechargeCalModel == 1) selected @endif>平均值</option>
                                    </select>
                                </div>

                                <div class="form-group">
                                    <label>是否生效</label>
                                    <div class="form-check">
                                        <input type="radio" class="form-check-input" name="Status" value="1" 
                                               @if ($info->Status == 1) checked @endif>
                                        <label class="form-check-label">生效</label>
                                    </div>
                                    <div class="form-check">
                                        <input type="radio" class="form-check-input" name="Status" value="0" 
                                               @if ($info->Status == 0) checked @endif>
                                        <label class="form-check-label">无效</label>
                                    </div>
                                </div>

                                <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>
                                    提交
                                </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>
                                    取消
                                </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 (data[i] !== '' && parseInt(data[i]) < 0) {
                    layer.msg('配置不能小于0');
                    return false;
                }
            }
            
            myRequest("/admin/Protect/protect_config_info_update/"+ID, "post", data, function (res) {
                layer.msg(res.msg);
                if (res.code == '200') {
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1500);
                }
            });
        }

        function cancel() {
            parent.layer.closeAll();
        }
    </script>
@endsection
