Add.js
2.71 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
98
99
100
101
102
103
/**
* Created by jiangmin on 16/5/26.
* 品牌发券管理
*/
var $ = require('jquery');
common = require('../../../common/common');
var activity = require('./../partials/Activity');
var startTimeObj;
var endTimeObj;
var e1 = new common.edit2("#basicForm");
/**
* 监听输入值的变化
*/
$(document).on("change", ".observe", function () {
var $this = $(this);
var name = $this.data("field");
activity = common.util.__buildobj(name, '.', activity, function (obj, name) {
obj[name] = $this.val();
});
});
//通用对象
var Bll = {
//渲染界面
render: function () {
$("#basicForm").html(common.util.__template2($("#couponListAdd-template").html(), activity));
Bll.__editRender();
},
//转换时间格式
getTime: function (time) {
var t = new Date(time * 1000);
return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
},
//验证
__editRender: function () {
e1.init();
new common.dropDown({
el: "#filter-activityType"
});
startTimeObj = $("#startTime").datetimepicker({
timeFormat: 'HH:mm:ss',
showSecond: true
}).data("datepicker");
endTimeObj = $("#endTime").datetimepicker({
timeFormat: 'HH:mm:ss',
showSecond: true
}).data("datepicker");
e1.on("file_onComplete", function (obj) {
var names = obj.field;
activity = common.util.__buildobj(names, '.', activity, function (o, name) {
o[name] = obj.data;
});
});
}
};
Bll.render();
/*添加一行*/
$(document).on("click", ".addBtn", function () {
activity.couponIds.push({
"id": ""
});
Bll.render();
});
/**
* 删除行
*/
$(document).on("click", ".delBtn", function () {
var index = $(this).data("index");
if (activity.couponIds.length <= 1) {
common.util.__tip("至少有一张优惠券", "warning")
}
else {
activity.couponIds.splice(index, 1);
Bll.render();
}
});
/**
* 保存
*/
$(document).on('click', "#save_brand", function () {
var ids = [];
if (activity.couponIds.length > 0) {
for (var index in activity.couponIds) {
ids.push(activity.couponIds[index].id)
}
}
if (ids.length > 0) {
activity.couponId = ids.join(",");
}
activity.startTime = ((new Date(activity.startTime).getTime())) / 1000 || "";
activity.endTime = ((new Date(activity.endTime).getTime())) / 1000 || "";
if (e1.validate()) {
common.util.__ajax({
url: "/couponActivity/add",
data: activity
}, function () {
location.href = "/couponActivity/index";
})
}
});