
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="referrer" content="no-referrer">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="author" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <link href="/css/common/common.css" rel="stylesheet" type="text/css" />
    <link href="/css/admin/console.css" rel="stylesheet" type="text/css"/>
    <link href="/ref/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <script src="/ref/layui-v2.6.8/layui/layui.js" type="text/javascript"></script>
    <script src="/ref/jquery/jquery-3.4.1.js" type="text/javascript"></script>

    <style>
        .search-condition-elem {
            width: 170px;
        }
    </style>
</head>
<body style="overflow-x: hidden">
<center>
    <div class="search-condition-module" style="background-color: transparent">
        <button class="btn" style="right: 100px" id="grant-btn">系统赠送</button>
    </div>

    <table class="account-apply-tab layui-table" id="search-result-tab">
        <thead>
        <tr>
            <th style="width: 50px">用户id</th>
            <th style="width: 70px">用户名</th>
            <th style="width: 100px">事件</th>
            <th style="width: 60px">类型</th>
            <th style="width: 200px;" class="line1ppp">金额</th>
            <th style="width: 200px">注册时间</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <div id="page"></div>
</center>
</body>
<script>

    var firstSearch = true;
    var curr = 0, size = 10, total = 0;
    loadUserWalletInFlow();
    function loadUserWalletInFlow() {
        $.ajax({
            url:"/api/user/wallet/page?pageNo="+(curr == 0 ? 1 : curr)+"&pageSize="+size,
            type:"get",
            success:function (data) {
                data = eval(data);
                $("#search-result-tab").children("tbody").empty();
                if (data.success){
                    $.each(data.data, function (index, value) {
                        var tr = "<tr>"+
                            "<td>"+value.user.userId+"</td>"+
                            "<td>"+value.user.userName+"</td>"+
                            "<td>"+value.event+"</td>"+
                            "<td>"+(value.type == 1 ? "收入" : "支出")+"</td>"+
                            "<td>"+(value.type == 1 ? "" : "-")+value.money+"</td>"+
                            "<td>"+value.timeStr+"</td>"+
                            "</tr>";
                        if (!firstSearch) {
                            $("#search-result-tab").children("tbody").append(tr);
                        }
                    })
                    if (curr == 0 || data.total != total) {
                        curr = 1;
                        firstSearch = false;
                        total = data.total;
                        initPage();
                    }
                } else {
                    layer.msg(data.msg);
                }
            },error:function () {}
        })
    }

    function initPage() {
        layui.use('laypage', function(){
            var laypage = layui.laypage;
            laypage.render({
                elem: 'page',
                count: total,
                limit: size,
                curr: curr,
                jump: function(obj){
                    curr = obj.curr;
                    loadUserWalletInFlow();
                }
            });
        })
    }

    $("#grant-btn").on('click', function() {
        layer.closeAll();
        layer.open({
            type: 1,
            title: false,
            skin: 'layui-layer-demo', //样式类名
            closeBtn: 0, //不显示关闭按钮
            anim: 2,
            area: ['380px', '300px'],
            shadeClose: true, //开启遮罩关闭
            content: '<div class=\"popup-module-header-div\" style="height: 70px;">' +
                '<p class=\"popup-module-title\" style="padding-top: 20px">账号钱包发钱</p>' +
                '</div>' +
                '<div class=\"popup-module-core-div\" style="margin-top: -40px">' +
                '<div class="popup-module-core-div-item">' +
                '<input class="popup-input-number" id="create-uid" placeholder="账号userId，列表中第一列">' +
                '</div>' +
                '<div class="popup-module-core-div-item">' +
                '<input class="popup-input-number" id="create-money" placeholder="金额，最好是整数">' +
                '</div>' +
                '<div class="popup-module-core-div-item" style=\"border: 0px\">' +
                '<button class=\"popup-btn\" onclick=\"grantMoney($(\'#create-uid\').val(), $(\'#create-money\').val())\">赠送</button>' +
                '</div>' +
                '</div>' +
                '</div>'
        });
    })

    function grantMoney(userId, money) {
        if (userId == '') {
            layer.msg("接收人账号id未设置");
            return;
        }
        if (money == '') {
            layer.msg("赠送金额未设置");
            return;
        }
        $.ajax({
            url: "/api/user/wallet/grant/"+userId+"/"+money,
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success:function (data) {
                data = eval(data);
                if (data.success){
                    layer.msg("赠送成功");
                    loadUserWalletInFlow();
                    layer.closeAll();
                } else {
                    layer.msg(data.msg);
                }
            },error:function () {
                layer.msg("服务端异常");
            }
        })
    }

</script>
<style>
    .layui-laypage a, .layui-laypage span {
        display: inline-block;
        *display: inline;
        *zoom: 1;
        vertical-align: middle;
        padding: 3px 13px;
        height: 28px;
        line-height: 28px;
        margin: 0px 5px;
        border-radius: 4px;
        background-color: #fff;
        color: #4e6ef2;
        font-size: 14px;
        border: none;
    }
    .layui-laypage a:hover, .layui-laypage span:hover {
        background: #4e6ef2;
        color: #fff;
    }
    .layui-laypage .layui-laypage-curr .layui-laypage-em {
        position: absolute;
        left: -1px;
        top: -1px;
        padding: 1px;
        width: 100%;
        height: 100%;
        border-radius: 4px;
        background: #4e6ef2;
        color: #fff;
        font-weight: normal;
    }
    .layui-laypage-next, .layui-laypage-prev {
        border-radius: 4px;
    }
    .layui-laypage-default {
        float: right;
    }
</style>
</html>