marketing.PromotionCode.Edit.js
7.6 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
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
webpackJsonp([86],{
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
var $ = __webpack_require__(1);
var edit = __webpack_require__(6);
var common = __webpack_require__(2);
var couponBean = __webpack_require__(61);
var e = new edit("#basicForm");
var type = $("#basicForm").attr("role");//类型
var userSourceLimit = [];
var userTypeLimit = [];
/**
* 监听输入值的变化
*/
$(document).on("change", ".observe", function () {
var $this = $(this);
var name = $this.data("field");
couponBean = common.util.__buildobj(name, '.', couponBean, function (obj, name) {
obj[name] = $this.val();
});
});
if (type == "info") {
e.on("render", function () {
$("input:text", "#basicForm")
.add("select", "#basicForm")
.add(":radio", "#basicForm")
.add(":checkbox", "#basicForm").prop("disabled", true);
$("textarea", "#basicForm").prop("disabled", true);
$(".panel-footer").hide();
});
}
/**
* 全局对象
*/
var Bll = {
validateCode: function () {
var result = false;
$.ajax({
type: 'POST',
url: '/market/coupon/checkPromotionCode',
async: false,
data: {
code: $("#code").val()
},
dataType: 'json'
}).then(function (data) {
if (data.code == "200") {
var badcode = [];
if (data.data.length > 0) {
$.each(data.data, function (index, item) {
if (item.flag == "1") {
badcode.push(item.code);
}
});
if (badcode.length > 0) {
result = "" + badcode.join(",") + "重复";
} else {
result = true;
return result;
}
} else {
result = true;
return result;
}
}
// result = "" + badcode.join(",") + "重复";
}, function () {
result = "检查优惠码,网络发生异常";
});
return result;
},
__render: function (item, type) {//渲染界面
$("#basicForm").html(common.util.__template2($("#promotionCode-template").html(), item));
e.init();
startTimeObj = $("#startTime").datetimepicker({
timeFormat: 'HH:mm:ss',
showSecond: true
}).data("datepicker");
endTimeObj = $("#endTime").datetimepicker({
timeFormat: 'HH:mm:ss',
showSecond: true
}).data("datepicker");
new common.dropDown({el: '#filter-couponType'});
new common.dropDown({el: '#filter-department'});
}
};
//详情页 不可改
if (type == "add") {
Bll.__render(couponBean, "add");
} else {
var id = location.href.substring(location.href.lastIndexOf("/") + 1);
common.util.__ajax(
{
url: "/market/coupon/getPromotionCode",
data: {id: id}
}, function (res) {
couponBean = res.data;
var reqDepartment = couponBean.reqDepartment.split('/');
couponBean.department1 = reqDepartment[0];
couponBean.department2 = reqDepartment[1];
var promotionInfo = JSON.parse(couponBean.promotionInfo);
couponBean.promotionInfotype = promotionInfo.type;
couponBean.amount_at_least = promotionInfo.condition.amount_at_least;
couponBean.count_at_least = promotionInfo.condition.count_at_least;
couponBean.discount = promotionInfo.action.discount;
couponBean.discount_at_most = promotionInfo.action.discount_at_most;
if (couponBean.userSourceLimit) {
userSourceLimit = couponBean.userSourceLimit.split('|');
for (var i = 0; i < userSourceLimit.length; i++) {
var custom = "custom-" + userSourceLimit[i];
$("input ." + custom).attr("checked", "checked");
}
}
if (couponBean.userTypeLimit) {
userTypeLimit = couponBean.userTypeLimit.split('|');
for (var i = 0; i < userTypeLimit.length; i++) {
var custom = "userTypeLimit-" + userTypeLimit[i];
$("input ." + custom).attr("checked", "checked");
}
}
Bll.__render(couponBean, type);
}, true);
}
e.init();
/**
* 用户身份
*/
$(document).on("click", "input[name='userTypeLimit']", function () {
if ($(this).is(':checked')) {
userTypeLimit.push($(this).val());
} else {
for (var i = 0; i < userTypeLimit.length; i++) {
if ($(this).val() == userTypeLimit[i]) {
userTypeLimit.splice(i, 1)
}
}
}
couponBean.userTypeLimit = userTypeLimit.join("|");
});
/**
* 用户来源
*/
$(document).on("click", "input[name='userSourceLimit']", function () {
if ($(this).is(':checked')) {
userSourceLimit.push($(this).val());
} else {
for (var i = 0; i < userSourceLimit.length; i++) {
if ($(this).val() == userSourceLimit [i]) {
userSourceLimit.splice(i, 1)
}
}
}
couponBean.userSourceLimit = userSourceLimit.join("|");
});
/**
* 优惠类型
*/
$(document).on('change', "input[name=promotionInfotype]", function () {
var $checked = $(this);
var $discount = $("#discount");
if ($checked.val() == "3") {
$discount.prop("disabled", true).val("0.0").parent("#resultdiscount").hide();
} else {
$discount.prop("disabled", false).parent("#resultdiscount").show();
}
});
/**
* 保存事件
*/
$(document).on("click", "#save_brand", function () {
var promotionInfo = {
type: couponBean.promotionInfotype,
condition: {
amount_at_least: couponBean.amount_at_least,
count_at_least: couponBean.count_at_least
},
action: {
discount: couponBean.discount,
discount_at_most: couponBean.discount_at_most
}
};
couponBean.promotionInfo = JSON.stringify(promotionInfo);
couponBean.reqDepartment = [couponBean.department1, couponBean.department2].join('/');
var url = $("#basicForm").data("action");
var flag = true;
if (type == "add") {
flag = Bll.validateCode();
}
if (e.validate()) {
if (flag == true) {
common.util.__ajax({
url: url,
data: couponBean
}, function () {
window.location = "/market/coupon/index";
});
} else {
common.util.__tip(Bll.validateCode(), 'warning')
}
}
return false;
});
/***/ },
/***/ 61:
/***/ function(module, exports) {
/**
* Created by yoho on 2016/6/27.
*/
var promotionCode = {
id: "",
name: "",
limitTimes: "0",
code: "",
describe: "",
promotionInfo: 1,
userSourceLimit: "",
userTypeLimit: "",
creatorId: "",
limitDateFrom: "",
limitDateTo: 0,
createTime: "",
reqDepartment: "零售部/营销策划",
staff: "admin",
status: "0",
department1: "零售部",
department2: "营销策划",
"amount_at_least": "",
"count_at_least": "",
"discount": "",
"discount_at_most": "",
"promotionInfotype": 1
};
module.exports = promotionCode;
/***/ }
});