@extends('base.base')
@section('base')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">代理级别配置</h3>
                    <div class="card-tools">
{{--                        <a href="{{ route('admin.extension_new.register_config_add') }}" class="btn btn-primary btn-sm">添加级别</a>--}}
                    </div>
                </div>
                <div class="card-body table-responsive p-0">
                    <table class="table table-hover text-nowrap">
                        <thead>
                            <tr>
                                <th>ID</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->level_name }}</td>
                                <td>{{ $item->level }}</td>
                                <td>{{ $item->required_referrals }}</td>
                                <td>{{ $item->commission_rate }}</td>
                                <td>{{ $item->created_at }}</td>
                                <td>{{ $item->updated_at }}</td>
                                <td>
{{--                                    <a href="{{ route('admin.extension_new.register_config_update', ['id' => $item->id]) }}" class="btn btn-sm btn-info">编辑</a>--}}
{{--                                    <button type="button" class="btn btn-sm btn-danger" onclick="deleteConfig({{ $item->id }})">删除</button>--}}
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="card-footer clearfix">
                    {{ $list->links() }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script>
    function deleteConfig(id) {
        if (!confirm('确定要删除该级别吗？')) {
            return;
        }

        $.post('/admin/extension_new/register_config_delete/' + id, {
            _token: '{{ csrf_token() }}'
        }, function(res) {
            if (res.code === 0) {
                alert('删除成功');
                location.reload();
            } else {
                alert(res.msg || '删除失败');
            }
        });
    }
</script>
@endsection
