@extends('vip.layouts')
@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;
        }

        .statistics{
            margin: 0 auto;
            text-align: center;
            margin-bottom: 5px;
        }

        .red{
            color: red;
            font-weight: bold;
        }
    </style>
    <!---注单管理-->
    <div class="layui-row">
        <div class="layui-col-sm12 layui-col-md12 text" >
            <form class="layui-form rewrite" eventType=eventForm>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间：</label>
                        <div class="layui-input-inline" style="width:200px;">
                            <input type="text" name="start_time" id="start_time"  lay-verify=""
                                   autocomplete="off" class="layui-input test-item" eventType=event-query
                                   value="{{ $start_time }}">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束时间：</label>
                        <div class="layui-input-inline" style="width:200px;">
                            <input type="text" name="end_time" id="end_time" placeholder=" - " lay-verify=""
                                   autocomplete="off" class="layui-input test-item" eventType=event-query
                                   value="{{ $end_time }}">
                        </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-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>
                        <a class="layui-btn layui-btn-sm" id="get_rec" data-type="reload" style="opacity: 1; pointer-events: auto;">获取最新流水</a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div id='txt' style="display: none;margin: 20px;">
        <p>数据自动拉取中......，请不要关闭窗口，系统会每隔30秒拉取一次数据。<span id='timer'>30</span>秒后重新拉取</p>
        <p><img src='/admin/image/loading.gif' /></p>
        <div  style="margin-top: 20px;"><span id="umsg">暂无可拉取的数据</span></div>
    </div>
    @push('dataTableJS')
        $('.layui-table-page').after('<div id="statistics" class="statistics"></div>');
        function dataTableLoadFinished(res,curr,count)
        {
            var str = '';
            var datau=res.data;
            var bettingamount = 0,winLoseamount = 0,validamount = 0,revenue = 0;
            for(var i = 0; i < datau.length; i++)
            {
                bettingamount += parseFloat(res.data[i]['AllBet']);
                winLoseamount += parseFloat(res.data[i]['Profit']);
                validamount += parseFloat(res.data[i]['CellScore']);
                revenue += parseFloat(res.data[i]['Revenue']);
            }
            $('#statistics').html('');
    
            str = '<p>本页共'+ datau.length +'条注单；总投注金额：<span class="red">'+ bettingamount.toFixed(2) +'RMB</span>；总盈亏金额：<span class="red">'+ winLoseamount.toFixed(2) +'RMB</span>；总有效投注额：<span class="red">'+ validamount.toFixed(2) +'RMB</span>；总抽水金额：<span class="red">'+ revenue.toFixed(2) +'RMB</span></p>';
    
            $.ajax({
                type: 'get',
                url: '/admin/LcqpGame/allTotal',
                data: {where:res.extras},
                dataType: 'json',
                success: function (data) {
                    var data=data.data;
                    str += '<p>本类共' + data.co + '条注单；总投注金额：<span class="red">'+data.bettingamount.toFixed(2)+'RMB</span>；总盈亏金额：<span class="red">'+data.winLoseamount.toFixed(2)+'RMB</span>；总有效投注额：<span class="red">'+data.validamount.toFixed(2)+'RMB</span>；总抽水金额：<span class="red">'+data.revenue.toFixed(2)+'RMB</span></p>';
    
                    //$('#statistics').html(str);
                }
            });
    
    
            }
    
    @endpush
    @include('vip.datatable')
    <script>
        $('#get_rec').on('click',function(){
            layer.open({
                type: 1,
                title: '获取最新流水',
                shadeClose: true,
                shade: 0.8,
                area: ['1000px', '70%'],
                content: $('#txt'),
                end: function(){ //此处用于演示
                    location.reload();
                }
            });

            $('#txt').show();
            var time=parseInt($('#timer').text());
            litime(time);
        });

        //定时拉取数据
        function litime(time){
            setTime=setInterval(function(){
                if(time<=1){
                    clearInterval(setTime);
                    updateWater(); 
                    litime(30);            
                }
                time--;
                $('#timer').text(time);
            },1000);
        }

        //更新流水
        function updateWater(){
            $.ajax({
                type: 'get',
                url: '/admin/MgGame/updatebetlist',
                data: {},
                dataType: 'json',
                success: function (data) {
                    $('#umsg').text(data.msg);
                }
            });
        }
    </script>
@endsection
