@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;
        }

        .layui-inline{
            margin-bottom: 10px;
        }

        .pull-left{
            float: left;
            width: 100%;
        }

        p{line-height: 25px;}
    </style>
    <!---注单管理-->
    <div class="layui-row">
        <div class="layui-col-sm12 layui-col-md12 text" >
                <div class="layui-form-item">
                    <div class="layui-inline pull-left" style="margin-bottom: 30px;">
                        <div class="layui-input-inline" style="width: 100%;" id="AGIN">
                            <p>
                                <a class="layui-btn layui-btn-sm" id="btn" onclick="rec()" style="opacity: 1; pointer-events: auto;">下载AG最新流水</a>
                                <a class="layui-btn layui-btn-disabled" id="btn2" style="display:none; opacity: 1; pointer-events: auto;">下载AG最新流水</a>
                                （共有5类游戏需要下载）
                            </p>
                            <p id="AGIN_txt" style="display: none;">#1：AG电子、真人数据下载中......，请不要做任何操作，耐心等待数据下载完毕。</p>
                            <p id="AGIN_load" style="display: none;"><img src='/admin/image/loading.gif' /></p>
                        </div>
                    </div>
                    <div class="layui-inline pull-left" style="margin-bottom: 30px;">
                        <div class="layui-input-inline" style="width: 100%;" id="HUNTER">
                            <p id="HUNTER_txt" style="display: none;">#2：AG捕鱼数据下载中......，请不要做任何操作，耐心等待数据下载完毕。</p>
                            <p id="HUNTER_load" style="display: none;"><img src='/admin/image/loading.gif' /></p>
                        </div>
                    </div>
                    <div class="layui-inline pull-left" style="margin-bottom: 30px;">
                        <div class="layui-input-inline" style="width: 100%;" id="SBTA">
                            <p id="SBTA_txt" style="display: none;">#3：AG体育数据下载中......，请不要做任何操作，耐心等待数据下载完毕。</p>
                            <p id="SBTA_load" style="display: none;"><img src='/admin/image/loading.gif' /></p>
                        </div>
                    </div>
                    <div class="layui-inline pull-left" style="margin-bottom: 30px;">
                        <div class="layui-input-inline" style="width: 100%;" id="XIN">
                            <p id="XIN_txt" style="display: none;">#4：AG XIN电子数据下载中......，请不要做任何操作，耐心等待数据下载完毕。</p>
                            <p id="XIN_load" style="display: none;"><img src='/admin/image/loading.gif' /></p>
                        </div>
                    </div>
                    <div class="layui-inline pull-left" style="margin-bottom: 30px;">
                        <div class="layui-input-inline" style="width: 100%;" id="YOPLAY">
                            <p id="YOPLAY_txt" style="display: none;">#5：AG街机游戏数据下载中......，请不要做任何操作，耐心等待数据下载完毕。</p>
                            <p id="YOPLAY_load" style="display: none;"><img src='/admin/image/loading.gif' /></p>
                        </div>
                    </div>
                    <div class="layui-inline pull-leftl" style="display:none; margin-bottom: 30px;"  id="download">
                        <div class="layui-input-inline"  style="width: 100%;" >
                            <p><a class="layui-btn layui-btn-sm" id="save_btn" onclick="saveRec()" style=" opacity: 1; pointer-events: auto;">读取并存储AG最新流水</a></p>
                            <p id="save_txt" style="display: none;">读取并存储AG最新数据中......，请不要做任何操作，耐心等待数据存储完毕。</p>
                            <p id="save_load" style="display: none;"><img src='/admin/image/loading.gif' /></p>
                        </div>
                    </div>
                </div>
        </div>
    </div>

    <script>
        function rec()
        {
            getRec('AGIN',1,'AG电子、真人');

            setTimeout(function(){
                getRec('HUNTER',2,'AG捕鱼');
            },2000);

            setTimeout(function(){
                getRec('SBTA',3,'AG体育');
            },4000);

            setTimeout(function(){
                getRec('XIN',4,'AG XIN电子');
            },6000);

            setTimeout(function(){
                getRec('YOPLAY',5,'AG街机游戏');
            },8000);
        }

        function getRec(type,num,text)
        {
            $('#btn').hide();
            $('#btn2').show();
            $('#'+ type +'_txt').show();
            $('#'+ type +'_load').show();

            const surl = '{{$host}}/api/aggameDownloadFile?token={{$token}}&type='+ type +'';

            $.ajax({
                url: surl,
                dataType: 'json',
                data: {},
                type: 'get',
                success:function(data){
                    if(data.status == 1)
                    {
                        var txt = '#'+ num +'：'+ text +'';
                        $('#'+ type +'_txt').text(txt+''+data.msg);
                        $('#'+ type +'_load').hide();

                        if(type == 'YOPLAY')
                        {
                            $('#download').show();
                        }
                    }
                    else
                    {
                        layer.msg(data.msg);
                    }
                }
            });
        }

        function saveRec()
        {
            $('#save_txt').show();
            $('#save_load').show();
            const surl = '{{$host}}/api/aggameReadFile?token={{$token}}';
            $.ajax({
                url: surl,
                dataType: 'json',
                data: {},
                type: 'post',
                success:function(data){
                    if(data.status == 1)
                    {
                        $('#btn').removeAttr('disabled');

                        $('#save_btn').hide();
                        $('#save_txt').text(data.msg);
                        $('#save_load').hide();

                        setTimeout(function(){
                            location.reload();
                        },2000);
                    }
                    else
                    {
                        layer.msg(data.msg);
                    }
                }
            });
        }
    </script>
@endsection
