@extends('vip.layouts')
@section('seo_title')
    篮球赛事
@endsection
@section('content')
    <style>
        .layui-laydate-range {
            width: auto;
        }

        .layui-form-switch em {
            width: auto;
        }

        .layui-form-switch {
            width: 44px;
            line-height: 23px;
        }

        .layui-form-item .checkbox {
            width: auto;
        }
    </style>

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

    <script type="text/html" id="matchstatus">
      @{{#if(d.status==0){ }}
        <span>未开始</span>
      @{{#} }}<br>
      @{{#if(d.status==1){ }}
        <span>进行中</span>
      @{{#} }}
      @{{#if(d.status==2){ }}
        <span>已结束</span>
      @{{#} }}
    </script>
    
    <script type="text/html" id="sectionone_two">
        <input type="text" style="width:30px;heigth:20px" id="okteamscore@{{d.match_id}}" name="okteamscore" value="@{{d.okteamscore}}" onchange="teamscore(1, event.target.value,@{{ d.match_id}})"> 
        <input type="text" style="width:30px;heigth:20px" id="ozteamscore@{{d.match_id}}" name="ozteamscore" value="@{{d.ozteamscore}}" onchange="teamscore(2, event.target.value,@{{ d.match_id}})"> / 
        <input type="text" style="width:30px;heigth:20px" id="tkteamscore@{{d.match_id}}" name="tkteamscore" value="@{{d.tkteamscore}}" onchange="teamscore(3, event.target.value,@{{ d.match_id}})">
        <input type="text" style="width:30px;heigth:20px" id="tzteamscore@{{d.match_id}}" name="tzteamscore" value="@{{d.tzteamscore}}" onchange="teamscore(4, event.target.value,@{{ d.match_id}})">
    </script>

    <script type="text/html" id="sectionthere_four">
        <input type="text" style="width:30px;heigth:20px" id="skteamscore@{{d.match_id}}" name="skteamscore" value="@{{d.skteamscore}}" onchange="teamscore(5, event.target.value,@{{ d.match_id}})"> 
        <input type="text" style="width:30px;heigth:20px" id="szteamscore@{{d.match_id}}" name="szteamscore" value="@{{d.szteamscore}}" onchange="teamscore(6, event.target.value,@{{ d.match_id}})"> / 
        <input type="text" style="width:30px;heigth:20px" id="akteamscore@{{d.match_id}}" name="akteamscore" value="@{{d.akteamscore}}" onchange="teamscore(7, event.target.value,@{{ d.match_id}})">
        <input type="text" style="width:30px;heigth:20px" id="azteamscore@{{d.match_id}}" name="azteamscore" value="@{{d.azteamscore}}" onchange="teamscore(8, event.target.value,@{{ d.match_id}})">
    </script>

    <script type="text/html" id="status">
        @if(checkRriv('/admin/sportsbk/index'))<input type="checkbox" name="status" 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('sportsbk.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('sportsbk.status') }}</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <select name="status"  id="form_status"  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>
                                <option value="-1">{{ trans('sportsbk.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('sportsbk.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('sportsbk.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">
                        <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('lq')">刷新赛事</i></a>
                        <!-- @if(checkRriv('/admin/sportsbk/addoutcome'))<a href="/admin/sportsbk/addoutcome" class="layui-btn layui-btn-sm ">添加</a>@endif -->
                        @if(checkRriv('/admin/sportsbk/deleteoutcome'))<a href="javascript:delWin('/admin/sportsbk/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){
            var match_id = $match_id;
            document.getElementById("match_id").value=$match_id;//赋值个弹窗
            $(":input").val("");
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbk/Matchresult',
                data: {match_id:match_id},
                success: function(data) {

                    if(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("uhomescore").value=data.newapp.u_home_score;
                    document.getElementById("uguestscore").value=data.newapp.u_guest_score;
                    document.getElementById("homeallcard").value=data.corner_ball.home;
                    document.getElementById("guestallcard").value=data.corner_ball.guest;
                    document.getElementById("homehalfcard").value=data.corner_ball.home_half;
                    document.getElementById("guesthalfcard").value=data.corner_ball.guest_half;
                    document.getElementById("homeallcorner").value=data.penalty_card.home;
                    document.getElementById("guestallcorner").value=data.penalty_card.guest;
                    document.getElementById("homehalfcorner").value=data.penalty_card.home_half;
                    document.getElementById("guesthalfcorner").value=data.penalty_card.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 buttonClick(){
            var match_id = $("#match_id").val();
            var firstscore = $("#firstscore").val();
            var lastscore = $("#lastscore").val();
            var matchwiner = $("#matchwiner").val();
            var uhomescore = $("#uhomescore").val();
            var uguestscore = $("#uguestscore").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();

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbk/addend',
                data: {match_id:match_id,firstscore:firstscore,lastscore:lastscore,matchwiner:matchwiner,uhomescore:uhomescore,uguestscore:uguestscore,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 lqrevoke(match_id){
            var match_id = match_id;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbk/revoke',
                data: {match_id:match_id},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }

        //篮球结算 
        function lqsettlement(match_id,type){
            var match_id = match_id;
            var type = type;
            alert(match_id);
            alert(type);
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbk/Settlementlq',
                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()//刷新当前页面
                    }
                }
            })
        }

        //修改赛事比分  only:唯一 num:inputval match_id:match_id
        function teamscore(only,num,match_id){
            var only = only;
            var num = num;
            var match_id = match_id;
            var reg = /^[0-99]\d*$/;
            var okteamscore = $("#okteamscore"+match_id).val();
            var ozteamscore = $("#ozteamscore"+match_id).val();
            var tkteamscore = $("#tkteamscore"+match_id).val();
            var tzteamscore = $("#tzteamscore"+match_id).val();
            var skteamscore = $("#skteamscore"+match_id).val();
            var szteamscore = $("#szteamscore"+match_id).val();
            var akteamscore = $("#akteamscore"+match_id).val();
            var azteamscore = $("#azteamscore"+match_id).val();
            // alert(azteamscore);
            // alert(akteamscore);

            if(reg.test(num)==false){ 
                layer.msg('不能为空值');
                reloadDataTable();return;
            }

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbk/updatascore',
                data: {only:only,num:num,match_id:match_id,okteamscore:okteamscore,ozteamscore:ozteamscore,tkteamscore:tkteamscore,tzteamscore:tzteamscore,skteamscore:skteamscore,szteamscore:szteamscore,akteamscore:akteamscore,azteamscore:azteamscore},
                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) {
                    
                    if(data.status==1){
                        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
