guochao-option.page.js
1.49 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
require('admin/coupon-option.page.css');
require('bootstrap-daterangepicker');
require('bootpag/lib/jquery.bootpag.min');
function bindEditPageEvent() {
function packInfo() {
let resData = {};
let error;
$('.form-imput').each(function() {
let $this = $(this);
let val = $this.val();
let data = $this.data();
if (!val && !error) {
error = data.empty || `请填写${data.type}`;
}
resData[data.type] = val;
});
if (error) {
alert(error);// eslint-disable line
return;
}
resData.place = $('input[name=place]:checked').val();
return resData;
}
function radioInit() {
let place = parseInt($('#place').val());
if (place) {
$($('input[name=place]')[1]).attr('checked', true);
} else {
$($('input[name=place]')[0]).attr('checked', true);
}
}
radioInit();
$('.btn-save').on('click', function() {
let info = packInfo();
if (!info || window.saveing) {
return;
}
window.saveing = true;
$.ajax({
method: 'post',
url: '/admin/api/guochao/update',
contentType: 'application/json',
data: JSON.stringify(info)
}).then(() => {
window.saveing = false;
alert('保存成功');
});
});
}
(function() {
bindEditPageEvent();
}());