-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_host_follower.html
executable file
·416 lines (335 loc) · 13.4 KB
/
add_host_follower.html
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="=IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--以上几个是必须的-->
<meta name="description" content="hello">
<meta name="author" content="test">
<link rel="shortcut icon" href="images/favicon.ico" />
<title>礼金录入</title>
<!--inport bootstrap-->
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="bootstrap-3.3.7/js/bootstrap.min.js"></script>
<!-- bootstrap-table-1.12.1 start -->
<link rel="stylesheet" href="bootstrap-table-1.12.1/dist/bootstrap-table.css">
<link rel="stylesheet" href="css/bootstrap-editable.css">
<script type="text/javascript" src="bootstrap-table-1.12.1/dist/bootstrap-table.js"></script>
<script type="text/javascript" src="bootstrap-table-1.12.1/dist/bootstrap-table-locale-all.js"></script>
<script type="text/javascript" src="bootstrap-table-1.12.1/docs/dist/extensions/editable/bootstrap-table-editable.js"></script>
<script src="js/bootstrap-editable.js"></script>
<script src="bootstrap-table-1.12.1/src/extensions/export/bootstrap-table-export.js"></script>
<script src="js/tableExport.js"></script>
<!-- bootstrap-table-1.12.1 end -->
<!-- Custom styles for this template -->
<link href="signin.css" rel="stylesheet">
</head>
<body style="background-color: #444141">
<div class="container" style="background-color: #ffffff">
<div class="container">
<div id="toolbar">
<!-- Button trigger modal -->
<button type="button" id="hostbtn" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#hostModal">
<i class="glyphicon glyphicon-queen">主人</i>
</button>
<button type="button" id="followerbtn" disabled class="btn btn-primary btn-sm" data-toggle="modal" data-target="#followModal">
<i class="glyphicon glyphicon-plus">增加</i>
</button>
</div>
<table id="table" data-toolbar="#toolbar">
</table>
<button class="btn-warning">确认提交</button>
</div>
<script>
var $table = $("#table"),
id = 1,
hostName = "",
hostAddr = "";
function initTable(){
$table.bootstrapTable({
//height: getHeight(),
//url: 'dataj.json',
method: 'get',
// dataType: "json",
// data_locale: 'zh-CN',
undefinedText: "暂无数据", //当数据为 undefined 时显示的字符
// search: true,
showRefresh: true,
showColumns: true,
mininumCountColumns: 2,
showExport: true,
columns: [
[{
title: "测试以下标题栏",
colspan: 4,
align: 'center'
}],
[{
title: "序号",
field: 'id',
align: 'center',
valign: 'midddle',
sortable: true,
}, {
title: "姓名",
field: 'full_name',
align: 'center',
valign: 'midddle',
editable: {
type: 'text',
title: '修改姓名',
disabled: false,
mode: "inline",
validate: function (value){
if(!value){
return '必须输入姓名,不能为空'
}
},
update: function(e, editable){
alert('new value: '+ editable.value);
}
}
}, {
title: "金额",
field: 'money',
align: 'center',
valign: 'midddle',
sortable: true,
editable: {
type: 'text',
title: '修改金额',
disabled: false,
mode: "inline",
validate: function (value){
if(!value){
return '必须输入金额,不能为空'
}
},
update: function(e, editable){
alert('new value: '+ editable.value);
}
}
}, {
field: 'operation',
title: '操作',
align: 'center',
events: operateEvents, //给按钮注册事件
formatter: addFunctionAlty //表格中增加按钮</span>
}]
],
//编辑时触发
onEditableSave: function (field, row, oldValue, $el) {
$table.bootstrapTable("resetView");
$.ajax({
type: "post",
url: "update.php",
data: row,
dataType: 'JSON',
success: function (data, status) {
if (status == "success") {
alert(JSON.stringify(data))
}
},
error: function () {
alert('编辑失败');
},
complete: function () {
}
});
}
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 修改按钮、删除按钮
function addFunctionAlty(value, row, index) {
return [
'<a style="color:red" class="remove" id="btn_delete" href="javascript:void(0)" title="删除">',
'<i class="glyphicon glyphicon-remove"></i>',
'</a>'
].join('');
}
window.operateEvents = {
// 点击删除按钮执行的方法
'click #btn_delete': function(e, value, row, index) {
// 写自己的方法。。。
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(function() {
var scripts = [
location.search.substring(1) || 'bootstrap-table-1.12.1/src/bootstrap-table.js',
'bootstrap-table-1.12.1/src/extensions/export/bootstrap-table-export.js',
'bootstrap-table-1.12.1/src/extensions/editable/bootstrap-table-editable.js',
],
eachSeries = function(arr, iterator, callback) {
callback = callback || function() {};
if (!arr.length) {
return callback();
}
var completed = 0;
var iterate = function() {
iterator(arr[completed], function(err) {
if (err) {
callback(err);
callback = function() {};
} else {
completed += 1;
if (completed >= arr.length) {
callback(null);
} else {
iterate();
}
}
});
};
iterate();
};
eachSeries(scripts, getScript, initTable);
$("#host_ok").click(function(){
hostName = $("#hostName").val();
hostAddr= $("#hostAddr").val();
var money = $("#hostMoney").val();
var per = {
'id': id,
'full_name': hostName,
'money': money
};
var cdata = {
'id': id,
'full_name': hostName,
'host_name': hostName,
'money': money,
'addr': hostAddr
};
alert(JSON.stringify(cdata));
var row = [];
row.push(per);
$table.bootstrapTable('append', row);
$("#hostbtn").attr("disabled", true);
$("#followerbtn").attr("disabled", false);
id = id + 1;
$.ajax({
type: "post",
url: "insert_host_follower.php",
data: cdata,
dataType: 'JSON',
success: function(data, status){
if('success' == status){
alert(JSON.stringify(data));
}
},
error: function(){
alert('提交数据失败');
},
complete: function(){
}
});
$("#hostModal").modal('hide');
});
$("#follower_ok").click(function(){
var name = $("#followName").val();
var money = $("#followMoney").val();
var per = {
'id': id,
'full_name': name,
'money': money
};
alert(JSON.stringify(per));
var row = [];
row.push(per);
$table.bootstrapTable('append', row);
var cdata = {
'id': id,
'full_name': name,
'host_name': hostName,
'money': money,
'addr': hostAddr
};
id = id + 1;
$.ajax({
type: "post",
url: "insert_host_follower.php",
data: cdata,
dataType: 'JSON',
success: function(data, status){
if('success' == status){
alert(JSON.stringify(data));
}
},
error: function(){
alert('提交数据失败');
},
complete: function(){
}
});
$("#followModal").modal('hide');
});
});
function getScript(url, callback) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = url;
var done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState ||
this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
if (callback)
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
}
};
head.appendChild(script);
// We handle everything using the script element injection
return undefined;
}
</script>
<!-- Modal -->
<div class="modal fade bs-example-modal-sm" id="hostModal" tabindex="-1" role="dialog" aria-labelledby="hostModalLabel">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="hostModalLabel">设置主人家信息</h4>
</div>
<div class="modal-body">
<form>
<input type="text" id = "hostName" class="form-control" placeholder="姓名">
<input type="text" id = "hostAddr" class="form-control" placeholder="来自哪里">
<input type="text" id = "hostMoney" class="form-control" placeholder="金额">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" id = "host_ok" class="btn btn-primary">确认提交</button>
</div>
</div>
</div>
</div>
<div class="modal fade bs-example-modal-sm" id="followModal" tabindex="-1" role="dialog" aria-labelledby="followModalLabel">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="followModalLabel">添加跟来人信息</h4>
</div>
<div class="modal-body">
<form>
<input type="text" id = "followName" class="form-control" placeholder="姓名">
<input type="text" id = "followMoney" class="form-control" placeholder="金额">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" id = "follower_ok" class="btn btn-primary">确认提交</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>