@extends('admin.base')

@section('content')
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <div class="layui-btn-group ">
                {{--@can('config.gameUrl.destroy')
                    <button class="layui-btn layui-btn-sm layui-btn-danger" id="listDelete">删除</button>
                @endcan--}}
                @can('config.gameUrl.create')
                    <a class="layui-btn layui-btn-sm" href="{{ route('admin.sign.setting') }}">设置</a>
                @endcan
                <button class="layui-btn layui-btn-sm" id="memberSearch">搜索</button>
            </div>
            <div class="layui-form">

                <div class="layui-input-inline">
                    <input type="text" name="userName" id="userName" placeholder="名称" class="layui-input">
                </div>

                <div class="layui-input-inline">
                    <input style="width: 200px" type="text" name="time" id="time" placeholder="时间区间" class="layui-input">
                </div>

            </div>
        </div>

        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    @can('config.gameUrl.edit')
                        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                    @endcan
                    {{--@can('config.gameUrl.destroy')
                        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
                    @endcan--}}
                </div>
            </script>
            {{--<script type="text/html" id="avatar">
                <a href="@{{d.avatar}}" target="_blank" title="点击查看"><img src="@{{d.avatar}}" alt="" width="28" height="28"></a>
            </script>--}}
        </div>
    </div>
@endsection

@section('script')
    @can('config.gameUrl')
        <script>
            let endDay = customFormatDateTime(new Date(new Date().setHours(0, 0, 0, 0)) / 1000,'-',1);
            let startDay = customFormatDateTime((new Date(new Date().setHours(0, 0, 0, 0)) / 1000) - 60 * 60 * 24 * 6,'-',1);
            $("#time").val(startDay+" , "+endDay);
            layui.use(['layer','table','form'],function () {
                var layer = layui.layer;
                var form = layui.form;
                var table = layui.table;
                //用户表格初始化
                var dataTable = table.render({
                    elem: '#dataTable'
                    ,height: 500
                    ,url: "{{ route('admin.sign.data') }}" //数据接口
                    ,where:{model:"sign"}
                    ,page: true //开启分页
                    ,cols: [[ //表头
                        {checkbox: true,fixed: true}
                        ,{field: 'getsign_id', title: 'ID', sort: true,width:80}
                        ,{field: 'getsign_identity', title: '工单号'}
                        ,{field: 'name', title: '用户名'}
                        ,{field: 'getsign_mony', title: '领取金额'}
                        ,{field: 'getsign_begin_money', title: '用户初始金额'}
                        ,{field: 'getsign_end_money', title: '领取后金额'}
                        ,{field: 'getsign_addtime', title: '生成时间', templet: function(d){
                            return customFormatDateTime(d.getsign_addtime, '', 3);
                      }}

                        /*,{fixed: 'right', width: 120, align:'center', toolbar: '#options'}*/
                    ]]
                });

                //监听工具条
                table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                    var data = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                    if(layEvent === 'del'){
                        layer.confirm('确认删除吗？', function(index){
                            $.post("{{ route('admin.gameUrl.destroy') }}",{_method:'delete',ids:[data.gameUrl_id]},function (result) {
                                if (result.code==0){
                                    obj.del(); //删除对应行（tr）的DOM结构
                                }
                                layer.close(index);
                                layer.msg(result.msg)
                            });
                        });
                    } else if(layEvent === 'edit'){
                        location.href = '/admin/gameUrl/'+data.gameUrl_id+'/edit';
                    }
                });

                //按钮批量删除
                $("#listDelete").click(function () {
                    var ids = []
                    var hasCheck = table.checkStatus('dataTable')
                    var hasCheckData = hasCheck.data
                    if (hasCheckData.length>0){
                        $.each(hasCheckData,function (index,element) {
                            ids.push(element.gameUrl_id)
                        })
                    }
                    if (ids.length>0){
                        layer.confirm('确认删除吗？', function(index){
                            $.post("{{ route('admin.gameUrl.destroy') }}",{_method:'delete',ids:ids},function (result) {
                                if (result.code==0){
                                    dataTable.reload()
                                }
                                layer.close(index);
                                layer.msg(result.msg)
                            });
                        })
                    }else {
                        layer.msg('请选择删除项')
                    }
                })
                //搜索
                $("#memberSearch").click(function () {
                    var userName = $("#userName").val();
                    var time = $("#time").val();
                    dataTable.reload({
                        where:{userName:userName, time: time},
                        page:{curr:1}
                    })
                })
            })
            layui.use('laydate', function () {
              var laydate = layui.laydate;
              laydate.render({
                elem: '#time'
                , range: ','
              });
            });
            /**
             * 时间戳转化为年 月 日 时 分 秒
             * time: 传入时间戳
             * format：返回格式，支持自定义，但参数必须与formateArr里保持一致
             */
            function customFormatDateTime(timeStamp,custom,isDtae) {
              var date = new Date();
              date.setTime(timeStamp * 1000);
              var y = date.getFullYear();
              var m = date.getMonth() + 1;
              m = m < 10 ? ('0' + m) : m;
              var d = date.getDate();
              d = d < 10 ? ('0' + d) : d;
              var h = date.getHours();
              h = h < 10 ? ('0' + h) : h;
              var minute = date.getMinutes();
              var second = date.getSeconds();
              minute = minute < 10 ? ('0' + minute) : minute;
              second = second < 10 ? ('0' + second) : second;
              if (isDtae == 0){
                return y + custom + m //+'student';
              }else if (isDtae ==1){
                return y + custom + m + custom + d;
              } else if (isDtae ==2) {
                return h + ':' + minute;
              } else {
                return y + '-' + m + '-' + d + '-' + h + ':' + minute + ':' + second;
              }
            };
        </script>
    @endcan
@endsection



