<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>网站用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="first_name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">telegram ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="member_id" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">游戏ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="game_id" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;"></div>
            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="buy">充值</a>
</script>
<script src="/layuiadmin/layui/layui.js"></script>
<script src="/static/js/alpha_2.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'table', 'layer'], function () {
        const $ = layui.$, form = layui.form, table = layui.table, layer = layui.layer;
        const token = localStorage.getItem('token');

        //用户管理
        let tableList = table.render({
            elem: '#LAY-user-manage',
            url: "{{url('/admin/user')}}", //模拟接口
            headers: {Authorization: token},
            // toolbar: true,
            // lineStyle: 'maxHeight: 95px;',
            // defaultToolbar: ['filter'],
            cols: [[
                {field: 'id', width: 80, title: 'ID', align: 'center'},
                {field: 'member_id', title: 'telegram ID'},
                {field: 'first_name', title: '昵称'},
                {field: 'usdt', title: '钱包地址'},
                {field: "game_id", title: "游戏ID"},
                {title: '操作', toolbar: '#toolbar', minWidth: 100, hide: true}
            ]],
            page: true,
            limit: 50,
            limits: [50, 100, 200, 300],
            where: {lang: 'zh-CN'},
            height: 'full-137',
            text: {none: '无数据'},
            parseData(res) {
                return {
                    code: res.code,
                    msg: res.msg,
                    count: res.data.total,
                    data: res.data.data
                };
            }
        });

        table.on('tool(LAY-user-manage)', function (obj) {
            switch (obj.event) {
                case "buy":
                    layer.prompt({
                        title: "钱包余额充值",
                        formType: 0,
                        placeholder: '请输入要充值的金额'
                    }, (value, index, elem) => {
                        const priceRegex = /^\d+(\.\d{1,2})?$/;
                        if (!priceRegex.test(value)) return false;
                        if (parseFloat(value) === 0) return false;

                        $.ajax({
                            url: "",
                            method: 'post',
                            headers: {'X-CSRF-TOKEN': ""},
                            data: {userId: obj.data.id, wallet: value},
                            success(res) {
                                if (res.code === 0) {
                                    tableList.reloadData();
                                    layer.close(index);
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        });
                    });
                    break;

                case "img":
                    let start = this.dataset.index - 1;
                    let data = [];
                    for (let i = 1; i < obj.data.photo.length; i++) {
                        if (obj.data.photo[i]) {
                            data.push({
                                "alt": `个人自拍_${i}`,
                                "pid": (i - 1),
                                "src": obj.data.photo[i],
                                "thumb": obj.data.photo[i],
                            });
                        }
                    }
                    layer.photos({
                        toolbar: false,
                        photos: {
                            title: "个人自拍",
                            id: obj.data.id,
                            start: start,
                            data: data
                        }
                    });
                    break;
            }

            console.log(this.src);
            // console.log(obj)
        });

        form.on('submit(LAY-user-front-search)', function (data) {
            let field = data.field;
            table.reload('LAY-user-manage', {
                where: field
            });
        });
    });
</script>
</body>
</html>
