@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>
                            <table class="table table-bordered">
                                <thead>
                                <tr>

                                    <th>{{ __('auto.功能名称') }}</th>
                                    <th>{{ __('auto.弹出状态') }}</th>
                                    <th>{{ __('auto.修改发布内容') }}</th>
                                    <th>{{ __('auto.上次发布时间') }}</th>
                                    <th>{{ __('auto.弹出功能总开关') }}</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $val)
                                    <tr>

                                        <td style="width: 7%">{{$val->StatusTip}}</td>
                                        <td style="width: 15%"></td>
                                        <td style="width: 15%">
                                            <div>
                                                <div>
                                                <textarea class="form-control" name="message" rows="4"
                                                          disabled="disabled"
                                                          style="float: left;width: 80%">{{$val->StatusString}}</textarea>
                                                </div>
                                                <div>
                                                    <button class="btn btn-sm btn-gradient-dark"
                                                            style="float: right;width: 20%;margin-top: 30px"
                                                            onclick="updateFunc('{{$val->StatusName}}')">{{ __('auto.修改') }}
                                                    </button>
                                                </div>
                                            </div>

                                        </td>
                                        <td style="width: 15%"></td>
                                        <td style="width: 15%">
                                            @if ($val->StatusValue == '1')
                                                {{ __('auto.已开启') }}
                                                <button class="btn btn-sm btn-gradient-dark"
                                                        onclick="updateStatusFunc('{{$val->StatusName}}',2)">
                                                    {{ __('auto.关闭') }}
                                                </button>
                                            @else
                                                {{ __('auto.已关闭') }}
                                                <button class="btn btn-sm btn-gradient-dark"
                                                        onclick="updateStatusFunc('{{$val->StatusName}}',1)">
                                                    {{ __('auto.开启') }}
                                                </button>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

        function updateStatusFunc(StatusName, statusVal) {
            myConfirm("{{ __('auto.操作不可逆,是否继续') }}?", function () {
                myRequest('/admin/system/update_status', 'post', {StatusName,statusVal}, function (response) {
                    layer.msg(response.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                })
            })
        }

        function updateFunc(StatusName) {

            switch (StatusName) {
                case 'SUSPENSION_NOTICE':
                    publicView('{{ __('auto.停服维护公告') }}', ['50%', '60%'], '/admin/system/add?StatusName='+StatusName)
                    break;
                case 'HN_SC_NOTICE':
                    publicView('{{ __('auto.跑马灯') }}', ['50%', '60%'], '/admin/system/add?StatusName='+StatusName)
                    break;
            }
        }

        function add() {
            var page = layer.open({
                type: 2,
                title: '{{ __('auto.添加菜单') }}',
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '90%'],
                content: '/admin/system/add'
            });
        }

        function publicView(title, area, content) {
            var page = layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: 0.8,
                area: area,
                content: content
            });
        }

        $('.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
