@extends('vip.layouts')
@section('seo_title')
    足球赛事
@endsection
@section('content')
<style type="text/css">
    /* 弹窗 (background) */
    .modal {
        display: none; /* 默认隐藏 */
        /*生成绝对定位的元素，相对于浏览器窗口进行定位。*/
        position: fixed; 
        z-index: 1; 
        left: 0;
        top: 0;
        /*设置弹窗位置*/
        padding-top: 100px;
        padding-bottom: 200px;
        /*浮在全屏上*/
        width: 100%; 
        height:  100%; 
        /*overflow：auto；如果内容被修剪，则浏览器会显示滚动条，以便查看其余内容。*/
        overflow: auto; 
        background-color: rgb(0,0,0); 
        background-color: rgba(0,0,0,0.4);
        text-align: right;
    }

    /* 弹窗内容 */
    .modal-content {
        /*position: relative;*/
        /*弹窗背景色设置*/
        background-color: #fefefe;
        margin: auto;
        padding: 260px auto;
        width: 600px;
        box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
        -webkit-animation-name: animatetop;
        -webkit-animation-duration: 0.4s;
        animation-name: animatetop;
        animation-duration: 0.4s;
        border-radius: 10px;
       }

    /* 添加动画 */
    @-webkit-keyframes animatetop {
        from {top:-200px; opacity:0} 
        to {top:0; opacity:1}
    }

    @keyframes animatetop {
        from {top:-200px; opacity:0}
        to {top:0; opacity:1}
    }

    /* 关闭按钮 */
    .close {
        color: white;
        float: right;
        font-size: 28px;
        font-weight: bold;
    }

    .close:hover, .close:focus {
        color: #000;
        text-decoration: none;
        cursor: pointer;
    }

    .modal-header {
        display: block;
        line-height: 30px;
        padding: 2px 10px;
        background-color: #AEAEAE;
        color: white;
        text-align: left;
        border-radius: 5px 5px 0 0;
    }

    .modal-body {
        padding: 2px 16px;
        font-size: 18px;
        /*height: 200px;*/
    }

    .modal-footer {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 520px;
        padding: 0 40px;
        height: 50px;
       border-radius:0 0 5px 5px;
        display: block;
        line-height: 39px;
        background-color: #AEAEAE;
        color: white;
    }
    .ok,.no{
        width: 100px;
        height: 40px;
    }
