xiaoyong931011
2021-04-23 d4488a987cccd3ddd51a202a9f8aa71d3cdcbced
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<div class="layui-fluid layui-anim febs-anim" id="febs-user" lay-title="会员列表">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="手机号/邮箱/邀请码" name="account" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">创建时间</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="createTime" id="user-createTime" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">账号类型</label>
                                        <div class="layui-input-inline">
                                            <select name="accountType">
                                                <option value=""></option>
                                                <option value="2">测试账号</option>
                                                <option value="1">正常账号</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">账号状态</label>
                                        <div class="layui-input-inline">
                                            <select name="accountStatus">
                                                <option value=""></option>
                                                <option value="0">禁用</option>
                                                <option value="1">正常</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">实名状态</label>
                                        <div class="layui-input-inline">
                                            <select name="certifyStatus">
                                                <option value="">请选择</option>
                                                <option value="1">待审核</option>
                                                <option value="2">审核通过</option>
                                                <option value="3">未实名</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="user:add,user:update,user:password:reset,user:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="userTable" lay-data="{id: 'userTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 表格字段状态格式化 start -->
<script type="text/html" id="certify-status">
    {{#
    var certifyStatus = {
    1: {title: '待审核', color: 'blue'},
    2: {title: '审核通过', color: 'green'},
    3: {title: '未实名', color: 'blue'}
    }[d.certifyStatus];
    }}
    <span class="layui-badge febs-tag-{{certifyStatus.color}}">{{ certifyStatus.title }}</span>
</script>
<script type="text/html" id="account-type">
    {{#
    var accountType = {
    1: {title: '正常账号'},
    2: {title: '测试账号'}
    }[d.accountType];
    }}
    <span>{{ accountType.title }}</span>
</script>
<script type="text/html" id="account-status">
    {{#
    var accountStatus = {
    1: {title: '正常', color : 'blue'},
    0: {title: '禁用', color : 'red'}
    }[d.accountStatus];
    }}
    <span class="layui-badge febs-bg-{{accountStatus.color}}">{{ accountStatus.title }}</span>
</script>
<!-- 表格字段状态格式化 start -->
 
<!-- 表格操作栏 start -->
<script type="text/html" id="user-option">
    <span shiro:lacksPermission="user:view,user:update,user:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <a lay-event="detail" shiro:hasPermission="user:view"><i
            class="layui-icon febs-edit-area febs-green">&#xe7a5;</i></a>
    <a lay-event="edit" shiro:hasPermission="user:update"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
    <a lay-event="del" shiro:hasPermission="user:delete"><i class="layui-icon febs-edit-area febs-red">&#xe7f9;</i></a>
</script>
<!-- 表格操作栏 end -->
<script data-th-inline="none" type="text/javascript">
    // 引入组件并初始化
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            $view = $('#febs-user'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;
 
        form.render();
 
        // 表格初始化
        initTable();
 
        // 时间组件
        laydate.render({
            elem: '#user-createTime',
            range: true,
            trigger: 'click'
        });
 
        // 新增下拉组件
        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('userTable');
                if (name === 'add') {
                    febs.modal.open('新增用户', 'system/user/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        offset: '30px',
                        yes: function (index, layero) {
                            $('#user-add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#user-add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的用户');
                    } else {
                        febs.modal.confirm('删除用户', '确定删除该用户?', function () {
                            var userIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                userIds.push(item.userId)
                            });
                            deleteUsers(userIds.join(','));
                        });
                    }
                }
                if (name === 'reset') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要重置密码的用户');
                    } else {
                        var usernames = [];
                        layui.each(checkStatus.data, function (key, item) {
                            usernames.push(item.username)
                        });
                        febs.post(ctx + 'user/password/reset/' + usernames.join(','), null, function () {
                            febs.alert.success('所选用户密码已重置为1234qwer');
                        });
                    }
                }
                if (name === 'export') {
                    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    febs.download(ctx + 'user/excel', params, '用户信息表.xlsx');
                }
            },
            options: [{
                name: 'add',
                title: '新增用户',
                perms: 'user:add'
            }, {
                name: 'delete',
                title: '删除用户',
                perms: 'user:delete'
            }, {
                name: 'reset',
                title: '密码重置',
                perms: 'user:password:reset'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: 'user:export'
            }]
        });
 
        // 下拉框选择器
        treeSelect.render({
            elem: $view.find('#dept'),
            type: 'get',
            data: ctx + 'dept/select/tree',
            placeholder: '请选择',
            search: false
        });
 
        // 初始化表格操作栏各个按钮功能
        table.on('tool(userTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.view('用户信息', 'system/user/detail/' + data.username, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }
            if (layEvent === 'del') {
                febs.modal.confirm('删除用户', '确定删除该用户?', function () {
                    deleteUsers(data.userId);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改用户', 'system/user/update/' + data.username, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    offset: '30px',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#user-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });
 
        // 查询按钮
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
 
        // 刷新按钮
        $reset.on('click', function () {
            $searchForm[0].reset();
            treeSelect.revokeNode('dept');
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });
 
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'userTable',
                url: ctx + 'member/getList',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'account', title: '用户姓名', minWidth: 150, align: 'center'},
                    {field: 'phone', title: '手机号', minWidth: 165},
                    {field: 'email', title: '邮箱', minWidth: 200},
                    {field: 'inviteId', title: '邀请码'},
                    {field: 'refererId', title: '上级邀请码'},
                    {field: 'contractTotal', title: '合约资产', minWidth: 120},
                    {field: 'coinTotal', title: '币币资产', minWidth: 120},
                    {field: 'agentTotal', title: '佣金资产', minWidth: 120},
                    // {title: '账号类型', templet: '#account-type'},
                    {title: '账号状态', templet: '#account-status'},
                    {title: '审核状态', templet: '#certify-status'},
                    {field: 'createTime', title: '注册时间', minWidth: 180}
                ]]
            });
        }
 
        // 获取查询参数
        function getQueryParams() {
            var createTime = $searchForm.find('input[name="createTime"]').val();
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            return {
                startTimeDate: createTimeFrom,
                endTimeDate: createTimeTo,
                account: $searchForm.find('input[name="account"]').val().trim(),
                accountStatus: $searchForm.find("select[name='accountStatus']").val(),
                accountType: $searchForm.find("select[name='accountType']").val(),
                certifyStatus: $searchForm.find("select[name='certifyStatus']").val(),
                invalidate_ie_cache: new Date()
            };
        }
 
        function deleteUsers(userIds) {
            var currentUserId = currentUser.userId + '';
            if (('' + userIds).split(',').indexOf(currentUserId) !== -1) {
                febs.alert.warn('所选用户包含当前登录用户,无法删除');
                return;
            }
            febs.get(ctx + 'user/delete/' + userIds, null, function () {
                febs.alert.success('删除用户成功');
                $query.click();
            });
        }
    })
</script>