@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-wrench"></i>
              </span>
                    {{ __('auto.兑换码列表') }}
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">{{ __('auto.兑换管理') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('auto.兑换码列表') }}</li>
                    </ol>
                </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">{{ __('auto.兑换码列表') }}</h4>
                            <form class="well form-inline margin-top-20" method="get" action='/admin/exchange/code_list'>
                                <spen style="padding-left: 10px" >{{ __('auto.选择状态：') }}</spen>
                                <select class="form-control" name="status" value="{{$status}}" style="color: black">
                                    <option value="">{{ __('auto.选择状态') }}</option>
                                    @foreach($status_type as $k=>$v)
                                        <option value="{{$k}}" @if($k===$status) selected @endif>{{$v}}</option>
                                    @endforeach
                                </select>
                                <spen style="padding-left: 10px" >{{ __('auto.礼包名称：') }}</spen>
                                <input class="form-control" type="text" name="name" style="width: 8%; " value="{{ $name }}" placeholder="{{ __('auto.请输入礼包名称') }}">
                                </select>
                                <spen style="padding-left: 10px" >{{ __('auto.选择时间：') }}</spen>
                                <input type="date"  step="01" name="start_time" class="form-control" value="{{$start_time}}" />&nbsp;&nbsp;
                                <input type="date"  step="01" name="end_time" class="form-control" value="{{$end_time}}" />&nbsp;&nbsp;
                                <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="{{ __('auto.搜索') }}" />&nbsp;&nbsp;
                                <a href="/admin/exchange/code_list" class="btn btn-sm btn-gradient-warning btn-icon-text">{{ __('auto.清空') }}</a>&nbsp;&nbsp;
                                <a href="/admin/exchange/code_list?excel=1&start_time={{$start_time}}&end_time={{$end_time}}&status={{$status}}&name={{$name}}" class="btn btn-sm btn-gradient-light btn-icon-text">{{ __('auto.导出') }}</a>&nbsp;&nbsp;
                                <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="gift()">{{ __('auto.新增礼包') }}</button>&nbsp;&nbsp;
                                <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="code()">{{ __('auto.新增兑换码') }}</button>
                            </form>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>{{ __('auto.批次') }}</th>
                                    <th>{{ __('auto.兑换码') }}</th>
                                    <th>{{ __('auto.奖品名称') }}</th>
                                    <th>{{ __('auto.奖品明细') }}</th>
                                    <th>{{ __('auto.生成时间') }}</th>
                                    <th>{{ __('auto.过期时间') }}</th>
                                    <th>{{ __('auto.兑换限制') }}</th>
                                    <th>{{ __('auto.状态') }}</th>
                                    <th>{{ __('auto.兑换人') }}</th>
                                    <th>{{ __('auto.兑换时间') }}</th>
                                    <!-- <th>操作</th> -->
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $k=>$v)
                                    <tr>
                                        <td style="width: 6%">{{ $v->id }}</td>
                                        <td style="width: 10%">{{ $v->code}}</td>
                                        <td style="width: 10%">{{ $v->desc}}</td>
                                        <td style="width: 10%">{{ $v->name}}</td>
                                        <td style="width: 10%">{{ date('Y-m-d H:i:s',strtotime($v->created_at)) }}</td>
                                        <td style="width: 10%">{{ date('Y-m-d H:i:s',strtotime($v->expired_at)) }}</td>
                                        <td style="width: 8%">{{ $v->limit }}</td>
                                        <td style="width: 8%">{{ $v->status }}</td>
                                        <td style="width: 10%">{{ $v->GameID }}</td>
                                        <td style="width: 10%">{{ $v->updated_at}}</td>
                                        <!-- <td style="width: 5%">
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="publish({{ $v->id }})">
                                                删除
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                        </td> -->
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                {{ __('auto.总共') }} <b>{{ $list->appends(["status"=>$status,"name"=>$name,"start_time"=>$start_time,"end_time"=>$end_time])->total() }}</b> {{ __('auto.条,分为') }}<b>{{ $list->lastPage() }}</b>{{ __('auto.页') }}
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        function gift(id){
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.新增礼包') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/gift/add'
            });
        }
        function code(id){
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.新增礼包') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/code/add'
            });
        }
        function publish(id){
            myConfirm("{{ __('auto.是否继续') }}?",function(){
                var myselect=document.getElementById("state"+id);
                var index=myselect.selectedIndex;
                var data = {state:myselect.options[index].value}
                myRequest("/admin/treasure/update/"+id,"post",data,function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

        $('.menu-switch').click(function(){
            id = $(this).attr('id');
            state = $(this).attr('state');
            if(state == "on"){
                $('.pid-'+id).hide();
                $(this).attr("state","off")
                $(this).removeClass('mdi-menu-down').addClass('mdi-menu-right');
            }else{
                $('.pid-'+id).show();
                $(this).attr("state","on")
                $(this).removeClass('mdi-menu-right').addClass('mdi-menu-down');
            }
        })
    </script>
@endsection