</style>

    <script type="text/html" id="newtime">
      @{{#if(d.match_id!=null){ }}
        <span>@{{ d.match_id}}</span>
      @{{#} }}<br>
      @{{#if(d.saisname!=null){ }}
        <span>@{{ d.saisname}}</span>
      @{{#} }}
    </script>

    <script type="text/html" id="totime">
      @{{#if(d.start_time!=null){ }}
        <span>@{{ d.start_time}}</span>
      @{{#} }}
    </script>

    <script type="text/html" id="dsnum">
        <span><a href="/admin/SoccerNoteList/notelist?match_id=@{{d.match_id}}"> 单式</a></span>
    </script>

    <script type="text/html" id="status">
		<button onclick="addResult(@{{d.match_id}})" class="layui-btn layui-btn-sm layui-btn-green set">赛事结果</button>
        @{{#if(d.status==2 || d.status==3){ }}
            @{{#if(d.status==2){ }}
                <span><li class="layui-btn layui-btn-sm layui-btn-green set" onclick="settlement(@{{d.match_id}},1)">结算</li></span>
            @{{#} }}
            @{{#if(d.status==3){ }}
                <span><li class="layui-btn   layui-btn-sm layui-btn-normal reset" onclick="settlement(@{{d.match_id}},2)">再结算</li></span>
            @{{#} }}
        @{{#} }}
        @{{#if(d.status!=4 && d.status!=3){ }}
        <span><li class="layui-btn layui-btn-sm  layui-btn-danger" onclick="revoke(@{{d.match_id}})">作废</li></span>
        @{{#} }}
        @{{#if(d.status==4){ }}
        <span><li class="layui-btn layui-btn-sm  layui-btn-danger" onclick="revoke(@{{d.match_id}})">已作废</li></span>
        @{{#} }}
    </script>

    <script type="text/html" id="statusmatch">
	@{{#if(d.status==0){ }}
        <span>未开始</span>
      @{{#} }}
      @{{#if(d.status==1){ }}
        <span>进行中</span>
      @{{#} }}
      @{{#if(d.status==2){ }}
        <span>已结束</span>
      @{{#} }}
	  @{{#if(d.status==3){ }}
        <span>已结算</span>
      @{{#} }}
	  @{{#if(d.status==4){ }}
        <span>已作废</span>
      @{{#} }}
    </script>

    <script type="text/html" id="sxalfcourt">
      @{{#if(d.match_time!=null){ }}
        <!-- <span>@{{ d.match_time}}</span> -->
        <input type="text" style="width:30px;heigth:20px" id="u_home_score@{{d.id}}" name="u_home_score" value="@{{d.u_home_score}}" onchange="inputFunc(@{{d.id}}, event.target.value,@{{d.match_id}})"> 
        <input type="text" style="width:30px;heigth:20px" id="u_guest_score@{{d.id}}" name="u_guest_score" value="@{{d.u_guest_score}}" onchange="inputTunc(@{{d.id}}, event.target.value,@{{d.match_id}})"> / 
        <input type="text" style="width:30px;heigth:20px" id="home_score@{{d.id}}" name="home_score" value="@{{d.home_score}}" onchange="inputSunc(@{{d.id}}, event.target.value,@{{d.match_id}})">
        <input type="text" style="width:30px;heigth:20px" id="guest_score@{{d.id}}" name="guest_score" value="@{{d.guest_score}}" onchange="inputAunc(@{{d.id}}, event.target.value,@{{d.match_id}})">

      @{{#} }}
    </script>


    <script type="text/html" id="status">
        @if(checkRriv('/admin/sportsfoot/index'))<input type="checkbox" name="status" id="uid" value="@{{d.id}}" lay-skin="switch" lay-text="进行中|已结束" lay-filter="openStatus" @{{ d.status == '1' ? 'checked' : '' }}>@endif
    </script>

    <div class="layui-row">
        <div class="layui-col-xs12">
            <form class="layui-form rewrite" eventType="eventForm"  action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsfoot.sousuo') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="home_team" id="home_team" eventType="event-query"  value="{{ $home_team }}" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline checkbox">
                            <input type="checkbox" name="sureblur" id="form_sureblur" lay-skin="switch" lay-text="精确|模糊" @if(!isset($sureblurs) || $sureblurs=='on') checked @endif  class="layui-input" eventType=event-query>
                            <input type="hidden" name="sureblurs" id="form_sureblurs" lay-verify="required" autocomplete="off" class="layui-input" eventType=event-query  value="{{ $sureblurs }}">
                        </div>
                    </div>
					<div class="layui-inline">
						<label class="layui-form-label">{{ trans('sportsfoot.status') }}</label>
						<div class="layui-input-inline" style="width: 200px">
							<select name="status"  id="status"  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>
								<option value="-1">{{ trans('sportsfoot.select_status') }}</option>
								@foreach(trans('status.match_status.status') as $k=>$v):
									@if($status==$k))
										<option value="{{$k}}" selected="selected">{{$v}}</option>
									@else
										<option value="{{$k}}">{{$v}}</option>
									@endif
								@endforeach
							</select>
						</div>
				   </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsfoot.sjsource') }}</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <select name="source"  id="form_source"  lay-verify="" autocomplete="off" class="layui-input" eventType=event-query>
                                <option value="">请选择{{ trans('sportsfoot.sjsource') }}</option>
                                @foreach(trans('status.sjsource.source') as $k=>$v):
                                    @if($source==$k)
                                        <option value={{$v}} selected>{{$v}}</option>
                                    @else
                                        <option value={{$v}}>{{$v}}</option>
                                    @endif
                                @endforeach
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">相关操作:</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <select name=""  id=""  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>
                                <option value="">选择确认</option>
                                @foreach(trans('status.xgstatus.status') as $k=>$v):
                                    <option value="{{$k}}">{{$v}}</option>
                                @endforeach
                                <option value="">设为无效</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsfoot.star_time') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="star_time" value="{{ $star_time }}" id="star_time" placeholder=" - "  lay-verify="" autocomplete="off" class="layui-input test-item" eventType=event-query>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsfoot.end_time') }}</label>
                        <div class="layui-input-inline">
                            <input type="text" name="end_time"  value="{{$end_time}}" id="end_time" placeholder=" - " word-break: break-all; lay-verify="" autocomplete="off" class="layui-input test-item" eventType=event-query>
                        </div>
                    </div>



                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-sm lay-btn-diy"   data-type="reload" eventType="event-query-submit" style="opacity: 1; pointer-events: auto;">提交</a>
                        <a  class="layui-btn   layui-btn-sm layui-btn-normal reset" data-type="reload" style="opacity: 1; pointer-events: auto;">重置</a>
                        <a class="layui-btn layui-btn-xs" data-type="reload" style="opacity: 1; pointer-events: auto;"><i class="layui-icon" onclick="refreshall('zq')">刷新赛事</i></a>
                        <!-- @if(checkRriv('/admin/sportsfoot/addoutcome'))<a href="/admin/sportsfoot/addoutcome" class="layui-btn layui-btn-sm ">添加</a>@endif -->
                        @if(checkRriv('/admin/sportsfoot/deleteoutcome'))<a href="javascript:delWin('/admin/sportsfoot/deleteoutcome?id=');" class="layui-btn layui-btn-sm  layui-btn-danger">删除</a>@endif
                    </div>
                </div>
            </form>
        </div>
    </div>
	
    <script type="text/javascript">
        $(function () {
            $('body').on('click', 'a[eventtype="event-delete"]', function () {
                var span = $(this).prev();
                var id = span.attr('data-id');
                // openWin('/admin/system/AddMenu','{{ trans("menu.menu_edit")}}','600px','500px',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');
            	}
            })
        })
		
		function addResult($match_id){
			$(":input",$("#myModal")).each(function(i){  $(this).val('');});
            var match_id = $match_id;//alert(match_id);
            document.getElementById("matchid").value=$match_id;//赋值个弹窗
            
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/Matchresult',
                data: {match_id:match_id},
                success: function(data) {
                    document.getElementById("firstscore").value=data.newapp.first_score;
                    document.getElementById("lastscore").value=data.newapp.last_score;
                    document.getElementById("matchwiner").value=data.newapp.match_winer;
                    document.getElementById("homeallcard").value=data.penalty_card.home;
                    document.getElementById("guestallcard").value=data.penalty_card.guest;
                    document.getElementById("homehalfcard").value=data.penalty_card.home_half;
                    document.getElementById("guesthalfcard").value=data.penalty_card.guest_half;
                    document.getElementById("homeallcorner").value=data.corner_ball.home;
                    document.getElementById("guestallcorner").value=data.corner_ball.guest;
                    document.getElementById("homehalfcorner").value=data.corner_ball.home_half;
                    document.getElementById("guesthalfcorner").value=data.corner_ball.guest_half;
                }
            }) 

            //获取弹窗得div
            var modal = document.getElementById('myModal');
            // 获取 <span> 元素，用于关闭弹窗 （X）
            var span = document.getElementsByClassName("close")[0];
            //获取弹窗中得确定按钮
            var ok=document.getElementsByClassName("ok")[0];
            //获取弹窗中得取消按钮
            var no=document.getElementsByClassName("no")[0];
            //窗体弹出
            modal.style.display = "block";
            //点击窗体ok
            ok.onclick=function(){
                //执行弹出窗体得确定后得操作
                alert("执行确定按钮点击得操作");
                //关闭窗口
                modal.style.display = "none";
                buttonClick();
            }
            //点击窗体取消按钮
            no.onclick=function(){
                //直接关闭窗口
                modal.style.display = "none";
            }
            // 点击 <span> (x), 关闭弹窗
            span.onclick = function() {
                //直接关闭窗口
                modal.style.display = "none";
            }
            // 在用户点击其他地方时，关闭弹窗
            window.onclick = function(event) {
                //点击窗口外内容，关闭窗口
                if (event.target == modal) modal.style.display = "none";
            }
        }
		
		function requests(match_id){
			$.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/Matchresult',
                data: {match_id:match_id},
                success: function(data) {
					return data;
                }
            })
		}
		
        function buttonClick(){
            var matchid = $("#matchid").val();
            var firstscore = $("#firstscore").val();
            var lastscore = $("#lastscore").val();
            var matchwiner = $("#matchwiner").val();
            var homeallcard = $("#homeallcard").val();
            var guestallcard = $("#guestallcard").val();
            var homehalfcard = $("#homehalfcard").val();
            var guesthalfcard = $("#guesthalfcard").val();
            var homeallcorner = $("#homeallcorner").val();
            var guestallcorner = $("#guestallcorner").val();
            var homehalfcorner = $("#homehalfcorner").val();
            var guesthalfcorner = $("#guesthalfcorner").val();
			
			requests = requests(matchid);
			alert(requests);
			
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/addend',
                data: {matchid:matchid,firstscore:firstscore,lastscore:lastscore,matchwiner:matchwiner,homeallcard:homeallcard,guestallcard:guestallcard,homehalfcard:homehalfcard,guesthalfcard:guesthalfcard,homeallcorner:homeallcorner,guestallcorner:guestallcorner,homehalfcorner:homehalfcorner,guesthalfcorner:guesthalfcorner},
                success: function(data) {
                    
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }


        //刷新赛事数据
        function refreshall(game_code){ 
            var game_code = game_code;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/setSports',
                data: {game_code:game_code},
                success: function(data) {
                    var data = JSON.stringify(data);
                    if(data){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }

        //撤销
        function revoke(match_id){
            var match_id = match_id;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/revoke',
                data: {match_id:match_id},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }

        //上半场主队
        function inputFunc(id,num,match_id){
            var id = id;
            var num = num;
            var reg = /^[0-99]\d*$/;
            var home_score = $("#home_score"+id).val();
            if(reg.test(num)==false){ 
                layer.msg('不能为空值');
                reloadDataTable();return;
            } 
            if(num>home_score){
                layer.msg('请输入正确的全场比分');
                reloadDataTable();return;
            }

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/updatenum',
                data: {id:id,num:num,type:1,match_id:match_id},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }
        //上半场客队
        function inputTunc(id,num,match_id){
           var id = id;
            var num = num;
            var reg = /^[0-99]\d*$/;
            var guest_score = $("#guest_score"+id).val();
            if(reg.test(num)==false){ 
                layer.msg('不能为空值');
                reloadDataTable();return;
            }else if(num>guest_score){
                layer.msg('请输入正确的全场比分');
                reloadDataTable();return;
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/updatenum',
                data: {id:id,num:num,type:2,match_id:match_id},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }
        //全场主队
        function inputSunc(id,num,match_id){
            var id = id;
            var num = num;
            var u_home_score = $("#u_home_score"+id).val();
            if(u_home_score>num){ 
                layer.msg('请输入正确的全场比分');
                reloadDataTable();return;
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/updatenum',
                data: {id:id,num:num,type:3,match_id:match_id},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }
        //全场客队
        function inputAunc(id,num,match_id){
            var id = id;
            var num = num;
            var u_guest_score = $("#u_guest_score"+id).val();
            if(u_guest_score>num){ 
                layer.msg('请输入正确的全场比分');
                reloadDataTable();return;
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/updatenum',
                data: {id:id,num:num,type:4,match_id:match_id},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }

        //结算 
        function settlement(match_id,type){
            var match_id = match_id;
            var type = type;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsfoot/Settlement',
                data: {match_id:match_id,type:type},
                success: function(data) {
                    // alert(data);
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }else{
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }

	</script>
@push('dataTableJS')
/*var active = {
    reload: function(){
      //执行重载
      table.reload('{{ $dataId }}', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
            account:$("#form_account").val(),
            register_ip:$('#form_register_ip').val(),
            last_ip:$('#form_last_ip').val(),
            register_url:$('#form_register_url').val(),
            last_url:$('#form_last_url').val(),
            regist_startime:$('#form_regist_startime').val(),
            regist_endtime:$('#form_regist_endtime').val(),
            statuss:$('#form_statuss').val(),
            cash_small:$('#form_cash_small').val(),
            cash_big:$('#form_cash_big').val(),
            sureblur:$('.layui-form-switch').text(),
        }
      });
    }
  };
$('.lay-btn-diy').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });*/

  //重置表单
  $('.reset').on('click',function(){
      $('input').val('');
      $('#form_statuss').val('');
      //var type = $(this).data('type');
      //active[type] ? active[type].call(this) : '';
  });
  //刷新表单
    $('.set').on('click',function(){
    //var type = $(this).data('type');
    //active[type] ? active[type].call(this) : '';
    });

@endpush

    @include('vip.datatable')
@endsection

<!-- 弹窗隐藏区域 -->
    <div id="myModal" class="modal">
            <input type="hidden" id="matchid" name="matchid" value="">
            <div class="modal-content">
                <div class="modal-header">
                    <span class="close">&times;</span>
                    <h2>赛事结果添加</h2>
                </div>
                <div class="modal-body">
                    <p style="text-align:left;color:#5f7788;">请认真填写赛事结果,将会按照改结果结算</p><br>
                    <div style="text-align:left;">
                        <div style="display: flex;">
                            <li>最先进球球队：</li><input type="text" id="firstscore" name="firstscore" value="">
                        </div>
                        <div style="display: flex;">
                            <li>最后进球球队：</li><input type="text" id="lastscore" name="lastscore" value="">
                        </div>
                        <div style="display: flex;">
                            <li> 获 &nbsp;胜&nbsp; 球&nbsp; 队&nbsp;：</li><input type="text" id="matchwiner" name="matchwiner" value="">
                        </div>
                        <div style="display: flex;">
                            <li>主队全场角球：</li><input type="text" id="homeallcorner" name="homeallcorner" value="" autocomplete="off">
                        </div>
                        <div style="display: flex;">
                            <li>客队全场角球：</li><input type="text" id="guestallcorner" name="guestallcorner" value="" autocomplete="off">
                        </div>
                        <div style="display: flex;">
                            <li>主队半场角球：</li><input type="text" id="homehalfcorner" name="homehalfcorner" value="" autocomplete="off">
                        </div>
                        <div style="display: flex;">
                            <li>客队半场角球：</li><input type="text" id="guesthalfcorner" name="guesthalfcorner" value="" autocomplete="off">
                        </div>
                        <div style="display: flex;"> 
                            <li>主队全场罚牌：</li><input type="text" id="homeallcard" name="homeallcard" value="" autocomplete="off">
                        </div>
                        <div style="display: flex;">
                            <li>客队全场罚牌：</li><input type="text" id="guestallcard" name="guestallcard" value="" autocomplete="off">
                        </div>
                        <div style="display: flex;">
                            <li>主队半场罚牌：</li><input type="text" id="homehalfcard" name="homehalfcard" value="" autocomplete="off">
                        </div> 
                        <div style="display: flex;">
                            <li>客队半场罚牌：</li><input type="text" id="guesthalfcard" name="guesthalfcard" value="" autocomplete="off">
                        </div><br>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="ok" onchange="buttonClick()"><h3>确定</h3></button>&nbsp;<button class="no"><h3>取消</h3></button>
                </div>
            </div>
    </div>
