@extends('vip.layouts254js')
@section('content')
    <link href={{ asset("baidu/themes/default/css/umeditor.css") }} type="text/css" rel="stylesheet">
    <form class="layui-form" action="{{ url()->full() }}" id="submitForm" name="submitForm" method="post"
          eventType=eventAjaxForm>
        {!! csrf_field() !!}
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" required lay-verify="required" autocomplete="off" class="layui-input"
                       value="{{isset($data['title'])?$data['title']:''}}">
            </div>
        </div>
        @if(isset($select))
            <div class="layui-form-item">
                <label class="layui-form-label">公告类型</label>
                <div class="layui-input-block">
                    <select name="type" id="testSelect" class="Selects" lay-filter="testSelect">
                        <option value="" selected>请选择</option>
                        <option value="1" @if (isset($data['type']) && $data['type']==1 )  selected  @endif>新闻</option>
                        <option value="2" @if (isset($data['type']) && $data['type']==2 )  selected  @endif>公告</option>
                        <option value="3" @if (isset($data['type']) && $data['type']==3 )  selected  @endif>优惠活动</option>
                        <option value="11" @if (isset($data['type']) && $data['type']==11 )  selected  @endif>新手指南</option>
                        <option value="10" @if (isset($data['type']) && $data['type']==10 )  selected  @endif>常见问题</option>
                        <option value="20" @if (isset($data['type']) && $data['type']==20 )  selected  @endif>彩金活动</option>

                    </select>
                </div>
            </div>
        @endif


        <div class="layui-form-item">
            <label class="layui-form-label">电脑内容</label>
            <div class="layui-input-block">
                <textarea name="desc" id="myEditor"
                          style="width:1000px;height:240px;">{{isset($data['content'])?$data['content']:''}}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电脑图片</label>
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            @if (isset($data['img']) && !empty($data['img']) )
                <a href="{{$data['img']}}" target="_blank"><img src="{{$data['img']}}" width="50"></a>
             @endif
            <div class="layui-input-block">
                <input type="text" name="img" id="img" class="layui-input"
                       value="{{isset($data['img'])?$data['img']:''}}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机内容</label>
            <div class="layui-input-block">
                <textarea name="mobilecontent" id="myEditortwo"
                          style="width:1000px;height:240px;">{{isset($data['mobilecontent'])?$data['mobilecontent']:''}}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">手机图片</label>
            <button type="button" class="layui-btn" id="test2">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            @if (isset($data['mobileimg']) && !empty($data['mobileimg']) )
                <a href="{{$data['mobileimg']}}" target="_blank"><img src="{{$data['mobileimg']}}" width="50"></a>
            @endif
            <div class="layui-input-block">
                <input type="text" name="mobileimg" id="mobileimg" class="layui-input"
                       value="{{isset($data['mobileimg'])?$data['mobileimg']:''}}">
            </div>
        </div>
        @if(isset($list))
            <div class="layui-form-item">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-block">
                    <input type="text" name="author" required lay-verify="required" autocomplete="off"
                           class="layui-input" value="{{isset($data['author'])?$data['author']:''}}">
                </div>
            </div>
        @endif

        <div class="layui-form-item">
            <label class="layui-form-label">绑定参数</label>
            <div class="layui-input-inline">
                <input type="text" name="typebind" autocomplete="off" class="layui-input"
                       value="{{isset($data['typebind'])?$data['typebind']:''}}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                参数可填写【saveMoneyScanQRcode（存款二维码扫描教程）,saveMoneyTobank（存款到银行卡教程），indexNotice（首页公告）,sign
                (签到规则说明),chatroomExplain(聊天室说明),openhome(首页活动推荐弹图),shoppingcart(购物车帮助),chathelp(存聊天室的帮助教程)】
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" required lay-verify="required" autocomplete="off" class="layui-input"
                       value="{{isset($data['sort'])?$data['sort']:''}}">

            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <a class="layui-btn lay-btn-diy" href="javascript:history.go(-1)">返回</a>
                @if(checkRriv('/admin/Notice/view'))
                    <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>@endif
                <button type="reset" class="layui-btn layui-btn-normal">重置</button>
            </div>
        </div>
    </form>
    <script type="text/javascript" src={{ asset("baidu/third-party/jquery.min.js") }}></script>
    <script type="text/javascript" charset="utf-8" src={{ asset("baidu/umeditor.config.js") }}></script>
    <script type="text/javascript" charset="utf-8" src={{ asset("baidu/umeditor.min.js") }}></script>
    <script type="text/javascript" src={{ asset("baidu/lang/zh-cn/zh-cn.js") }}></script>
    <script>
        //Demo
        layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , upload = layui.upload;
            //图片上传接口
            layedit.set({
                uploadImage: {
                    url: '/admin/notice/upImg' //接口url
                    , type: 'post' //默认post
                }
            });

            upload.render({
                elem: '#test1' //绑定元素
                , url: '/admin/notice/upImg' //上传接口
                , headers: {"X-CSRF-TOKEN": "{{ csrf_token() }}"}
                , done: function (res) {
                    if (res.code == 0) {
                        $("#img").val(res.data.src);
                        layer.msg("上传图片成功!", {icon: 1});
                    } else {
                        layer.msg("上传图片发生错误!", {icon: 5});
                    }
                }
                , error: function () {
                    console.log('upload img error');
                }
            });

            //执行实例
            upload.render({
                elem: '#test2' //绑定元素
                , url: '/admin/notice/upImg' //上传接口
                , headers: {"X-CSRF-TOKEN": "{{ csrf_token() }}"}
                , done: function (res) {
                    if (res.code == 0) {
                        $("#mobileimg").val(res.data.src);
                        layer.msg("上传图片成功!", {icon: 1});
                    } else {
                        layer.msg("上传图片发生错误!", {icon: 5});
                    }
                }
                , error: function () {
                    console.log('upload img error');
                }
            });

            //var um = UM.getEditor('myEditor');
            var um = UM.getEditor('myEditor', {
                initialFrameWidth: 1000,
                initialFrameHeight: 400
            });
            var umtwo = UM.getEditor('myEditortwo', {
                initialFrameWidth: 1000,
                initialFrameHeight: 400
            });
            /*var editIndex = layedit.build('LAY_demo_editor');*/
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
                , pass: [/(.+){6,12}$/, '密码必须6到12位']
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });


            //监听提交
            form.on('submit(submitForm)', function (data) {
                return true;
            });


        });

        //创建一个编辑器
        function cbFormSuccess(data) {
            layer.msg(data.msg);
            setTimeout(function () {
                window.history.go(-1)
            }, 2500);
        }
    </script>
@endsection
