@extends('vip.layouts')
@section('seo_title')
    足球单式注单管理
@endsection
@section('content')

    <script type="text/html" id="game_status">
        <!--
        @{{#if(d.is_champion==1){ }}
            <a href="/admin/SoccerNoteList/orderupgj?id=@{{d.lg_id}}&order=@{{d.order_id}}" class="layui-btn layui-btn-sm layui-btn-green set">修改结果</a>
        @{{#}else{ }}
            <button onclick="addResult('@{{d.id}}','{{$type}}')" class="layui-btn layui-btn-sm layui-btn-green set">修改结果</button>
        @{{#} }}
        -->

        <!--<button style="margin-left: 0;" onclick="setScore('@{{d.order_id}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">手动设置比分</button>-->
        <button style="margin-left: 0;" onclick="setScore_v2('@{{d.order_id}}','@{{d.match_id}}','@{{d.game_code}}')"  class="layui-btn layui-btn-sm settlement">手动设置比分</button>

        @{{#if(d.settle_status==1){ }}
            <span>未结算</span>
        @{{#} }}<br>
        @{{#if(d.settle_status==2){ }}
            <span>已结算</span>
        @{{#} }}


        <!--
        @{{#if(d.status==2 || d.status==3 || d.status==5){ }}
            <button onclick="resettlement('@{{d.order_id}}','{{$type}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">再1结算</button>
        @{{#} }}
        @{{#if(d.status==1){ }}
            <button onclick="resettlement('@{{d.order_id}}','{{$type}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">结算</button>
        @{{#} }}

        @{{#if(d.status==2 || d.status==3 || d.status==5){ }}
            <button onclick="resettlement('@{{d.order_id}}','{{$type}}','@{{d.match_id}}')" class="layui-btn layui-btn-sm settlement">再1结算</button>
        @{{#} }}
        -->

    </script>

    <script type="text/html" id="status">
        @if(checkRriv('/admin/SportsSoccer/score'))<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="" method="get">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsnotelist.notelist_type') }}</label>
                        <div class="layui-input-inline" style="">
                            <select name="type"  id="form_type"  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>
                                <option value="-1"></option>
                                @foreach(trans('status.notelist_type.type') as $k=>$v):
                                @if($type==$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('sportsnotelist.account') }}</label>
                        <div class="layui-input-inline" style="">
                            <input type="text" name="account" id="account" eventType="event-query"  value="{{ $account }}" 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('sportsnotelist.date') }}</label>
                        <div class="layui-input-inline" style="">
                            <input type="text" name="star_time" value="{{ $star_time }}" id="form_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('sportsnotelist.end_time') }}</label>--}}
                        <div class="layui-input-inline" style="">
                            <input type="text" name="end_time" value="{{ $end_time }}" id="end_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('sportsnotelist.order_id') }}</label>
                        <div class="layui-input-inline" style="">
                            <input type="text" name="order_id" id="order_id" eventType="event-query"  value="{{ $order_id }}" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsnotelist.match_id') }}</label>
                        <div class="layui-input-inline" style="">
                            <input type="text" name="match_id" id="match_id" eventType="event-query"  value="{{ $match_id }}" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <!--
                    <div class="layui-inline">
                        <label class="layui-form-label">{{ trans('sportsnotelist.ifsettlement') }}</label>
                        <div class="layui-input-inline" style="">
                            <select name="status"  id="form_status"  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>
                                <option value="-1"></option>
                                @foreach(trans('status.ifsettlement.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('sportsnotelist.order_status') }}</label>
                        <div class="layui-input-inline" style="">
                            <select name="order_status"  id="form_order_status"  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>
                                <option value="-1"></option>
                                @foreach(trans('status.order_status.status') as $k=>$v):
                                @if($order_status==$k))
                                <option value="{{$k}}" selected="selected">{{$v}}</option>
                                @else
                                    <option value="{{$k}}">{{$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>
                        {{--@if(checkRriv('/admin/SoccerNoteList/batchsettlement'))<a href="javascript:batchsettlement('/admin/SoccerNoteList/batchsettlement');" class="layui-btn layui-btn-sm  layui-btn-danger">批量结算</a>@endif--}}

                        <a class="layui-btn layui-btn-sm layui-btn-green set" data-type="reload" style="opacity: 1; pointer-events: auto;" href="javascript:window.location.reload()"><i class="layui-icon">ဂ</i></a>

                        {{--@if(checkRriv('/admin/SportsSoccer/add'))<a href="/admin/SportsSoccer/add" class="layui-btn layui-btn-sm ">添加</a>@endif--}}
                        {{--@if(checkRriv('/admin/SoccerNoteList/orderstatus'))<a href="/admin/SoccerNoteList/orderstatus" class="layui-btn layui-btn-sm ">订单状态审核</a>@endif--}}
                        @if(checkRriv('/admin/SoccerNoteList/delete'))<a href="javascript:delWin('/admin/SoccerNoteList/delete?id=');" class="layui-btn layui-btn-sm  layui-btn-danger">删除</a>@endif
                    </div>

                    <!-- &nbsp;&nbsp;&nbsp;&nbsp;<div class="layui-inline"><a href="javascript:openWin('/admin/user/infoAdd','{{ trans('menu.menu_add') }}','700px','500px')" class="layui-btn layui-btn-sm  ">添加</a></div>
                    <div class="layui-inline"><a href="/admin/menu/add" class="layui-btn layui-btn-sm  layui-btn-danger">删除</a></div> -->

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

    <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');
                }
            })
        })

        let conttxt = '';
        let layerOpen = '';
        function addResult($id,$qlgame){
            var did = $id;
            var qlgame = 1;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/SoccerNoteList/addend',
                data: {did:did,qlgame:qlgame},
                success: function(data) {
                    conttxt = '<div style="margin-left:100px;margin-top:20px;font-size:18px;line-height:150%;"><input type="hidden" id="did" name="did" value="'+did+'" /><div style="display: flex;"><li>主队全场进球：</li><input type="text" id="home_score" name="home_score" value="'+data[0].home_score+'" autocomplete="off"></div><div style="display: flex;"><li>客队全场进球：</li><input type="text" id="guest_score" name="guest_score" value="'+data[0].guest_score+'" autocomplete="off"></div><div style="display: flex;"><li>主队半场进球：</li><input type="text" id="u_guest_score" name="u_guest_score" value="'+data[0].u_guest_score+'" autocomplete="off"></div><div style="display: flex;"><li>客队半场进球：</li><input type="text" id="u_home_score" name="u_home_score" value="'+data[0].u_home_score+'" autocomplete="off"></div><div style="display: flex;"><li>主队全场角球：</li><input type="text" id="homeallcorner" name="homeallcorner" value="'+data[0].corner_ball.home+'" autocomplete="off"></div><div style="display: flex;"><li>客队全场角球：</li><input type="text" id="guestallcorner" name="guestallcorner" value="'+data[0].corner_ball.guest+'" autocomplete="off"></div><div style="display: flex;"><li>主队半场角球：</li><input type="text" id="homehalfcorner" name="homehalfcorner" value="'+data[0].corner_ball.home_half+'" autocomplete="off"></div><div style="display: flex;"><li>客队半场角球：</li><input type="text" id="guesthalfcorner" name="guesthalfcorner" value="'+data[0].corner_ball.guest_half+'" autocomplete="off"></div><div style="display: flex;"><li>主队全场罚牌：</li><input type="text" id="homeallcard" name="homeallcard" value="'+data[0].penalty_card.home+'" autocomplete="off"></div><div style="display: flex;"><li>客队全场罚牌：</li><input type="text" id="guestallcard" name="guestallcard" value="'+data[0].penalty_card.guest+'" autocomplete="off"></div><div style="display: flex;"><li>主队半场罚牌：</li><input type="text" id="homehalfcard" name="homehalfcard" value="'+data[0].penalty_card.home_half+'" autocomplete="off"></div> <div style="display: flex;"><li>客队半场罚牌：</li><input type="text" id="guesthalfcard" name="guesthalfcard" value="'+data[0].penalty_card.guest_half+'" autocomplete="off"></div>';

                    if(data[0].home_score>0 || data[0].guest_score>0){
                        conttxt += '<div style="display: flex;"><li>最后胜利球队：</li><input type="text" id="matchwiner" name="matchwiner" value="'+data[0].match_winer+'" autocomplete="off"></div><div style="display: flex;"><li>首 进 球 时 间：</li><input type="text" id="onescoretime" name="onescoretime" value="'+data[0].first_score.scoretime+'" autocomplete="off"></div><div style="display: flex;"><li>最先进球球队：</li><select name="firstscore" id="firstscore">';
                        if(data[0].first_score.teamscore.length>0){
                            conttxt += '<option value="'+ data[0].first_score.teamscore +'" selected="">'+ data[0].first_score.teamscore +'</option><option value="">无任何进球</option>';
                        }else{
                            conttxt += '<option value="">请选择最先进球</option>';
                        }
                        conttxt += '<option value="'+data[0].home_team+'">'+data[0].home_team+'</option><option value="'+data[0].guest_team+'">'+data[0].guest_team+'</option></select></div>';

                        conttxt += '<div style="display: flex;"><li>首 进 球 方 式：</li><select name="firststye" id="firststye">';
                        if(data[0].first_score.scoretype.length>0){
                            conttxt += '<option value="'+ data[0].first_score.scoretype +'" selected="">'+ data[0].first_score.scoretype +'</option><option value="">无任何进球</option>';
                        }else{
                            conttxt += '<option value="">请选择首进球方式</option>';
                        }
                        conttxt += '<option value="射门">射门</option><option value="头球">头球</option><option value="点球">点球</option><option value="任意球">任意球</option><option value="乌龙球">乌龙球</option></select></div>';

                        conttxt += '<div style="display: flex;"><li>最后进球球队：</li><select name="lastscore" id="lastscore">';
                        if(data[0].last_score.length>0){
                            conttxt += '<option value="'+ data[0].last_score +'" selected="">'+ data[0].last_score +'</option><option value="">无任何进球</option>';
                        }else{
                            conttxt += '<option value="">请选择最后进球</option>';
                        }
                        conttxt += '<option value="'+data[0].home_team+'">'+data[0].home_team+'</option><option value="'+data[0].guest_team+'">'+data[0].guest_team+'</option></select></div>';
                    }

                    conttxt += '<br><div style="margin-left:230px;"><button class="layui-btn layui-btn-sm layui-btn-green set" onclick="buttonClick()"><h3>确定</h3></button>&nbsp;<button onclick="czClick()" class="layui-btn layui-btn-sm layui-btn-danger"><h3>取消</h3></button></div></div>';

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

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

        function buttonClick(){
            var did = $("#did").val();
            var qlgame = 2;
            var firstscore = $("#firstscore").val();
            var onescoretime = $("#onescoretime").val();
            var firststye = $("#firststye").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();
            var home_score = $("#home_score").val();//主队得分
            var guest_score = $("#guest_score").val();//客队得分
            var u_guest_score = $("#u_guest_score").val();// 上半场客队得分
            var u_home_score = $("#u_home_score").val();//上半场主队得分

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/SoccerNoteList/addend',
                data: {did:did,firstscore:firstscore,onescoretime:onescoretime,firststye:firststye,lastscore:lastscore,matchwiner:matchwiner,homeallcard:homeallcard,guestallcard:guestallcard,homehalfcard:homehalfcard,guesthalfcard:guesthalfcard,homeallcorner:homeallcorner,guestallcorner:guestallcorner,homehalfcorner:homehalfcorner,guesthalfcorner:guesthalfcorner,home_score:home_score,guest_score:guest_score,u_guest_score:u_guest_score,u_home_score:u_home_score},
                success: function(data) {
                    layer.msg(data.msg);
                    location. reload()//刷新当前页面
                }
            })

        }


    </script>
    @push('dataTableJS')
        /*var active = {
            reload: function(){
                //执行重载
                console.log($('#form_status').val());
                table.reload('{{ $dataId }}', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        account_name:$("#form_account_name").val(),
                        order_id:$('#form_order_id').val(),
                        bank_user:$('#form_bank_user').val(),
                        money_small:$('#form_money_small').val(),
                        money_big:$('#form_money_big').val(),
                        status:$('#form_status').val(),
                        apply_startime:$('#form_apply_startime').val(),
                        apply_endtime:$('#form_apply_endtime').val(),
                        haddle_startime:$('#form_haddle_startime').val(),
                        haddle_endtime:$('#form_haddle_endtime').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_status').val('3');
    $('.layui-form-select input').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) : '';
    });


    function dataTableLoadFinished(res,curr,count){
    var str='';
    //console.log(res);
    if(document.getElementById("statistics")){

    }else{
    $('.layui-table-page').after('<div id="statistics"></div>');
    }
    $.ajax({
    type: 'get',
    url: '/admin/SoccerNoteList/moneycount',
    data: {where:res.extras},
    dataType: 'json',
    //async: false,
    success: function (data) {
    var data=data.data;
    for(var i in data){
    data[i]=parseFloat(data[i]);
    }
    str+='<p class="bottom-txt">总投注金额：<span class="blue">'+data.all_money+'</span> , 总可赢金额：<span class="red">'+data.all_prize_money+'</span> , 已赢金额：<span class="green">'+data.alraedy_prize_money+'</span></p>'
    {{--str+='<p class="bottom-txt">总金额：<span class="blue">'+data.all_money+'</span> , 成功：<span class="green">'+data.success_money+'</span> , 手续费：<span class="red">'+data.service_money+'</span> , 处理中：<span class="yellow">'+data.handing+'</span></p>'--}}
    $('#statistics').html(str);
    var height1=$('.layui-table-view').height();
    var height2=$('#statistics').height();

    $('.layui-table-view').css({height:(height1+height2)});
    }
    });


    }
    @endpush
    <script type="text/javascript">
        //批量结算
        function batchsettlement(url) {
            layer.confirm('是否确认批量结算？', {
                btn: ['确认', '取消'] //按钮
            }, function() {
                $.getJSON(url, function(data, textStatus) {
                    if (data.status == '1') {
                        reloadDataTable();
                        layer.msg('批量结算成功');
                    } else {
                        layer.msg(data.msg);
                    }
                });
            }, function() {

            });

        }
        //单式注单结算
        function settlement(url,ids) {
            layer.confirm('是否确认结算？', {
                btn: ['确认', '取消'] //按钮
            }, function() {
                $.getJSON(url, function(data, textStatus) {
                    //console.log(data);
                    if (data.status == '1') {
                        reloadDataTable();
                        layer.msg('结算成功');
                    } else {
                        layer.msg(data.msg);
                    }
                });
            }, function() {

            });

        }

        function resettlement(order_id,type,match_id) {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/SoccerNoteList/resettlement',
                data: {order_id:order_id,type:type,match_id:match_id},
                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==3){
                        layer.msg(data.msg);
                        reloadDataTable();return;
                    }else{
                        layer.msg(data.msg);
                        reloadDataTable();return;
                    }
                }
            })
        }



        // 设置结算比分
        function setScore_v2(order_id, match_id, game_code) {
            $.getJSON("/admin/SoccerNoteList/manualmatchget_v2", {'order_id': order_id}, function (res) {
                if (1 == res.status) {
                    //console.log(res);
                    switch (game_code) {
                        case 'zq':
                            setScore_v2_zq(res.data.order, res.data.result,order_id, match_id, game_code);
                            break;
                        case 'lq':
                            setScore_v2_lq(res.data.order, res.data.result,order_id, match_id, game_code);
                            break;
                        case 'bq':
                            setScore_v2_bq(res.data.order, res.data.result,order_id, match_id, game_code);
                            break;
                        case 'wq':
                            setScore_v2_wq(res.data.order, res.data.result,order_id, match_id, game_code);
                            break;
                    }
                } else {
                    layer.alert("数据拉取失败!", {title: '友情提示', icon: 2});
                }
            });
        }

        function setScore_v2_zq(orderObj, resultObj,order_id,match_id,game_code) {
            let content = '<div style="width: 100%;height:25px;"></div><div class="layui-form-item">' +
                '  <div class="layui-inline">' +
                '    <label class="layui-form-label" style="width:60px;">进球数:</label>' +
                '    <label class="layui-form-label"  style="width:100px;">上半场[主/客]</label>' +
                '    <div class="layui-input-inline" style="width: 50px;">' +
                '      <input type="text" name="set_zq_home_score" id="set_zq_home_score_u" placeholder="主"  value="' + resultObj.u_home_score +'"  required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 50px;">' +
                '      <input type="text" name="set_zq_guest_score"  id="set_zq_guest_score_u"  placeholder="客"  value="' + resultObj.u_guest_score +'"   required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <label class="layui-form-label"  style="width:100px;">全场[主/客]</label>' +
                '    <div class="layui-input-inline" style="width: 50px;">' +
                '      <input type="text" name="set_zq_home_score" id="set_zq_home_score" placeholder="主"  value="' + resultObj.home_score +'"   required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 50px;">' +
                '      <input type="text" name="set_zq_guest_score"  id="set_zq_guest_score"  placeholder="客"   value="' + resultObj.guest_score +'"     required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '  </div>' +
                '</div>';

            layer.open({
                area: ['700px', '200px'], //宽高
                type: 1,
                title: '设置比分',
                content: content, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响,
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                 matchdata = JSON.stringify({
                            home: $("#set_zq_home_score").val(),
                            guest: $("#set_zq_guest_score").val(),
                            home_u: $("#set_zq_home_score_u").val(),
                            guest_u: $("#set_zq_guest_score_u").val(),
                        });

                    ajax_setScore_all_v2(order_id,game_code,match_id,matchdata);
                    return true;
                },
            });
        }

        function setScore_v2_lq(orderObj, resultObj,order_id,match_id,game_code) {
            let home = JSON.parse(resultObj.home_score);
            let guest = JSON.parse(resultObj.guest_score);

            let content = '<div style="width: 100%;height:25px;"></div><div class="layui-form-item">' +
                '  <div class="layui-inline">' +
                '    <label class="layui-form-label" style="width: 100px;">主队各场球数:</label>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_home_score_1" id="set_lq_home_score_1" value="' + home[1] + '"  required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_home_score_2"  id="set_lq_home_score_2"   value="' + home[2] + '"   required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_home_score_3" id="set_lq_home_score_3"  value="' + home[3] + '"   required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_home_score_4"  id="set_lq_home_score_4"  value="' + home[4] + '"     required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '  </div>' +
                '  <div class="layui-inline">' +
                '    <label class="layui-form-label" style="width: 100px;">客队各场球数:</label>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_gueste_score_1" id="set_lq_gueste_score_1"  value="' + guest[1] + '"  required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_gueste_score_2"  id="set_lq_gueste_score_2"    value="' + guest[2] + '"   required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_gueste_score_3" id="set_lq_gueste_score_3"  value="' + guest[3] + '"   required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '    <div class="layui-input-inline" style="width: 35px;">' +
                '      <input type="text" name="set_lq_gueste_score_4"  id="set_lq_gueste_score_4"   value="' + guest[4] + '"     required   autocomplete="off" class="layui-input">' +
                '    </div>' +
                '  </div>' +
                '</div>';

            layer.open({
                area: ['800px', '200px'], //宽高
                type: 1,
                title: '设置比分',
                content: content, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响,
                btn: ['提交', '取消'],
                yes: function (index, layero) {
                    matchdata = JSON.stringify({
                        'home': [$("#set_lq_home_score_1").val(), $("#set_lq_home_score_2").val(), $("#set_lq_home_score_3").val(), $("#set_lq_home_score_4").val(),],
                        'guest': [$("#set_lq_gueste_score_1").val(), $("#set_lq_gueste_score_2").val(), $("#set_lq_gueste_score_3").val(), $("#set_lq_gueste_score_4").val(),],
                    });

                    // 请求设置接口
                    ajax_setScore_all_v2(order_id,game_code,match_id,matchdata);
                    return true;
                },
            });

            return;
        }


        function setScore_v2_bq(orderObj, resultObj,order_id,match_id,game_code) {
            let match_score = JSON.parse(resultObj.match_score_t);

            let content = '<div style="width: 100%;height:25px;"></div><div class="layui-form-item">' +
                '  <div class="layui-inline">' +
                '    <label class="layui-form-label" style="width: 100px;">主队各局得分:</label>' ;

                 tmp = '' ;
                 for (let i=1;i<=9;i++){
                     tmp +=   '<div class="layui-input-inline" style="width: 30px;">' +
                         '      <input type="text" name="set_bq_home_score_'+i+'" id="set_bq_home_score_'+i+'" value="' + match_score[i]['home'] + '"  required   autocomplete="off" class="layui-input">' +
                         '    </div>';
                     }
                content = content + tmp ;
                content +=  '  </div>' +
                    '  <div class="layui-inline">' +
                    '    <label class="layui-form-label" style="width: 100px;">客队各局得分:</label>' ;
                    tmp = '' ;
                    for (let i=1;i<=9;i++){
                        tmp +=     '    <div class="layui-input-inline" style="width: 30px;">' +
                            '      <input type="text" name="set_bq_gueste_score_'+i+'" id="set_bq_guest_score_'+i+'"  value="' +  + match_score[i]['guest']  + '"  required   autocomplete="off" class="layui-input">' +
                            '    </div>' ;
                    }
                content = content + tmp ;
                content +=  '  </div>' ;
                content +=     '</div>';
                content +=   '  <div class="layui-inline">' +
                    '    <label class="layui-form-label" style="width: 130px;">加试赛得分[主/客]:</label>' +
                    '    <div class="layui-input-inline" style="width: 35px;">' +
                    '      <input type="text" name="set_bq_home_score_ext" id="set_bq_home_score_ext" value="' + match_score['other']['home']  + '"  required   autocomplete="off" class="layui-input">' +
                    '    </div>' +
                    '    <div class="layui-input-inline" style="width: 35px;">' +
                    '      <input type="text" name="set_bq_guest_score_ext"  id="set_bq_guest_score_ext"   value="' + match_score['other']['guest']  + '"   required   autocomplete="off" class="layui-input">' +
                    '    </div>' +
                    '  </div>' ;




            layer.open({
                area: ['800px', '300px'], //宽高
                type: 1,
                title: '设置比分',
                content: content, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响,
                btn: ['提交', '取消'],
                yes: function (index, layero) {

                    let home_scores=[],guest_scores=[],str_home,str_guest,i;
                    for (i=0;i<=8;i++){
                        str_home = '#set_bq_home_score_'+(i+1);
                        str_guest = '#set_bq_guest_score_'+(i+1);
                        home_scores.push($(str_home).val());
                        guest_scores.push($(str_guest).val());
                        //home_scores[i] = $(str_home).val();
                        //guest_scores[i] = $(str_guest).val();
                        //console.log(home_scores[i],guest_scores[i]);
                    }

                    matchdata = JSON.stringify({
                        'home':home_scores,
                        'guest':guest_scores,
                        'home_other':$("#set_bq_home_score_ext").val(),
                        'guest_other':$("#set_bq_guest_score_ext").val(),
                    });

                    // 请求设置接口
                    ajax_setScore_all_v2(order_id,game_code,match_id,matchdata);
                    return true;
                },
            });

            return ;
        }

        function setScore_v2_wq(orderObj, resultObj,order_id,match_id,game_code) {
            let match_score = JSON.parse(resultObj.inning);

            let content = '<div style="width: 100%;height:25px;"></div><div class="layui-form-item">' +
                '  <div class="layui-inline">' +
                '    <label class="layui-form-label" style="width: 100px;">主队各盘得分:</label>' ;

            tmp = '' ;
            for (let i=1;i<=5;i++){
                tmp +=   '<div class="layui-input-inline" style="width: 30px;">' +
                    '      <input type="text" name="set_wq_home_score_'+i+'" id="set_wq_home_score_'+i+'" value="' + match_score[i]['home'] + '"  required   autocomplete="off" class="layui-input">' +
                    '    </div>';
            }
            content = content + tmp ;
            content +=  '  </div>' +
                '  <div class="layui-inline">' +
                '    <label class="layui-form-label" style="width: 100px;">客队各盘得分:</label>' ;
            tmp = '' ;
            for (let i=1;i<=5;i++){
                tmp +=     '    <div class="layui-input-inline" style="width: 30px;">' +
                    '      <input type="text" name="set_wq_gueste_score_'+i+'" id="set_wq_guest_score_'+i+'"  value="' +  + match_score[i]['guest']  + '"  required   autocomplete="off" class="layui-input">' +
                    '    </div>' ;
            }
            content = content + tmp ;
            content +=  '  </div>' ;
            content +=     '</div>';

            layer.open({
                area: ['800px', '200px'], //宽高
                type: 1,
                title: '设置比分',
                content: content, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响,
                btn: ['提交', '取消'],
                yes: function (index, layero) {

                    let home_scores=[],guest_scores=[],str_home,str_guest,i;
                    for (i=0;i<=8;i++){
                        str_home = '#set_wq_home_score_'+(i+1);
                        str_guest = '#set_wq_guest_score_'+(i+1);
                        home_scores.push($(str_home).val());
                        guest_scores.push($(str_guest).val());
                    }

                    matchdata = JSON.stringify({
                        'home':home_scores,
                        'guest':guest_scores
                    });

                    // 请求设置接口
                    ajax_setScore_all_v2(order_id,game_code,match_id,matchdata);
                    return true;
                },
            });

            return ;
        }
        function  ajax_setScore_all_v2(order_id, game_code, match_id, matchdata){
            // 请求设置接口
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/admin/SoccerNoteList/manualmatchpdate_v2',
                data: {order_id: order_id, game_code: game_code, match_id: match_id, matchdata: matchdata},
                success: function (res) {
                    if (1 == res.status) {
                        layer.alert("设置成功", {title: '友情提示', icon: 1, closeBtn: 0}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.alert("服务器异常(0)", {title: '友情提示', icon: 2});
                    }
                },
                error: function () {
                    layer.alert("服务器异常(1)", {title: '友情提示', icon: 2});
                }
            })
        }


        // 设置结算比分
        function setScore(order_id, match_id) {
          // 请求订单数据
          $.getJSON("/admin/SoccerNoteList/manualmatchget", {'order_id' : order_id}, function(res){
            if(1 == res.status){
              const getData = res.data.matchdatas;
              let content = '<div class="ibox-content" id="box" style="width: 600px !important;">';
              let id = '';
              let teamName = '';
              // 拼接玩法数据
              for (let o in getData) {
                id = getData[o].id;
                teamName = getData[o].home_team + ' VS ' + getData[o].guest_team + ' - ' + getData[o].odds_name;
                content +=
                    '        <div style="margin-top: 10px; margin-bottom: 10px;">' +
                    '            <div style="color: #5f5f5f; margin-left: 10px; margin-bottom: 10px;">' + teamName + '</div>' +
                    '            <div class="col-5 layui-inline">' +
                    '                <label class="layui-form-label">结算比分：</label>' +
                    '                <div class="layui-input-inline" style="">' +
                    '                    <input type="text" name="" id="resultInfo' + id + '" placeholder="请输入结算比分" eventType="event-query" lay-verify="required" autocomplete="off" class="layui-input">' +
                    '                </div>' +
                    '            </div>' +
                    '            <div class="col-5 layui-inline">' +
                    '                <label class="layui-form-label">订单结果：</label>' +
                    '                <div class="layui-input-inline" style="">' +
                    '                    <select name="order_status"  id="teamResult' + id + '"  lay-verify="" autocomplete="off" class="layui-input"  eventType=event-query>' +
                    '                        <option value="-1" selected>输</option>' +
                    '                        <option value="1">赢</option>' +
                    '                        <option value="2">平</option>' +
                    '                        <option value="3">半赢半平</option>' +
                    '                        <option value="4">半输半平</option>' +
                    '                    </select>' +
                    '                </div>' +
                    '            </div>' +
                    '        </div>' +
                    '        <div style="border-bottom: 2px dashed #cbcbcb;"></div>';
              }
              content += '</div>';
              // 打开弹窗.
              layer.open({
                area: ['600px', '300px'], //宽高
                type: 1,
                title: '设置比分',
                content: content, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响,
                btn: ['提交', '取消'],
                yes: function(index, layero){
                  let matchdata = [];
                  let teamResult = '';
                  let resultInfo = '';
                  // 循环获取输入的数据.
                  for (let o in getData) {
                    id = getData[o].id;
                    teamResult = $("#teamResult" + id).val();
                    resultInfo = $("#resultInfo" + id).val();
                    matchdata.push({id: id, result: teamResult, matchresult: resultInfo})
                  }
                  matchdata = JSON.stringify(matchdata);
                  // 请求设置接口
                  $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: '/admin/SoccerNoteList/manualmatchpdate',
                    data: {order_id: order_id, matchdata: matchdata},
                    success: function(res) {
                      if (1 == res.status) {
                        layer.alert("设置成功", {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                          window.location.reload();
                        });
                      } else {
                        layer.alert("服务器异常", {title: '友情提示', icon: 2});
                      }
                    },
                    error: function () {
                      layer.alert("服务器异常", {title: '友情提示', icon: 2});
                    }
                  })
                },
              });
            } else {
              layer.alert("数据拉取失败", {title: '友情提示', icon: 2});
            }
          });
        }

        //单式注单作废
        function invalid(url,order_id,league) {
            // 请求订单数据
            $.getJSON("/admin/SoccerNoteList/manualmatchget", {'order_id' : order_id}, function(res) {
                //console.log(res);
                if(1 == res.status){
                    const getData = res.data.matchdatas;
                    let content = '<div class="ibox-content" id="box" style="width: 400px !important;">';
                    let id = '';
                    let teamName = '';
                    let detail = '';
                    // 拼接玩法数据
                    for (let o in getData) {
                        id = getData[o].id;
                        teamName = getData[o].home_team + ' VS ' + getData[o].guest_team;
                        detail += getData[o].odds_name+' '+getData[o].condition+'@'+getData[o].odds+'<br>';
                    }
                    content +=
                            '        <div style="margin-top: 20px;margin-left: 15px; margin-bottom: 10px;">' +
                            '       <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">联赛名称：</label>' +
                            '                <div class="layui-input-inline" style="line-height: 38px;">' + league +
                            '                </div>' +
                            '            </div><br>' +
                            '       <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">主客队：</label>' +
                            '                <div class="layui-input-inline" style="line-height: 38px;">' + teamName +
                            '                </div>' +
                            '            </div><br>' +
                            '       <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">投注信息：</label>' +
                            '                <div class="layui-input-inline" style="line-height: 38px;">' + detail +
                            '                </div>' +
                            '            </div><br>' +
                            '       <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">投注金额 ：</label>' +
                            '                <div class="layui-input-inline" style="line-height: 38px;">' + res.data.money +
                            '                </div>' +
                            '            </div><br>' +
                            '       <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">最高可赢 ：</label>' +
                            '                <div class="layui-input-inline" style="line-height: 38px;">' + res.data.prize_money +
                            '                </div>' +
                            '            </div><br>' +
                            '       <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">下注时间 ：</label>' +
                            '                <div class="layui-input-inline" style="line-height: 38px;">' + res.data.money_time +
                            '                </div>' +
                            '            </div><br>' +
//                                '            <div style="color: #5f5f5f; margin-left: 10px; margin-bottom: 10px;">' + teamName + '</div>' +
                            '            <div class="col-5 layui-inline">' +
                            '                <label class="layui-form-label">作废原因：</label>' +
                            '                <div class="layui-input-inline" style="">' +
                            '                    <input type="text" name="" id="reason' + id + '" placeholder="请输入作废原因" eventType="event-query" lay-verify="required" autocomplete="off" class="layui-input">' +
                            '                </div><br>' +
                            '            </div>' +
                            '        </div>';
                    content += '</div>';
                    // 打开弹窗.
                    layer.open({
                        area: ['400px', '480px'], //宽高
                        type: 1,
                        title: '注单作废',
                        content: content, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响,
                        btn: ['提交', '取消'],
                        yes: function(index, layero){

                            reason = $("#reason" + id).val();
                            //console.log(reason);
                            // 请求设置接口
                            //console.log(url);
                            $.ajax({
                                type: 'get',
                                //dataType: 'json',
                                url: url,
                                data: {'reason': reason},
                                success: function(res) {
                                    //console.log(res);
                                    if (1 == res) {
                                        layer.alert("设置成功", {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                                            window.location.reload();
                                        });
                                    } else {
                                        layer.alert("服务器异常", {title: '友情提示', icon: 2});
                                    }
                                },
                                error: function () {
                                    layer.alert("服务器异常", {title: '友情提示', icon: 2});
                                }
                            })
                        },
                    });
                } else {
                    layer.alert("数据拉取失败", {title: '友情提示', icon: 2});
                }

        });
//            layer.confirm('是否确认作废？', {
//                btn: ['确认', '取消'] //按钮
//            }, function() {
//                $.getJSON(url, function(data, textStatus) {
//                    //console.log(data);
//                    if (data == '1') {
//                        reloadDataTable();
//                        layer.msg('作废成功');
//                    } else {
//                        layer.msg(data.msg);
//                    }
//                });
//            }, function() {
//
//            });

        }
    </script>

    @include('vip.datatable')
@endsection
