@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>
                            <p class="card-description">
                                <button type="button" class="btn btn-sm btn-gradient-success btn-icon-text" onclick="add()">
                                    <i class="mdi mdi-plus btn-icon-prepend"></i>
                                    {{ __('auto.新增公告') }}
                                </button>
                            </p>
                            <form class="forms-sample" method="post" action="/admin/punish/test" enctype="multipart/form-data">
                                @csrf
                                        <div class="form-group">
                                    <label class="col-sm-2 control-label">{{ __('auto.文件') }}</label>
                     
                                    <div class="col-sm-5">
                                        <input type="file" name="file" />
                                    </div>
                                    <div class="col-sm-5">
                                        <p class="form-control-static text-danger"></p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <button type="submit" class="btn btn-primary">{{ __('auto.提交') }}</button>
                                    </div>
                                </div>
                            </form>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <th>{{ __('auto.期数') }}</th>
                                    <th>{{ __('auto.发布时间') }}</th>
                                    <th>{{ __('auto.处罚明细') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $k=>$v)
                                    <tr>
                                        <td style="width: 5%">{{ $v->id }}</td>
                                        <td style="width: 5%">{{ $v->add_time }}</td>
                                        <td style="width: 15%"><textarea class="form-control" name="message" rows="4" disabled="disabled">{{ $v->content }}</textarea></td>
                                        <td style="width: 5%">
                                            <button type="button" class="btn btn-sm btn-gradient-dark btn-icon-text" onclick="update({{ $v->id }})">
                                                {{ __('auto.修改') }}
                                                <i class="mdi mdi-file-check btn-icon-append"></i>
                                            </button>
                                            @if($v->publish)
                                            <button type="button" class="btn btn-sm btn-gradient-info btn-icon-text">
                                                &nbsp;{{ __('auto.已') }}&nbsp;{{ __('auto.发') }}&nbsp;{{ __('auto.布') }}&nbsp;
                                            </button>
                                            @else
                                            <button type="button" class="btn btn-sm btn-gradient-danger btn-icon-text" onclick="publish({{ $v->id }})">
                                                {{ __('auto.确认发布') }}
                                            </button>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                {{ __('auto.总共') }} <b>{{ $list->total() }}</b> {{ __('auto.条,分为') }}<b>{{ $list->lastPage() }}</b>{{ __('auto.页') }}
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        function add(){
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.新增公告') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/punish/add'
            });
        }

        function update(id){
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.修改公告') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/punish/update/'+id
            });
        }

        function publish(id){
            myConfirm("{{ __('auto.是否继续') }}?",function(){
                myRequest("/admin/punish/update/"+id,"post",{},function(res){
                    layer.msg(res.msg)
                    setTimeout(function(){
                        window.location.reload();
                    },1500)
                });
            });
        }

        $('.menu-switch').click(function(){
            id = $(this).attr('id');
            state = $(this).attr('state');
            console.log(id)
            console.log(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
