admin
2025-08-20 f318c9c7c127b00f353bf45f273096d1dc4b424f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>积分设置管理</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
    <script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
</head>
 
<body>
 
<form class="layui-form" action="" lay-filter='search'>
    <div class="layui-form-item">
        <div class="layui-inline">
            <input type="text" name="uid" id="uid" placeholder="用户ID" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="search" id="search"><i
                    class="layui-icon layui-icon-search"></i>搜索
            </button>
        </div>
 
    </div>
</form>
    <table id="table" lay-filter="table"></table>
 
 
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    </script>
 
    <script>
        layui.use(['table', 'layer'], function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
 
            // 渲染表格
            table.render({
                elem: '#table',
                url: '/admin/api/credit/setting/list',
                toolbar: '#toolbar',
                cols: [[
                    { field: 'id', title: 'ID', width: 80 },
                    { field: 'name', title: '名称', width: 150 },
                    { field: 'value', title: '值', width: 150 },
                    { fixed: 'right', title: '操作', toolbar: '#bar', width: 150 }
                ]],
                page: true
            });
            // 监听搜索
            form.on('submit(search)', function (data) {
 
                tableIns.reload();
                return false;
            });
 
 
 
 
            // 行操作事件
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'edit') {
                    var layerIndex = layer.open({
                        title: "修改积分设置",
                        type: 2,
                        area: ['600px', '400px'],
                        shade: 0.3,
                        shadeClose: false, //默认开启遮罩关闭
                        resize: false, //默认重设大小是否
                        //如果不让iframe出现滚动条,
                        //可以content: ['http://sentsin.com', 'no']
                        content: 'credit-setting-edit.html?id=' + data.id,
                        btn: ['确定', '取消'],
                        yes: function (index) {
                            //submit方法为弹框内容中的方法
                            window["layui-layer-iframe" + index].submit(function (res) {
                                console.log(res);
                                let fdata = {
                                    id: data.id
                                };
                                for (let key in res) {
                                    if (key.indexOf(".") >= 0) {
                                        let k1 = key.split(".")[0];
                                        let k2 = key.split(".")[1];
                                        if (k1 in fdata) {
                                        } else {
                                            fdata[k1] = {};
                                        }
                                        fdata[k1][k2] = res[key];
                                    } else {
                                        fdata[key] = res[key]
                                    }
                                }
                                for (let key in fdata) {
                                    console.log(typeof (fdata[key]))
                                    if (typeof (fdata[key]) == 'object') {
                                        fdata[key] = JSON.stringify(fdata[key]);
                                    }
                                }
                                console.log(fdata);
                                try {
                                    var index = layer.load(1);
                                    $.post('/admin/api/credit/setting/update', fdata, function (res) {
                                        layer.close(index);
                                        if (res.code === 0) {
                                            layer.close(layerIndex);
                                            layer.msg('修改成功');
                                        } else {
                                            layer.msg('修改失败:' + res.msg);
                                        }
                                    },'json').fail(function(jqXHR, textStatus, errorThrown) {
                                        layer.msg("网络请求失败");
                                        layer.close(index);
                                    });
                                } catch (e) {
                                    console.log(e);
                                }
                            });
                        },
                        cancel: function () {
                        }
                    });
 
 
                }
            });
        });
    </script>
</body>
 
</html>