coupon-edit.js
5.87 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
var $ = require('jquery');
var edit=require('../common/edit');
var e=new edit("#basicForm");
var type=$("#basicForm").attr("role");
if(type=="info"){
e.on("render",function(){
$("input:text","#basicForm")
.add("select","#basicForm")
.add(":radio","#basicForm")
.add(":checkbox","#basicForm").prop("disabled",true);
$(".panel-footer").hide();
});
}
//渲染优惠详情
e.on("render",function(){
if($("#promotionInfo").val()){
var __promotionInfo = JSON.parse($("#promotionInfo").val());
$("#promotionInfo-type").val(__promotionInfo["type"]);
$("#promotionInfo-condition-amount_at_least").val(__promotionInfo["condition"]["amount_at_least"]);
$("#promotionInfo-condition-count_at_least").val(__promotionInfo["condition"]["count_at_least"]);
$("#promotionInfo-action-discount").val(__promotionInfo["action"]["discount"]);
$("#promotionInfo-action-discount_at_most").val(__promotionInfo["action"]["discount_at_most"]);
if ($("#promotionInfo-type").val() == "3") {
$("#resultdiscount").hide();
}
}
});
e.on("render",function(){
if($("#reqDepartment").val()){
var departmentArr = String.prototype.split.call($("#reqDepartment").val(), '/'),
$department1 = $("#department1"),
$department2 = $("#department2");
$department1.val(departmentArr[0]);
if (departmentArr[1]) {
$department2.val(departmentArr[1]).show();
} else {
$department2.hide();
}
}
});
e.on("bind",function(){
if($("#reqDepartment").val()){
var departmentArr = String.prototype.split.call($("#reqDepartment").val(), '/'),
$department1 = $("#department1"),
$department2 = $("#department2");
$("select").change(function() {
if ($(this).is($department1)) {
departmentArr.length = 0;
departmentArr[0] = $(this).val();
if ($(this).val() === "零售运营部") {
$department2.show();
departmentArr[1] = $department2.val();
} else {
$department2.hide();
}
} else {
departmentArr[1] = $(this).val();
}
$("#reqDepartment").val(departmentArr.join('/'));
});
}
});
e.on("bind",function(){
$discount = $("#promotionInfo-action-discount");
$("input:radio[name=promotionInfo-type]").change(function(){
var $checked=$(this);
if ($checked.prop("name") == "promotionInfo-type") {
if ($checked.val() == "3") {
$discount.prop("disabled", true).val("0.00").parents("#resultdiscount").hide();
} else {
$discount.prop("disabled", false).parents("#resultdiscount").show();
}
}
});
});
//添加需要验证
if(type=="add"){
e.on("validate",function(){
function validatecode(){
var result=false;
$.ajax({
type: 'POST',
url: '/market/coupon/checkPromotionCode',
async:false,
data: {
code:$("#code").val()
},
dataType: 'json'
}).then(function(data) {
console.log(data);
data = data.data;
if (data.code == "200") {
var badcode = [];
$.each(data.data, function(index, item) {
if (item.flag == "1") {
badcode.push(item.code);
}
});
if (badcode.length == 0) {
result=true;
return result;
}
}
result=""+badcode.join(",")+"重复";
}, function() {
result="检查优惠码,网络发生异常";
});
return result;
}
return validatecode();
});
}
e.init();
//提交
var submit=function(callback){
e.submit($("#basicForm").attr("action"),function(option){
option.success=function(res){
res=res.data;
if(res.code=="200"){
e.$tip('提交成功',function(){
location.href="/market/coupon/index";
},'growl-success');
}else{
e.$tip(res.message);
}
return false;
},
option.error=function(res){
e.$tip("提交失败");
}
callback&&callback(option.data);
});
};
$("#save_brand").click(function(){
var promotionInfo={
type:$("input:checked[name=promotionInfo-type]").val(),
condition:{
amount_at_least:$("#promotionInfo-condition-amount_at_least").val(),
count_at_least:$("#promotionInfo-condition-count_at_least").val()
},
action:{
discount:$("#promotionInfo-action-discount").val(),
discount_at_most:$("#promotionInfo-action-discount_at_most").val()
}
}
$("#promotionInfo").val(JSON.stringify(promotionInfo));
submit(function(data){
//修改数据
if(data.status=="2"){
data.status=0;
}
});
return false;
});