@extends('vip.layouts')
@section('content')
    <style>
        .layui-form-checked span,.layui-form-checkbox span{
            width: 120px!important;
            overflow: hidden;
        }
        .layui-form-checked,.layui-form-checkbox {
            margin-bottom: 5px;
        }
        .layui-unselect{
            margin-left: 5px;
        }
        .tablename{
            display: inline-block;
            width: 100px!important;
            overflow: hidden;
            color: #8a8a8a
        }
    </style>
    <form class="layui-form" action="{{ url()->full() }}" id="submitForm" name="submitForm" method="post" eventType=eventAjaxForm>
        {!! csrf_field() !!}


        <div class="layui-card">
            <div class="layui-card-header layui-inline">
                <div class="layui-card-header">游戏开奖，投注表</div>
            </div>
            <div class="layui-card-body">
                @foreach($gamelist as $g)
                    <input  style="margin-bottom: 2px;" type="checkbox"  class="checkbox1" name="games[{{$g['gameCode']}}]" title="{{$g['name']}}"  >
                @endforeach
            </div>
        </div>
        @if($special)
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">特殊关表<b style="color: #c42a20">（请谨慎清除）</b></div>
                <div class="layui-card-body">
                    @foreach($special as $s)
                        <input  style="margin-bottom: 2px;" type="checkbox" class="checkbox1" name="games[{{$s['gameCode']}}]" title="{{$s['name']}}"  >
                    @endforeach
                </div><span class="tablename"  title="{{$s['gameCode']}}">{{$s['gameCode']}}</span>
            </div>
        </div>
        @endif
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">一般记录表<b style="color: #c42a20">（将清除截至日期之前的数据）</b></div>
                <div class="layui-card-body">
                    @foreach($normal as $n)
                        <div class="layui-inline">
                        <input  style="margin-bottom: 2px;" type="checkbox"  class="checkbox1"name="games[{{$n['gameCode']}}]" title="{{$n['name']}}"  ><span class="tablename"  title="{{$n['gameCode']}}">{{$n['gameCode']}}</span>
                        </div>
                    @endforeach
                </div>
            </div>
        </div>
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">其他相关表<b style="color: #c42a20">（没有时间字段，请谨慎清除，将清除所有数据）</b></div>
                <div class="layui-card-body showtable">
                    @foreach($other as $o)
                        <input  style="margin-bottom: 2px;" type="checkbox" class="checkbox1" name="games[{{$o['gameCode']}}]" title="{{$o['name']}}"  ><span class="tablename" title="{{$o['gameCode']}}">{{$o['gameCode']}}</span>
                    @endforeach
                </div>
            </div>
        </div>

        <div class="layui-col-md12">

            <input type="checkbox"  lay-skin="primary" title="全选" id="selectall" lay-filter="selectall">
            <div class="layui-input-inline">
                <label class="layui-form-label">清除截至到</label>
            </div>

            <div class="layui-input-inline">
                <input type="text" name="time"  class="layui-input" id="test1" placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
            <div class=" layui-word-aux layui-input-inline">的数据</div>
            <button class="layui-btn" lay-submit lay-filter="submit" id="submit">确认清理</button>
        </div>
        <input type="hidden" id="limitdate" value="{{$limitdate}}" >
    </form>

    <script>



        function allselect(){
            console.log(111)
           var selected = $('#selectall').val();
           console.log(selected)
        }
        //Demo
        layui.use(['laydate','form','element' ], function(){
            var form = layui.form
            var laydate = layui.laydate;
            var limitdate   =   $('#limitdate').val()
            //日期时间选择器
            laydate.render({
                elem: '#test1'
                ,type: 'datetime',
                value:limitdate
                ,max: -120
            });

            //监听提交
            form.on('checkbox(selectall)', function (data) {
                console.log(data)
                var a = data.elem.checked;
                if(a == true){
                    $(".checkbox1").prop("checked", true);
                    form.render('checkbox');
                }else {
                    $(".checkbox1").prop("checked", false);
                    form.render('checkbox');
                }

            });
            //监听提交
            form.on('submit(submit)', function(data){
                layer.load(3);
//此处演示关闭
                $('#submit').attr('disabled','disabled')
                $.post("{{ url()->full() }}",data.field,function(res){
                    setTimeout(function(){
                        layer.closeAll('loading');
                        $('#submit').attr('disabled',false)
                    }, 1000);
                    if(res.status==1){
                        let data =res.data
                        let msg='';
                        for(let i in data){
                            msg +=   data[i].name+'成功清理 '+ data[i].success+' 条<br>'
                        }
                        layer.alert(msg);

                    }else{
                        layer.msg(res.msg, {time: 2000});
                    }
                },'json');
                return false;
                return true;
            });
        });



    </script>
@endsection
