@extends('vip.layouts')
@section('content')
	
	<div class="layui-row">
		<div class="layui-col-xs12">
			<div class="layui-form-item" style="margin-left:50px;">
            <form class="layui-form rewrite" eventType="eventForm"  action="">
				<div class="layui-inline">
    				<label class="layui-form-label">搜&nbsp;&nbsp;索 </label>
                    <input type="hidden" id="match_id" name="match_id" value="{{$match_id}}">
    				<div class="layui-input-inline">
                        <select name="sousuo" id="sousuo" autocomplete="off">
                            <option value="">请选择危险球类型</option>
                            <option value="角球">角球</option>
                            <option value="12码罚球">12码罚球</option>
                            <option value="自由球">自由球</option>
                            <option value="掷入球">掷入球</option>
                        </select>
    					<!-- <input type="text" placeholder="输入赛事ID" name="sousuo" id="sousuo" lay-verify="" autocomplete="off" class="layui-input" value="{{$sousuo}}">11 -->
    				</div>

    				<div class="layui-inline">
                        <button class="layui-btn layui-btn-sm lay-btn-diy" data-type="reload" style="opacity: 1; pointer-events: auto;">提交</button>
                        <button onclick="addResult({{$match_id}},'',10000)" class="layui-btn layui-btn-sm lay-btn-diy" style="margin-left: 20px">添加危险球</button>
                        <a class="layui-btn layui-btn-sm lay-btn-diy" href="javascript:history.go(-1)">返回</a>
    				</div>
				</div>
            </form>

            </div>
		</div>
    </div>

    <table id="demo" lay-filter="test"></table>
    
<!--
	
    <table lay-filter="parse-table-demo" style="width:80%;text-align:left;">
        <tr class="layui-form-item">
            <td class="layui-form-label" style="width:5%;left:10px;"><h3>id</h3></td>
            <td class="layui-form-label" style="width:20%;left:10px;"><h3>危险球时间</h3></td>
            <td class="layui-form-label" style="width:20%;left:10px;"><h3>危险球有效时间</h3></td>
            <td class="layui-form-label" style="width:20%;left:10px;"><h3>危险球类型</h3></td>
            <td class="layui-form-label" style="width:20%;left:10px;"><h3>操 作</h3></td>
        </tr>
        @if($warnmore)
        @foreach ($warnmore as $k=>$val)
        <tr class="layui-form-item">
            <td class="layui-form-label" style="width:5%;left:10px;">{{$k+1}}</td>
            <td class="layui-form-label" style="width:20%;left:10px;">{{$val['timei']}}</td>
            <td class="layui-form-label" style="width:20%;left:10px;">{{$val['timep']}}</td>
            <td class="layui-form-label" style="width:20%;left:10px;">{{$val['rtype']}}</td>
            <td class="layui-form-label" style="width:20%;left:10px;">
                <button onclick="addResult({{$match_id}},{{$k}},2)" class="layui-btn layui-btn-sm layui-btn-green set">编辑</button>
            </td>
        </tr>
        @endforeach
        @else
        <tr class="layui-form-item">
            <td class="layui-form-label" style="width:150px;left:10px;">暂时无危险球数据</td>
        </tr>
        @endif
    </table>

