@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-numeric"></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>游戏ID</th>
                                        <th>游戏名称 (brand-title)</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @if(count($mappings) > 0)
                                        @foreach($mappings as $mapping)
                                        <tr>
                                            <td>{{ $mapping->id }}</td>
                                            <td><strong>{{ $mapping->number }}</strong></td>
                                            <td>{{ $mapping->game_id }}</td>
                                            <td>
                                                @if($mapping->brand && $mapping->title)
                                                    {{ $mapping->brand }}-{{ $mapping->title }}
                                                @else
                                                    <span style="color: #999;">游戏不存在</span>
                                                @endif
                                            </td>
                                            <td>
                                                <button class="btn btn-sm btn-gradient-info" onclick="update({{ $mapping->id }})">修改</button>
                                                <button class="btn btn-sm btn-gradient-danger" onclick="del({{ $mapping->id }})">删除</button>
                                            </td>
                                        </tr>
                                        @endforeach
                                    @else
                                        <tr>
                                            <td colspan="5" style="text-align: center; color: #999;">暂无数据</td>
                                        </tr>
                                    @endif
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function add() {
        layer.open({
            type: 2,
            title: '添加数字游戏映射',
            shadeClose: true,
            shade: 0.8,
            area: ['60%', '70%'],
            content: '/admin/game-number-mapping/add'
        });
    }

    function update(id) {
        layer.open({
            type: 2,
            title: '修改数字游戏映射',
            shadeClose: true,
            shade: 0.8,
            area: ['60%', '70%'],
            content: '/admin/game-number-mapping/update/' + id
        });
    }

    function del(id) {
        myConfirm('确定要删除这条映射吗？', function() {
            myRequest('/admin/game-number-mapping/delete/' + id, 'post', {}, function(res) {
                layer.msg(res.msg);
                if (res.code == '200') {
                    setTimeout(function() {
                        window.location.reload();
                    }, 1500);
                }
            });
        });
    }
</script>
@endsection
