@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.请输入咖啡金额') }}">
                                </div>
                                <div class="form-group">
                                    <label for="nickname">*咖啡档位（优惠价）</label>
                                    <input type="number" step="0.01" class="form-control required" name="favorable_price" placeholder="{{ __('auto.请输入咖啡档位') }}">
                                </div>
                                <div class="form-group">
                                    <label for="nickname">*咖啡档位（赠送彩金）</label>
                                    <input type="number" step="0.01" class="form-control required" name="give" placeholder="{{ __('auto.请输入咖啡档位') }}" value="0">
                                </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">
                                        <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">
                                        <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">
                                        <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">
                                        <label class="form-check-label" for="googlepay">GooglePay</label>
                                    </div>
                                    <br><br>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="usdt-trc20" value="64">
                                        <label class="form-check-label" for="usdt-trc20">USDT-TRC20</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="usdt-erc20" value="128">
                                        <label class="form-check-label" for="usdt-erc20">USDT-ERC20</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="usdc-trc20" value="256">
                                        <label class="form-check-label" for="usdc-trc20">USDC-TRC20</label>
                                    </div>
                                    <div class="form-check form-check-inline">
                                        <input class="form-check-input" type="checkbox" name="pay_methods[]" id="usdc-erc20" value="512">
                                        <label class="form-check-label" for="usdc-erc20">USDC-ERC20</label>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="in_shop">*是否在商城展示</label><br>
                                    显示 <input type="radio" name="in_shop" value="1" checked>&nbsp;&nbsp;
                                    隐藏 <input type="radio" name="in_shop" value="0">
                                </div>

                                <div class="form-group">
                                    <label for="account">*开关</label><br>
                                    {{ __('auto.开启') }} <input type="radio"   name="status" value="1" checked>&nbsp;&nbsp;
                                    {{ __('auto.关闭') }} <input type="radio"   name="status" value="-1">
                                </div>


                                <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>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>


        function commit(){
            if($("#password").val() != $("#password_verify").val()){
                layer.msg('{{ __('auto.两次密码输入不一致') }}', function(){});
            }
            if(!checkForm()){
                return false;
            }

            // var config_ids = []
            // $("input:checkbox:checked").each(function () {
            //     config_ids.push($(this).val())
            // })
            var data = $("#form").serializeObject();

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