@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">
                                    <label for="nickname">*充值金额</label>
                                    <input type="number" step="0.01" class="form-control required" name="money" placeholder="{{ __('auto.请输入充值金额') }}" value="{{$info->money}}">
                                </div>
                                <div class="form-group">
                                    <label for="nickname">*充值档位（优惠价）</label>
                                    <input type="number" step="0.01" class="form-control required" name="favorable_price" placeholder="{{ __('auto.请输入充值档位') }}" value="{{$info->favorable_price}}">
                                </div>
                                <div class="form-group">
                                    <label for="nickname">*充值档位（赠送彩金）</label>
                                    <input type="number" step="0.01" class="form-control required" name="give" placeholder="{{ __('auto.请输入充值档位') }}" value="{{$info->give}}">
                                </div>

                                <div class="form-group">
                                    <label for="nickname">*充值档位（次日赠送）</label>
                                    <input type="text"  class="form-control required" name="second_give" placeholder="{{ __('auto.请输入充值档位') }}" value="{{$info->second_give}}">
                                </div>

                                <div class="form-group">
                                    <label for="pay_methods">*支持的支付方式</label><br>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="cashapp" value="1" {{ (($info->pay_methods ?? 0) & 1) ? 'checked' : '' }}>
                                        <label class="form-check-label" for="cashapp">CashApp</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="paypal" value="2" {{ (($info->pay_methods ?? 0) & 2) ? 'checked' : '' }}>
                                        <label class="form-check-label" for="paypal">PayPal</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="applepay" value="4" {{ (($info->pay_methods ?? 0) & 4) ? 'checked' : '' }}>
                                        <label class="form-check-label" for="applepay">ApplePay</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="googlepay" value="8" {{ (($info->pay_methods ?? 0) & 8) ? 'checked' : '' }}>
                                        <label class="form-check-label" for="googlepay">GooglePay</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>
                                    {{ __('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();

            var money = data.money
            var favorable_price = data.favorable_price
            var give = data.give
            var second_give = data.second_give
            
            // 计算支付方式位掩码
            var pay_methods = 0;
            $("input[name='pay_methods[]']:checked").each(function() {
                pay_methods += parseInt($(this).val());
            });
            
            myRequest("/admin/recharge/update_config/"+id,"post", {money,favorable_price,give,second_give,pay_methods},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
