@extends('vip.layouts')
@section('content')

    <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>

            <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="">请选择</option>
                        {{--<option  value="1" selected>系统信息</option>--}}
                        <option  value="1" @if(isset($data['type'])&&$data['type']==1) selected @endif>普通信息</option>
                        {{--<option  value="3">会员组</option>--}}
                        <option  value="3" @if(isset($data['type'])&&$data['type']==3) selected @endif>系统通知</option>
                        {{--<option  value="4">管理员通知</option>--}}
                    </select>
                </div>
            </div>

        <!-------用户组---->
            <div class="layui-form-item" id="labels"   @if((isset($data['type'])&&$data['type']!=3)||!isset($data['type'])) style="display: none" @endif>
                <label class="layui-form-label">用户组</label>
                <div class="layui-input-block">
                    @foreach ($group as $k=>$v)
                        <input type="checkbox" name="groups[]" @if(isset($data['group_code'])&&in_array($v['group_code'],explode(',',$data['group_code'])))   checked @endif value="{{$v['group_code']}}" title="{{$v['group_name']}}">
                    @endforeach
                </div>
                <p style="color: red">(不选择用户组时，默认发送全部用户)</p>
            </div>

            <!---------普通发送-------->
            <div class="layui-form-item single">
                <label class="layui-form-label">接收者</label>
                <div class="layui-input-block">
                    <input type="text" name="toname" autocomplete="off" class="layui-input"
                           value="{{isset($data['toname'])?$data['toname']:''}}">
                    <p style="color: red">(选择普通消息时，填写名字请用‘，’分开)</p>
                </div>
            </div>

            <div class="layui-form-item single">
                <label class="layui-form-label">发布者</label>
                <div class="layui-input-block">
                    <input type="text" name="formname"  autocomplete="off" class="layui-input" value="{{isset(
      $data['formname'])?$data['formname']:''}}">
                    <p style="color: red">(选择普通消息时，必须填写发布者)</p>
                </div>
            </div>



        @if(isset($data['add_type']))
        <div class="layui-form-item">
            <label class="layui-form-label">新用户是否接收</label>
            <div class="layui-input-block">
                <input type="radio" name="status" eventType="event-query" value="1" title="接收"
                       @if($data['add_type']==1) checked @endif>
                <input type="radio" name="status" eventType="event-query" value="0" title="不接收"
                       @if($data['add_type']==2) checked @endif>
            </div>
        </div>
        @else
        <div class="layui-form-item">
            <label class="layui-form-label">新用户是否接收</label>
            <div class="layui-input-block">
                <input type="radio" name="add_type" eventType="event-query" value="1" title="接收">
                <input type="radio" name="add_type" eventType="event-query" value="2" title="不接收">
            </div>
        </div>
        @endif
        @if(isset($data['is_show']))
            <div class="layui-form-item">
                <label class="layui-form-label">首页是否弹出</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_show" eventType="event-query" value="1" title="是"
                           @if($data['is_show']==1) checked @endif>
                    <input type="radio" name="is_show" eventType="event-query" value="0" title="否"
                           @if($data['is_show']==0) checked @endif>
                </div>
            </div>
        @else
            <div class="layui-form-item">
                <label class="layui-form-label">首页是否弹出</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_show" eventType="event-query" value="1" title="是">
                    <input type="radio" name="is_show" eventType="event-query" value="0" title="否">
                </div>
            </div>
        @endif
        <div class="layui-form-item">
            <label class="layui-form-label">信息内容</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea layui-hide" name="desc" lay-verify="content"
                          id="LAY_demo_editor">{{isset($data['content'])?$data['content']:''}}</textarea>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                @if(!isset($data['toname']))
                @if(checkRriv('/admin/Message/view'))<button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>@endif
                <button type="reset" class="layui-btn layui-btn-normal">重置</button>
                    @else

                @endif
            </div>
        </div>


    </form>

    <script>

        //Demo
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            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('select(testSelect)', function(data){
               console.log(data.value);
               if (data.value==3) {
                    $('.single').hide();
                    $('#labels').show();
               }else{
                   $('.single').show();
                   $('#labels').hide();
               }
            });

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


        });
        //创建一个编辑器
function cbFormSuccess(data){
	layer.msg(data.msg);
	setTimeout(function(){
        window.location.href="/admin/Message/index";
	},2500);
}

    $(function(){

    });

    $("#label").change(function(){
        $(this).parent().next().hide();
        if ($(this).val()=='1') {
         $(this).parent().next().show();
        }
    });

    </script>
@endsection
