Edit.js
2.45 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
97
var $ = require('jquery'), common = require('../../../common/common');
var e = new common.edit('#editor-group');
e.on("validate", function () {
if (new Date($("#beginTimeStr").val()).getTime() >= new Date($("#endTimeStr").val()).getTime()) {
return "开始时间必须小于结束时间";
}
var discount = $("#discount").val();
if (!/^1|0\.[0-9][0-9]$/.test(discount) || discount > 1.0) {
return "折扣格式不正确";
}
var skns = '';
$("input[name='productSkn']").each(function (index) {
var skn = $(this).val();
if (skn && skn.length > 1) {
skns = skns + skn + "/";
}
});
var lio = skns.lastIndexOf("/");
if (lio == -1) {
return "请填写商品 SKN";
}
$("#productSkn").val(skns.substring(0, lio));
});
e.init();
// submit
$('#add-btn').click(function(option) {
e.submit($('#add-form').attr('action'), function(option) {
var data = option.data;
// convert date
data.startTime = toSeconds(data.beginTimeStr);
data.endTime = toSeconds(data.endTimeStr);
data.popupPic = $("#popupPic").parent().find("img").attr("src");
option.beforeSend = function() {
$('#add-btn').addClass('disabled');
};
option.success = function(res) {
if (res.code == "200") {
e.$tip('提交成功', function() {
location.href = "/activity/yohocoin/index";
}, 'growl-success');
} else {
$('#add-btn').removeClass('disabled');
e.$tip(res.message);
}
return false;
}
option.error = function(res) {
e.$tip("提交失败");
};
});
});
$(".btn-up").click(function() {
var tr = $(this).parents("tr");
var ipt = tr.find("input[name='productSkn']");
var prev = tr.prev().find("input[name='productSkn']");
var val = ipt.val();
ipt.val(prev.val());
prev.val(val);
});
$(".btn-down").click(function() {
var tr = $(this).parents("tr");
var ipt = tr.find("input[name='productSkn']");
var next = tr.next().find("input[name='productSkn']");
var val = ipt.val();
ipt.val(next.val());
next.val(val);
});
function toSeconds(strDate) {
var seconds = new Date(strDate).getTime() / 1000;
return seconds;
}
$("#set_default_img").click(function() {
$("#popupPic").parent().find("img").attr("src", default_img);
});