-->

    <script type="text/javascript">
        $(function () {
            $('body').on('click', 'a[eventtype="event-delete"]', function () {
                var span = $(this).prev();
                var id = span.attr('data-id');
            })
            $('body').on('click','#form_sureblur~.layui-form-switch',function(){
                var sus = $('#form_sureblur').next().text();
                if(sus=='精确'){
                    $('#form_sureblurs').val('on');
                }else{
                    $('#form_sureblurs').val('off');
                }
            })
        })


        let conttxt = '';
        let layerOpen = '';
        function addResult(match_id,wid,typenum){
            var wid = wid?wid:0;

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/warnresult',
                data: {match_id:match_id,wid:wid,typenum:typenum},
                success: function(data) {
                    conttxt ='<div style="margin-left:50px;margin-top:20px;font-size:18px;line-height:150%;"><input type="hidden" id="matchid" name="matchid" value="'+match_id+'" /><input type="hidden" id="wid" name="wid" value="'+wid+'" /><input type="hidden" id="typenum" name="typenum" value="'+typenum+'" /><div style="display: flex;margin-top: 30px;"><li style="width: 120px;">危险球时间：</li>';

/*
                    if(wid!=0){
                        conttxt += '<input type="text" id="timei" name="timei" value="'+data.warn_more[wid].timei+'" autocomplete="off">';
                    }else{
                        conttxt += '<input type="text" id="timei" name="timei" value="'+data['starttime']+'" autocomplete="off">';
                    }

                    //=================

/*
                    conttxt += '<input type="number" min="0" max="90" style="width:63px;" placeholder="0~90" id="timei_i" name="timei_i" value="" autocomplete="off">';
                    conttxt += '<p>分</p>';
                    conttxt += '<input type="number" min="0" max="59" style="width:63px;" placeholder="0~59" id="timei_s" name="timei_s" value="" autocomplete="off">';
                    conttxt += '<p>秒</p>';
*/
                    //======================
                    conttxt += '<input type="text" id="timei" name="timei">';

                    conttxt +='</div><div style="display: flex;margin-top: 20px;"><li style="width: 120px;">需审核时间：</li>';
                    if(data.warn_more[wid].timep!=0){
                        conttxt += '<input type="number" min="60" max="300"  style="width:200px;" placeholder="60~300" id="timep" name="timep" value="'+data.warn_more[wid].timep+'" autocomplete="off">';
                    }else{
                        conttxt += '<input type="number" min="60" max="300"  style="width:200px;" placeholder="60~300" id="timep" name="timep" autocomplete="off">';
                    }
                    conttxt += '<p>秒</p>';

                    conttxt += '</div><div style="display: flex;margin-top: 20px;"><li style="width: 120px;">危险球类型：</li><select style="width:225px;" name="warntype" id="warntype">';
                    if(data.warn_more[wid].rtype!=0){
                        conttxt += '<option style="width:225px;" value="'+data.warn_more[wid].rtype+'">'+data.warn_more[wid].rtype+'</option><option style="width:140px;" value="0">无危险球类型';
                    }else{
                        conttxt += '<option style="width:225px;" value="0">请选择危险球类型';
                    }

                    conttxt += '</option><option style="width:225px;" value="角球">角球</option><option style="width:225px;" value="12码罚球">12码罚球</option><option style="width:225px;" value="自由球">自由球</option><option style="width:225px;" value="掷入球">掷入球</option></select></div><br><div style="margin-left:230px;"><button class="layui-btn layui-btn-sm layui-btn-green set" onclick="buttonClick()"><h3>确定</h3></button>&nbsp;<button class="layui-btn layui-btn-sm layui-btn-danger" onclick="czClick()"><h3>取消</h3></button></div></div>';

                    layerOpen = layer.open({
                      type: 1 //Page层类型
                      ,area: ['500px', '270px']
                      ,title: '<h2>添加/编辑危险球结果<h2>'
                      ,shade: 0.6 //遮罩透明度
                      ,maxmin: true //允许全屏最小化
                      ,anim: 1 //0-6的动画形式，-1不开启
                      ,content:conttxt
                    });

                     //日期时间有效范围的设定: 
                    laydate.render({ 
                    elem: '#timei'
                    ,type: 'datetime'
                    ,value: data.warn_more[wid].timei
                    ,min: data.starttime
                    ,max: data.endtime
                    });
                }
            })
        }


        function czClick() {
            layer.close(layerOpen)
        }

        function ces(){
            var match_id = $("#match_id").val();
            var warn_type = $("#sousuo").val();
            console.log(match_id);
            console.log(warn_type);

        }

        function buttonClick(){
            var matchid = $("#matchid").val();
            var timei = $("#timei").val();
            var timep = $("#timep").val();
            var warntype = $("#warntype").val();
            var wid = ($("#wid").val())-1;
            var typenum = $("#typenum").val();

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/addwarnonly',
                data: {match_id:matchid,time_i:timei,time_p:timep,warn_type:warntype,wid:wid,type_num:typenum},
                success: function(data) {
                    //console.log(data);
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }else{
                        layer.msg(data.msg);return;
                    }
                }
            })
        }

        /*
        function buttonClick(){
            var matchid = $("#matchid").val();
            var timei = $("#timei").val();
            var timep = $("#timep").val();
            var warntype = $("#warntype").val();
            var wid = $("#wid").val();
            var typenum = $("#typenum").val();

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/addwarnonly',
                data: {matchid:matchid,timei:timei,timep:timep,warntype:warntype,wid:wid,typenum:typenum},
                success: function(data) {
                    //console.log(data);
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }else{
                        layer.msg(data.msg);return;
                    }
                }
            })
        }
        */

    </script>
    <script src="/layui/layui.js"></script> 
    <script type='text/javascript'>
        var table = layui.table;
 
        //执行渲染危险期数据
        table.render({
            elem: '#demo' //指定原始表格元素选择器（推荐id选择器）
            ,height: 315 //容器高度
            ,cols:  [[ //标题栏
                {checkbox: true}
                ,{field: 'id', title: 'ID'}
                ,{field: 'timei', title: '发生时间'}
                ,{field: 'timep', title: '有效时间(秒)'}
                ,{field: 'rtype', title: '类型'}
                ,{fixed: 'right', title: '操作', align:'center', toolbar: '#barDemo'}

            ]] 
            ,url: '/admin/Sportsfoot/getWarnData'
            ,where: {match_id: {{$match_id}}}
        });


        //监听工具条 
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var warn_id = (obj.data.id)-1; //获得当前id
            var layEvent = obj.event; 
            
                if(layEvent === 'edit'){ //编辑
                    addResult({{$match_id}},warn_id,2)
                }
        });
    
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>    
    </script>

    
      

@endsection
