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
| /**
| * 门禁部门
| */
| $(function(){
| $('#test-table').bootstrapTable('destroy')
| $('#test-table').bootstrapTable({
| method : 'GET',
| url: "group/groupList.action",
| cache : false,
| striped : true,
| pagination : true, //在表格底部显示分页工具栏
| pageSize : 5, //默认每页条数
| pageNumber : 1, //默认分页
| pageList : [ 10, 20, 50, 100, 200, 500 ],//分页数
| showColumns : false, //显示隐藏列
| showRefresh : false, //显示刷新按钮
| showExport : false,
| toolbar:"#toolbar",
| singleselect : true,
| clickToSelect: true, // 单击行即可以选中
| search : false,//显示搜素表单
| silent : true, //刷新事件必须设置
| sidePagination : "server", //表示服务端请求
| columns : [ {
| field : "f_GroupID",
| title : "部门ID",
| class : 'col-md-1',
| align : "center",
| valign : "middle",
| sortable : "true"
| }, {
| field : "f_GroupName",
| title : "部门名称",
| align : "center",
| valign : "middle",
| sortable : "true"
| }, {
| field : "f_GroupNO",
| title : "部门描述",
| align : "center",
| valign : "middle",
| sortable : "true"
| }, {
| field: 'operate',
| title: '操作',
| class : 'col-md-2',
| align: 'center',
| valign: 'middle',
| formatter: operateFormatter,
| }],
| queryParamsType: "undefined",
| queryParams: function queryParams(params) { //设置查询参数
| var param = {
| pageNumber: params.pageNumber,
| pageSize: params.pageSize,
| // searchText: params.searchText
| };
| return param;
| },
| formatLoadingMessage : function() {
| return "请稍等,正在加载中...";
| },
|
| formatNoMatches : function() {
| return '无符合条件的记录';
| },
| //注册加载子表的事件。注意下这里的三个参数!
| onExpandRow: function (index, row, $detail) {
| oInit.InitSubTable(index, row, $detail);
| }
|
| });
| });
|
| function operateFormatter(value, row, index) {
| return [
| '<button type="button" class=" btn btn-info" onclick="getvalue('+row.f_GroupID+')">修改</button>',
| ' <button class=" btn btn-danger" type="button" onclick="delGroup('+row.f_GroupID+')">删除</button>'
| ].join('');
| }
|
| function formValidator(){
| $("#addForm").bootstrapValidator({
| message: 'This value is not valid',
| feedbackIcons: {
| valid: 'glyphicon glyphicon-ok',
| invalid: 'glyphicon glyphicon-remove',
| validating: 'glyphicon glyphicon-refresh'
| },
|
| fields:{
| // dept_desc:{
| // message: '部门名称验证失败',
| // validators:{
| // notEmpty:{
| // message:'部门描述不能为空'
| // },
| // stringLength:{
| // max:200,
| // message:'字符长度不能超过200'
| // }
| // }
| // },
| f_GroupName:{
| message: '部门名称验证失败',
| validators:{
| notEmpty:{
| message:'部门名称不能为空'
| },
| stringLength:{
| max:20,
| message:'字符长度不能超过20'
| }
| }
| }
| }
| });
|
| $("#myform").bootstrapValidator({
| message: 'This value is not valid',
| feedbackIcons: {
| valid: 'glyphicon glyphicon-ok',
| invalid: 'glyphicon glyphicon-remove',
| validating: 'glyphicon glyphicon-refresh'
| },
|
| fields: {
| f_GroupID:{
| message: '部门ID验证失败',
| validators: {
| notEmpty: {
| message: '部门ID不能为空'
| }
| }
| },
| f_GroupName:{
| validators:{
| notEmpty:{
| message:'部门名称不能为空'
| },
| stringLength: {
| max: 20,
| message: '字符长度不能超过20'
| }
| }//,
| // dept_desc:{
| // validators:{
| // notEmpty:{
| // message:'部门描述不能为空'
| // },
| // stringLength:{
| // max:200,
| // message:'字符长度不能超过200'
| // }
| // }
| // },
| }
| }
| });
| }
| //表单验证
| $(function(){
| formValidator();
|
| });
|
| //添加部门,打开模态框
| function addGroup(){
| $("#addDlg").modal('show');
| }
|
| // 提交部门
| function insertGroup(){
| var name=$("#f_GroupName1").val();
| $.ajax({//部门名称唯一验证
| url:'group/valid.action',
| dataType:'json',
| type:'post',
| data:{name:name},
| success:function(data){
| if(data.i>0){
| if($("#addForm").data('bootstrapValidator').validate().isValid()){
| $.ajax({
| url:'group/addGroup.action',
| type:'post',
| dataType:'json',
| data:$("#addForm").serialize(),
| success:function(info){
| if(info>0){
| alert("添加成功");
| }else{
| alert("添加失败");
| }
| $("#test-table").bootstrapTable('refresh');
| $("#addDlg").modal('hide');
| $("#f_GroupName1").val("");
| $("#f_GroupNO").val("");
| },
| error:function(){
| alert('请求失败');
| }
| });
| }else{
| return false;
| }
| }else{
| $("#info").text(data.msg);
| }
| },
| error:function(){
| alert("请求失败");
| }
| });
| }
|
|
| //打开模态框,数据回写
| function getvalue(id){
| $.ajax({
| url:'group/groupById.action',
| type:'post',
| dataType:'json',
| data:{did:id},
| success:function(data){
| $("#f_GroupID").val(data.f_GroupID);
| $("#f_GroupName").val(data.f_GroupName);
| $("#f_GroupNO").val(data.f_GroupNO);
| },
| error:function(){
| alert("请求失败");
| }
| });
| $("#mydlg").modal("show");
| }
| //保存修改内容
| function upGroup(){
| var name=$("#f_GroupName").val();
| var id=$("#f_GroupID").val();
| $.ajax({//部门名称唯一验证
| url:'group/valid.action',
| dataType:'json',
| type:'post',
| data:{name:name,id:id},
| success:function(data){
| if(data.i>0){
| if($("#myform").data('bootstrapValidator').validate().isValid()){
| $.ajax({
| url:'group/upGroup.action',
| type:'post',
| dataType:'json',
| data:$("#myform").serialize(),
| success:function(data){
| if(data>0){
| alert("修改成功");
| }else{
| alert("修改失败");
| }
| $("#test-table").bootstrapTable('refresh');
| $("#mydlg").modal("hide");
| },
| error:function(){
| alert("请求失败");
| }
| });
| }else{
| return false;
| }
| }else{
| $("#infos").text(data.msg);
| }
| },
| error:function(){
| alert("请求失败");
| }
| });
| }
| //关闭模态框
| function closedlg(){
| $("#mydlg").modal("hide");
| $("#addDlg").modal("hide")
| $("#info").text("");
| $("#infos").text("");
|
| $('#myform').data('bootstrapValidator', null);
| $("#addForm").data('bootstrapValidator',null);
| formValidator();
| //$('#mydlg').data('bootstrapValidator').resetForm(true);
| $("input[type=reset]").trigger("click");
|
|
| }
|
| //单个删除
| function delGroup(id){
| if(confirm('您确定要删除这条数据吗')){
| $.ajax({
| url:'group/delGroup.action',
| type:'post',
| dataType:'json',
| data:{did:id},
| success:function(data){
| if(data>0){
| alert("删除成功");
| }else{
| alert("删除失败");
| }
| $("#test-table").bootstrapTable('refresh');
| },
| error:function(){
| alert("请求失败");
| }
| });
| }
| }
|
|