@extends('base.base')
@section('base')
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="row">
                <div class="col-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">{{ __('auto.请填写管理员信息') }}</h4>

                            <form class="forms-sample" id="form">

                                <div class="form-group">
                                    <label for="nickname">*功能名称</label>
                                    <input type="text" class="form-control required" name="Title" placeholder="{{ __('auto.请输入功能名称') }}"
                                           value="{{$info->Title}}">
                                </div>

                                <div class="form-group">
                                    <label for="account">*展示权重</label>
                                    <input type="number" class="form-control required" name="Sort" placeholder="{{ __('auto.请输入权重') }}"
                                           value="{{$info->Sort}}">
                                </div>

                                <h5>*公告展示内容</h5>
                                <label for="written_words">
                                    <input type="radio" name="Type" id="written_words" onclick="written_wordsFunc()"
                                           value="1" @if ($info->Type == 1)
                                           checked
                                        @endif> {{ __('auto.文字公告') }}
                                </label>
                                <label for="image">
                                    <input type="radio" name="Type" id="image" onclick="imageFunc()" value="2"
                                           @if ($info->Type == 2)
                                           checked
                                        @endif> {{ __('auto.图片内容') }}
                                </label>


                                <div class="written_words" @if ($info->Type == 2)
                                style="display: none;"
                                    @endif>
                                    <div class="form-group">
                                        <label for="account">*标题</label>
                                        <input type="text" class="form-control" name="Abstract" placeholder="{{ __('auto.请输入标题') }}"
                                               @if ($info->Type == 1)
                                               value="{{$info->Abstract}}"
                                            @endif>
                                    </div>
                                    <div class="form-group">
                                        <label for="account">*正文</label>
                                        <textarea name="Content" id="" cols="30" rows="10"
                                                  class="form-control">@if ($info->Type == 1){{$info->Content}}@endif</textarea>
                                    </div>
                                </div>

                                <div class="image" @if ($info->Type == 1)
                                style="display: none;"
                                    @endif>
                                    <div class="form-group">
                                        <label>{{ __('auto.请上传一张活动图片') }}</label>
                                        <input type="file" class="file-upload-default img-file" data-path="avatar">
                                        <input type="hidden" name="avatar" class="image-path"  value="{{$info->Content}}">
                                        <div class="input-group col-xs-12">
                                            <input type="text" class="form-control file-upload-info" disabled=""
                                                   @if ($info->Type == 2)
                                                   value="{{$info->Content}}"
                                                   @endif>
                                            <span class="input-group-append">
                                            <button class="file-upload-browse btn btn-gradient-primary"
                                                    onclick="upload($(this))" type="button">{{ __('auto.上传') }}</button>
                                        </span>
                                        </div>
                                        <div class="img-yl" style="display: block;">
                                            @if ($info->Type == 2)
                                                <img src="{{$info->Content}}" alt="">
                                            @endif

                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="account">*支持图片跳转功能，请填写客户端代码跳转地址</label>
                                        <input type="text" class="form-control" name="Url" @if ($info->Type == 2)
                                        value="{{$info->Abstract}}"
                                            @endif>
                                    </div>
                                </div>
                                <button type="button" onclick="commit({{$info->ID}})"
                                        class="btn btn-sm btn-gradient-primary btn-icon-text">
                                    <i class="mdi mdi-file-check btn-icon-prepend"></i>
                                    {{ __('auto.提交') }}
                                </button>
                                <button type="button" onclick="cancel()"
                                        class="btn btn-sm btn-gradient-warning btn-icon-text">
                                    <i class="mdi mdi-reload btn-icon-prepend"></i>
                                    {{ __('auto.取消') }}
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        function written_wordsFunc() {

            $('.image').attr('style', 'display:none')
            $('.written_words').attr('style', 'display:block')
        }

        function imageFunc() {

            $('.written_words').attr('style', 'display:none')
            $('.image').attr('style', 'display:block')
        }

        function commit(id) {
            if (!checkForm()) {
                return false;
            }
            var data = $("#form").serializeObject();

            myRequest("/admin/notice/hall_announcement_update/" + id, "post", data, function (res) {
                if (res.code == '200') {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        parent.location.reload();
                    }, 1500)
                } else {
                    layer.msg(res.msg)
                }
            });
        }

        function cancel() {
            parent.location.reload();
        }
    </script>
@endsection
