
<style>
    .layui-table-cell .layui-form-checkbox[lay-skin="primary"], .layui-table-cell .layui-form-radio[lay-skin="primary"] {
        top:5px !important;
    }

</style>
<?php $__env->startSection('content'); ?>
    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto layui-form">
            <form class="layui-form-item" id="search-form">
                <div class="layui-inline">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-inline">
                        <select name="type"  id="type">
                            <option value="">收支类型</option>
                            <option value="2">账户充值</option>
                            <option value="1">账户消费</option>
                            <option value="3">订单退款</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">时间区间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" placeholder="开始时间" name="create_start" id="start_time" autocomplete="off">
                    </div>
                    <div class="layui-form-mid">至</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" placeholder="结束时间" name="create_end" id="end_time" autocomplete="off">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">用户电话</label>
                    <div class="layui-input-inline">
                        <input type="text" name="phone" id="phone"  placeholder="请输入用户电话" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="searchBtn">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>

            </form>
            <div>
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm" href="<?php echo e(route('admin.account.create')); ?>">充 值</a>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.member.member.toExcel')): ?>
                    <button class="layui-btn layui-btn-sm" id="toExcel">导 出</button>
                    <?php endif; ?>
                </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">
                    <a class="layui-btn layui-btn-sm" lay-event="edit">查看详情</a>
                </div>
            </script>
            <script type="text/html" id="thumb">
                <a href="{{d.thumb}}" target="_blank" title="点击查看"><img src="{{d.thumb}}" alt="" width="28" height="28"></a>
            </script>


        </div>
    </div>
    <?php $__env->stopSection(); ?>
            <!-- 首先引入css, 和js, 唯一依赖: jQuery -->
    <link href="/static/admin/layuiadmin/layui/dist/formSelects-v4.css" rel="stylesheet" />
    <script src="/static/admin/layuiadmin/layui/dist/jquery.min.js"></script>
    <script src="/static/admin/layuiadmin/layui/dist/formSelects-v4.min.js"></script>
<?php $__env->startSection('script'); ?>
    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.member.member')): ?>

    <script>
        layui.use(['layer','table','form','laydate'],function () {
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var laydate = layui.laydate;


            formSelects.render('selectId');
            //用户表格初始化
            var dataTable = table.render({
                elem: '#dataTable'
                // ,height: 500
                ,url: "<?php echo e(route('admin.account.data')); ?>" //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {checkbox: true,fixed: true}
                     ,{field: 'id', title: 'ID', sort: true,width:80}
                    ,{field: 'phone', title: '用户电话',templet:function (d) {
                        if(d.member) {
                            return d.member.phone
                        }else{
                            return ''
                        }
                      }
                    }
                    ,{field: 'money', title: '交易金额',templet:function (d) {
                        if(d.money){
                            return d.money+'元';
                        }else{
                            return ''
                        }}}
                    ,{field: 'type', title: '交易类型',templet:function (d) {
                        switch(d.type) {
                            case 1:
                                return '账户支出'
                                        break;
                            case 2:
                                return '充值：用户充值'
                                break;
                            case 3:
                                return '订单退款'
                                break;
                            case 4:
                                return '结算冻结金额'
                                break;
                            case 5:
                                return '充值：后台充值'
                                break;
                            default :
                                return '其他操作类型'
                                break;
                        }
                    }}
                    ,{field: 'freeze_money', title: '冻结金额',templet:function (d) {
                        if(d.freeze_money){
                            return d.freeze_money+'元';
                        }else{
                            return ''
                        }
                    }}
                    ,{field: 'total_money', title: '可用金额',templet:function (d) {
                        if(d.total_money){
                            return d.total_money+'元';
                        }else{
                            return ''
                        }}}
                    ,{field: 'order_id', title: '订单号',templet:function (d) {
                        if (d.order_no) {
                            return d.order_no
                        }else{
                            return ''
                        }
                    }}
                    ,{field: 'mark', title: '备注'}
                    ,{field: 'created_at', title: '操作时间', sort: true}
                     ,{fixed: 'right', title:'操作',width: 100, align:'center', toolbar: '#options'}
                ]]
            });




            //监听是否显示
            form.on('switch(isShow)', function(obj){
                var index = layer.load();
                var url = $(obj.elem).attr('url')
                var data = {
                    "is_show" : obj.elem.checked==true?1:0,
                    "_method" : "put"
                }
                $.post(url,data,function (res) {
                    layer.close(index)
                    layer.msg(res.msg)
                },'json');
            });

            //按钮批量删除
            $("#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("",{_method:'delete',ids:ids},function (result) {
                            if (result.code==0){
                                dataTable.reload()
                            }
                            layer.close(index);
                            layer.msg(result.msg,{icon:6})
                        });
                    })
                }else {
                    layer.msg('请选择删除项',{icon:5})
                }
            })


            //导出
            $("#toExcel").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)
                    })
                }
                var phone = $("#phone").val();
                var start_time = $("#create_start").val();
                var end_time = $("#create_end").val();
                var type = $("#type").val();
                var u = '<?php echo e(route('admin.account.excel')); ?>';
                u = u+'?type='+type+'&start_time='+start_time+'&end_time='+end_time+'&phone='+phone+'&ids='+ids;
                window.location.href=u;
            })
            //监听工具条
            table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                if(layEvent === 'edit'){
                    location.href = '/admin/account/'+data.id+'/edit';
                }
            });
            //监听搜索
            form.on('submit(searchBtn)', function(data){
                var field = data.field;

                //执行重载
                table.reload('dataTable', {
                    where: field
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                return false;
            });


            laydate.render({
                elem: '#start_time' //指定元素
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#end_time' //指定元素
                ,type: 'datetime'
            });
        });

    </script>
    <?php endif; ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.base', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>