@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="name_chinese" required  lay-verify="required" placeholder="请输入联赛名称" autocomplete="off" value="{{ isset($name_chinese)?$name_chinese:'' }}" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">所属地区</label>
            <div class="layui-input-block">
                <select name="area_id" id="area" lay-filter="sect">
                    <option value></option>
                    @if(isset($area))
                        @foreach($area as $k=>$v)
                            <option value="{{ $v['id'] }}"  @if(isset($area_id)&&$area_id==$v['id'])  selected @endif>   {{$v['name']}}   </option>
                        @endforeach
                    @endif
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-form">
            <label class="layui-form-label">所属国家</label>
            <div class="layui-input-block">
                <select name="country_id" id="country" lay-filter = 'sect_country' autocomplete="off" class="layui-input"  eventType=event-query>
                    <option value="{{ isset($country_id)?$country_id:'' }}">{{ isset($country)?$country:'' }}</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">联赛状态</label>
            <div class="layui-input-block">
                @if(isset($status))
                    <input type="radio" name="status" value="-1" title="未启用" @if($status=='-1') checked @endif >
                    <input type="radio" name="status" value="1" title="启用" @if($status=='1') checked @endif>
                @else
                    <input type="radio" name="status" value="-1" title="未启用" checked >
                    <input type="radio" name="status" value="1" title="启用">
                @endif
            </div>
        </div>

        @if(S('ACTION')!='view')
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <a class="layui-btn layui-btn-sm lay-btn-diy" href="javascript:history.go(-1)" style="background-color:#1E9FFF;width: 92px; height: 38px;line-height: 38px;font-size: 14px;">返回</a>
                    <button class="layui-btn" lay-submit lay-filter="submitForm">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        @endif
    </form>

    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script>
        var id;
        var aa;
        layui.use(['form'], function(){
            var form = layui.form;
            form.on('select(sect)',function(data){
                id = data.value;
                //console.log(id);
                $.ajax({
                    type:'get',
                    url:'/admin/BasketLeague/getcountry',
                    data:{id:id},
                    dataType:'json',
                    success:function(data){  //请求成功回调函数
                        //console.log(data);
                        var option = '';
                        var dd = '';
                        option += '<option value></option>';
                        //dd += '<dd lay-value class="layui-select-tips">请选择</dd>';
                        for(var i=0;i<data.length;i++){  //循环获取返回值，并组装成html代码
                            option += "<option value="+data[i]["id"]+">"+data[i]["name"]+"</option>";
                        }
                        $("#country").html(option);
                        //重新渲染select
                        form.render('select');
                    },
                });
            })
            //监听提交
            form.on('submit(submitForm)', function(data){
                return true;
            });
        });
    </script>
@endsection
