@extends('vip.layouts')
@section('seo_title')
    棒球赛事
@endsection
@section('content')
    <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="match_score">
            <input type="text" style="width:30px;heigth:20px" id="u_home_score@{{d.match_id}}" name="u_home_score" value="@{{d.u_home_score}}"> 
            <input type="text" style="width:30px;heigth:20px" id="u_guest_score@{{d.match_id}}" name="u_guest_score" value="@{{d.u_guest_score}}"> / 
            <input type="text" style="width:30px;heigth:20px" id="home_score@{{d.match_id}}" name="home_score" value="@{{d.home_score}}">
            <input type="text" style="width:30px;heigth:20px" id="guest_score@{{d.match_id}}" name="guest_score" value="@{{d.guest_score}}">
            <button class="layui-icon" onclick="teamscore(@{{d.match_id}})"><h6>提交</h6></button>
    </script>

    <script type="text/html" id="dsnum">
        <span><a href="/admin/SoccerNoteList/notelist?type=bq&match_id=@{{d.match_id}}"> 单式</a></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="operation">
        <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>
        @{{#} }}
        <button onclick="resultLog(@{{d.match_id}})" class="layui-btn layui-btn-sm layui-btn-green set">赛事结果比分记录</button>
    </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" placeholder="输入赛事id,主队,客队名">
                        </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_operation.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.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('bq')">刷新赛事</i></a>
                        <!--@if(checkRriv('/admin/sportsbk/addoutcome'))<a href="/admin/sportsbk/addoutcome" class="layui-btn layui-btn-sm ">添加</a>@endif-->
                        @if(checkRriv('/admin/sportsbq/deleteoutcome'))<a href="javascript:delWin('/admin/sportsbq/deleteoutcome?id=');" class="layui-btn layui-btn-sm  layui-btn-danger">删除</a>@endif
                        @if(checkRriv('/admin/sportsbq/Settlementlq'))<a href="javascript:allbalance('/admin/sportsbq/Settlementlq?allhalf=1&id=');" class="layui-btn layui-btn-sm layui-btn-green set">结算全场</a>@endif
                        @if(checkRriv('/admin/sportsbq/Settlementlq'))<a href="javascript:allbalance('/admin/sportsbq/Settlementlq?allhalf=2&id=');" class="layui-btn layui-btn-xs">结算上半场</a>@endif
                        @if(checkRriv('/admin/sportsbq/Settlementlq'))<a href="javascript:allbalance('/admin/sportsbq/Settlementlq?allhalf=2&id=');" class="layui-btn layui-btn-sm layui-btn-green set">重新结算上半场</a>@endif
                    </div>
                </div>
            </form>
        </div>
    </div>

    <style>

        .layui-btn{
             margin: 1px 0px;
         }
        .log_title{

        }

        .log_head_div{
            font-size: 17px;
            margin-bottom: 5px;
        }
        .log_content_div td{
            padding: 5px;
            border: 1px solid #888888;
        }

        hr{
            margin: 14px 0;
        }
    </style>
	<script>
        $(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');
            	}
            })
        })

        //layer弹窗开始
        let conttxt = '';
        let layerOpen = '';
        function addResult(match_id){
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbq/Matchresult',
                data: {match_id:match_id},
                success: function(data) {
                    conttxt ='<div style="margin-left:80px;margin-top:20px;font-size:18px;line-height:150%;"><input type="hidden" id="match_id" name="match_id" value="'+match_id+'" /><div style="display: flex;"><li>第一局比分(主/客)：</li><input style="width:50px;" type="text" id="homea" name="homea" value="'+data.bqresult[1]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guesta" name="guesta" value="'+data.bqresult[1]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第二局比分(主/客)：</li><input style="width:50px;" type="text" id="homeb" name="homeb" value="'+data.bqresult[2]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guestb" name="guestb" value="'+data.bqresult[2]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第三局比分(主/客)：</li><input style="width:50px;" type="text" id="homec" name="homec" value="'+data.bqresult[3]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guestc" name="guestc" value="'+data.bqresult[3]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第四局比分(主/客)：</li><input style="width:50px;" type="text" id="homed" name="homed" value="'+data.bqresult[4]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guestd" name="guestd" value="'+data.bqresult[4]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第五局比分(主/客)：</li><input style="width:50px;" type="text" id="homee" name="homee" value="'+data.bqresult[5]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="gueste" name="gueste" value="'+data.bqresult[5]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第六局比分(主/客)：</li><input style="width:50px;" type="text" id="homef" name="homef" value="'+data.bqresult[6]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guestf" name="guestf" value="'+data.bqresult[6]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第七局比分(主/客)：</li><input style="width:50px;" type="text" id="homeg" name="homeg" value="'+data.bqresult[7]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guestg" name="guestg" value="'+data.bqresult[7]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第八局比分(主/客)：</li><input style="width:50px;" type="text" id="homeh" name="homeh" value="'+data.bqresult[8]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guesth" name="guesth" value="'+data.bqresult[8]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第九局比分(主/客)：</li><input style="width:50px;" type="text" id="homei" name="homei" value="'+data.bqresult[9]['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guesti" name="guesti" value="'+data.bqresult[9]['guest']+'" autocomplete="off"></div><div style="display: flex;"><li>第十局比分(主/客)：</li><input style="width:50px;" type="text" id="homej" name="homej" value="'+data.bqresult['other']['home']+'" autocomplete="off">&nbsp;/&nbsp;<input style="width:50px;" type="text" id="guestj" name="guestj" value="'+data.bqresult['other']['guest']+'" autocomplete="off"></div>';
                    
                    conttxt += '<br><div style="margin-left:230px;"><button class="layui-btn layui-btn-sm layui-btn-green set" id="buttonClick" onclick="buttonClick()"><h3>确定</h3></button>&nbsp;<button onclick="czClick()" class="layui-btn layui-btn-sm layui-btn-danger" id="reset"><h3>取消</h3></button></div></div>';
                
                layerOpen = layer.open({
                  type: 1 //Page层类型
                  ,area: ['500px', '400px']
                  ,title: '<h2>赛事结果添加<h2>'
                  ,shade: 0.6 //遮罩透明度
                  ,maxmin: true //允许全屏最小化
                  ,anim: 1 //0-6的动画形式，-1不开启
                  ,content:conttxt
                }); 
                }
            }) 
        }
        function czClick() {
            layer.close(layerOpen)
        }
        //layer弹窗结束
        
        function buttonClick(){
             $("#buttonClick").attr('disabled', true);

            var match_id = $("#match_id").val();
            var homea = $("#homea").val();
            var guesta = $("#guesta").val();
            var homeb = $("#homeb").val();
            var guestb = $("#guestb").val();
            var homec = $("#homec").val();
            var guestc = $("#guestc").val();
            var homed = $("#homed").val();
            var guestd = $("#guestd").val();
            var homee = $("#homee").val();
            var gueste = $("#gueste").val();
            var homef = $("#homef").val();
            var guestf = $("#guestf").val();
            var homeg = $("#homeg").val();
            var guestg = $("#guestg").val();
            var homeh = $("#homeh").val();
            var guesth = $("#guesth").val();
            var homei = $("#homei").val();
            var guesti = $("#guesti").val();
            var homej = $("#homej").val();
            var guestj = $("#guestj").val();

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbq/addend',
                data: {match_id:match_id,homea:homea,guesta:guesta,homeb:homeb,guestb:guestb,homec:homec,guestc:guestc,homed:homed,guestd:guestd,homee:homee,gueste:gueste,homef:homef,guestf:guestf,homeg:homeg,guestg:guestg,homeh:homeh,guesth:guesth,homei:homei,guesti:guesti,homej:homej,guestj:guestj},
                success: function(data) {
                    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/Sportsbq/revoke',
                data: {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/Sportsbq/Settlement',
                data: {match_id:match_id,type:type},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }else if(data.status==2){
                        layer.msg(data.msg);
                        reloadDataTable();return;
                    }else if(data.status==4){
                        layer.msg(data.msg);
                        reloadDataTable();return;
                    }else{
                        layer.msg(data.msg);
                        reloadDataTable();return;
                    }
                }
            })
        }

        //修改赛事比分  only:唯一 num:inputval match_id:match_id
        function teamscore(match_id){
            var match_id = match_id;
            var u_home_score = document.getElementById("u_home_score"+match_id).value;
            var u_guest_score = document.getElementById("u_guest_score"+match_id).value;
            var home_score = document.getElementById("home_score"+match_id).value;
            var guest_score = document.getElementById("guest_score"+match_id).value;
            // var reg = /^[0-99]\d*$/;

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

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbq/updatascore',
                data: {match_id:match_id,u_home_score:u_home_score,u_guest_score:u_guest_score,home_score:home_score,guest_score:guest_score},
                success: function(data) {
                    if(data.status==1){
                        layer.msg(data.msg);
                        location. reload()//刷新当前页面
                    }
                }
            })
        }

        //layer弹窗开始
        let resultLogOpen = '';
        function resultLog(match_id){
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/Sportsbq/resultLog',
                data: {match_id:match_id},
                success: function(data) {
                    let length = data.list.length;
                    if(length <= 0){
                        layer.alert('该赛事还没有赛事结果比分记录');
                        return false;
                    }

                    let html = '';
                    let info = '';
                    for(let i=0; i<length; i++){
                        info = data['list'][i];
                        if(info.type == 1){ //结果

                            html +='<div style="margin-left: 20px;"><div class="log_head_div"><span class="log_title">修改人</span>：'+info['loginname']+'&nbsp;&nbsp;&nbsp;<span class="log_title">添加时间：</span>'+info['create_at']+'&nbsp;&nbsp;&nbsp;<span class="log_title">添加类型</span>：赛事结果</div>'
                                    +'<div class="log_content_div"><table><tr>' +
                                '<td>第一局比分(主/客)</td>' +
                                '<td>第二局比分(主/客)</td>' +
                                '<td>第三局比分(主/客)</td>' +
                                '<td>第四局比分(主/客)</td>' +
                                '<td>第五局比分(主/客)</td>' +
                                '<td>第六局比分(主/客)</td>' +
                                '<td>第七局比分(主/客)</td>' +
                                '<td>第八局比分(主/客)</td>' +
                                '<td>第九局比分(主/客)</td>' +
                                '<td>第十局比分(主/客)</td>' +
                                '</tr><tr>' +
                                '<td>'+info['match_score_t'][1]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][1]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][2]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][2]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][3]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][3]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][4]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][4]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][5]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][5]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][6]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][6]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][7]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][7]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][8]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][8]['guest']+'</td>' +
                                '<td>'+info['match_score_t'][9]['home']+'&nbsp;/&nbsp;'+info['match_score_t'][9]['guest']+'</td>' +
                                '<td>'+info['match_score_t']['other']['home']+'&nbsp;/&nbsp;'+info['match_score_t']['other']['guest']+'</td>' +
                                '</tr></table></div></div><hr>';
                        }else{ //比分
                            html +='<div style="margin-left: 20px"><div class="log_head_div"><span class="log_title">修改人</span>：'+info['loginname']+'&nbsp;&nbsp;&nbsp;<span class="log_title">添加时间：</span>'+info['create_at']+'&nbsp;&nbsp;&nbsp;<span class="log_title">添加类型</span>：赛事比分</div>'
                                    +'<div>上半场比分(主/客)：'+info['u_home_score']+'&nbsp;/&nbsp;'+info['u_guest_score']+'</div>'
                                    +'<div>整场比分(主/客)：'+info['home_score']+'&nbsp;/&nbsp;'+info['guest_score']+'</div></div><hr>';
                        }
                    }

                    html += '<br><div style="margin:0px auto 10px;width: 112px;"><button class="layui-btn layui-btn-sm layui-btn-green set" id="buttonClick" onclick="rlClick()"><h3>确定</h3></button>&nbsp;<button onclick="rlClick()" class="layui-btn layui-btn-sm layui-btn-danger" id="reset"><h3>取消</h3></button></div></div>';

                    resultLogOpen = layer.open({
                        type: 1 //Page层类型
                        ,area: ['900px', '500px']
                        ,title: '<h2>赛事结果比分记录<h2>'
                        ,shade: 0.6 //遮罩透明度
                        ,maxmin: true //允许全屏最小化
                        ,anim: 1 //0-6的动画形式，-1不开启
                        ,content:html
                    });
                }
            })
        }

        function rlClick() {
            layer.close(resultLogOpen)
        }

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

