@extends('base.base')
@section('base')
<div class="main-panel">
    <div class="content-wrapper">
        <div class="page-header">
            <h3 class="page-title">
                <span class="page-title-icon bg-gradient-primary text-white mr-2">
                    <i class="mdi mdi-gift"></i>
                </span>
                充值礼包配置管理
            </h3>
            <nav aria-label="breadcrumb">
                <button class="btn btn-sm btn-gradient-primary" onclick="add()">
                    <i class="mdi mdi-plus"></i> 添加礼包
                </button>
            </nav>
        </div>
        <div class="row">
            <div class="col-lg-12 grid-margin stretch-card">
                <div class="card">
                    <div class="card-body">
                        <h4 class="card-title">礼包列表</h4>
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>礼包ID</th>
                                        <th>礼包名称</th>
                                        <th>总获得(%)</th>
                                        <th>立即获得(%)</th>
                                        <th>首充</th>
                                        <th>VIP</th>
                                        <th>推荐充值档位值</th>
                                        <th>配置倒计时(小时)</th>
                                        <th>到期后倒计时(小时)</th>
                                        <th>每日奖励</th>
                                        <th>下注奖励</th>
                                        <th>下注任务</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($list as $item)
                                    <tr>
                                        <td>{{ $item->id }}</td>
                                        <td>{{ $item->gift_id }}</td>
                                        <td>{{ $item->gift_name }}</td>
                                        <td>{{ $item->total_bonus }}%</td>
                                        <td>{{ $item->bonus_instantly }}%</td>
                                        <td>{{ $item->first_pay ? '是' : '否' }}</td>
                                        <td>{{ $item->is_vip ? '是' : '否' }}</td>
                                        <td>{{ number_format($item->recommend ?? 0, 2) }}</td>
                                        <td>{{ $item->valid_h }}</td>
                                        <td>{{ $item->valid_h_2 ?? 0 }}</td>
                                        <td>
                                            @if($item->day_rewards)
                                                <small>总: {{ $item->day_rewards['total_bonus'] }}% | 天数: {{ $item->day_rewards['bonus_day'] }}</small>
                                            @else
                                                -
                                            @endif
                                        </td>
                                        <td>
                                            @if($item->betting_bonus)
                                                <small>总: {{ $item->betting_bonus['total_bonus'] }}% | 每注: {{ $item->betting_bonus['per_bet'] }}</small>
                                            @else
                                                -
                                            @endif
                                        </td>
                                        <td>
                                            @if($item->betting_task)
                                                <small>总: {{ $item->betting_task['total_bonus'] }}% | 倍数: {{ $item->betting_task['bet_pay_times'] }}</small>
                                            @else
                                                -
                                            @endif
                                        </td>
                                        <td>
                                            <button class="btn btn-sm btn-gradient-info" onclick="update({{ $item->id }})">修改</button>
                                            <button class="btn btn-sm btn-gradient-danger" onclick="del({{ $item->id }})">删除</button>
                                        </td>
                                    </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                        <div class="box-footer clearfix">
                            {!! $list->links() !!}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function add() {
        layer.open({
            type: 2,
            title: '添加充值礼包',
            shadeClose: true,
            shade: 0.8,
            area: ['90%', '90%'],
            content: '/admin/recharge/gift_add'
        });
    }

    function update(id) {
        layer.open({
            type: 2,
            title: '修改充值礼包',
            shadeClose: true,
            shade: 0.8,
            area: ['90%', '90%'],
            content: '/admin/recharge/gift_update/' + id
        });
    }

    function del(id) {
        layer.confirm('确定删除该礼包吗？', function(index) {
            myRequest("/admin/recharge/gift_delete/" + id, "post", {}, function(res) {
                layer.msg(res.msg);
                if (res.code == '200') {
                    setTimeout(function() {
                        location.reload();
                    }, 1500);
                }
            });
            layer.close(index);
        });
    }
</script>
@endsection
