admin.js
4.0 KB
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
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'auth/admin/index',
add_url: 'auth/admin/add',
edit_url: 'auth/admin/edit',
del_url: 'auth/admin/del',
multi_url: 'auth/admin/multi',
}
});
var table = $("#table");
//在表格内容渲染完成后回调的事件
table.on('post-body.bs.table', function (e, json) {
$("tbody tr[data-index]", this).each(function () {
if (parseInt($("td:eq(1)", this).text()) == Config.admin.id) {
$("input[type=checkbox]", this).prop("disabled", true);
}
});
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
columns: [
[
{field: 'state', checkbox: true, },
{field: 'id', title: 'ID'},
{field: 'username', title: __('Username')},
{field: 'nickname', title: __('Nickname')},
{field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
{field: 'email', title: __('Email')},
{field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
{field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:
[
{
text: '代理地区',
title: '代理地区',
icon: 'fa fa-list',
classname: 'btn btn-xs btn-primary btn-dialog',
url: 'admin_area/index?admin_id={id}',
extend: 'data-area=\'["80%","80%"]\'',
visible: function(row){
var group = row.groups.split(',');
if($.inArray("1", group) === -1 && $.inArray("6", group) !== -1 || $.inArray("7", group) !== -1){
return true;
}
}
}
],formatter: function (value, row, index) {
if(row.id == Config.admin.id){
return '';
}
return Table.api.formatter.operate.call(this, value, row, index);
}}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Form.api.bindevent($("form[role=form]"));
Controller.api.change();
},
edit: function () {
Form.api.bindevent($("form[role=form]"));
Controller.api.change();
setTimeout(function () {
$('select[name="group[]"]').trigger("change");
}, 100);
},
api: {
change: function () {
$('select[name="group[]"]').change(function () {
var group = $(this).val();
if($.inArray("1", group) === -1 && $.inArray("6", group) !== -1 || $.inArray("7", group) !== -1){
$('#store_num').show();
$("form[role=form]").validator("setField", "#c-store_num", "required;");
}else{
$('#store_num').hide();
$("form[role=form]").validator("setField", "#c-store_num", null);
}
})
}
}
};
return Controller;
});