@extends('admin.base')

@section('content')
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <div class="layui-btn-group ">
                <button class="layui-btn layui-btn-sm" id="memberSearch">搜索</button>
                <button class="layui-btn layui-btn-sm" id="add">增加</button>
                <button class="layui-btn layui-btn-sm" id="reduce">减少</button>
                <button class="layui-btn layui-btn-sm" id="return">返回</button>
            </div>
            <div class="layui-form">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" placeholder="开始时间" name="start_time" id="start_time">
                </div>
                <div class="layui-form-mid layui-word-aux" style="float:none;display: inline;margin-right: 0">-</div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" placeholder="结束时间" name="end_time" id="end_time">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="describe" id="describe" placeholder="请输入关键字" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>
@endsection

@section('script')
    @can('member.member.getDetailedInfo')
        <script>
            layui.use(['layer','table','form'],function () {
                var layer = layui.layer;
                var form = layui.form;
                var table = layui.table;
                var url = document.location.toString();
                var arrUrl = url.split("=");
                var para = arrUrl[1];
                //用户表格初始化
                var dataTable = table.render({
                    elem: '#dataTable'
                    ,height: 500
                    ,url: "{{ route('admin.member.dataDetailedInfo') }}" //数据接口
                    ,where:{members_id: para}
                    ,page: true //开启分页
                    ,cols: [[ //表头
                        {checkbox: true,fixed: true}
                        ,{field: 'moneyDetails_describe', title: '资金变动描述'}
                        ,{field: 'moneyDetails_money', title: '金额'}
                        ,{field: 'moneyDetails_cash', title: '剩余金额'}
                        ,{field: 'moneyDetails_type', title: '增加/减少', templet:function (d) { if ( d.moneyDetails_type === 1 )  { return '增加';}else if (d.moneyDetails_type === 2) {return '减少'}}}
                        ,{field: 'moneyDetails_time', title: '记录时间'}
                    ]]
                });

                //监听工具条
                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.member.destroy') }}",{_method:'delete',ids:[data.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/member/'+data.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.id)
                        })
                    }
                    if (ids.length>0){
                        layer.confirm('确认删除吗？', function(index){
                            $.post("{{ route('admin.member.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 startTime = $("#start_time").val()
                    var endTime = $("#end_time").val();
                    var describe = $("#describe").val();
                    dataTable.reload({
                        where:{startTime:startTime,endTime:endTime,describe:describe,members_id: para},
                        page:{curr:1}
                    })
                })
                //搜索
                $("#reduce").click(function () {
                    var startTime = $("#start_time").val()
                    var endTime = $("#end_time").val();
                    var describe = $("#describe").val();
                    dataTable.reload({
                        where:{startTime:startTime,endTime:endTime,describe:describe,type:2,members_id: para},
                        page:{curr:1}
                    })
                })
                //搜索
                $("#add").click(function () {
                    var startTime = $("#start_time").val()
                    var endTime = $("#end_time").val();
                    var describe = $("#describe").val();
                    dataTable.reload({
                        where:{startTime:startTime,endTime:endTime,describe:describe,type:1,members_id: para},
                        page:{curr:1}
                    })
                })
                //返回
                $("#return").click(function () {
                    location.href = '/admin/member';
                })
            })
        </script>
    @endcan
@endsection



