product.productBundle.Edit.js
8.32 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
webpackJsonp([144],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var $ = __webpack_require__(1), common = __webpack_require__(2);
var dropDown = new common.dropDown({
el: '#shop',
ajax: 'shopsRest'
});
var e = new common.edit('#editor-group');
e.on("validate", function () {
var discount = $("#discount").val();
if (!/^1|0\.[0-9]{0,2}$/.test(discount) || discount >= 1.0 || discount <= 0.0) {
return "折扣格式不正确";
}
var skns = '';
var iptSkns = $("input[name='productSkn']");
for (var i = 0, l = iptSkns.length; i < l; i++) {
var $thiz = $(iptSkns[i]);
var skn = $.trim($thiz.val());
if (/^[1-9][0-9]{4,10}$/.test(skn)) {
skns = skns + skn + ",";
} else if(skn.length != 0) {
return "第 " + (i + 1) + " 个 SKN 格式错误";
}
}
/*var lio = skns.lastIndexOf(",");
if (lio == -1) {
return "请填写商品 SKN";
}*/
// $("#productSkn").val(skns.substring(0, lio));
});
e.init();
if($("#id").val()){
var sknArray = $("#productSkn").val().split(",");
var shopName = $("#shopName").val();
$.each(sknArray,function(index,item){
$($("#budle-table").find("input[name='productSkn']")[index]).val(item);
})
$("#budle-table").find("input[name='bundleDiscount']").val($("#edit-discount").val());
$("#shopLable").text(shopName);
$("#discount, input[name=bundleDiscount], #shop").attr('disabled', 'disabled');
}
// submit
$('#add-btn').click(function(option) {
var bundleName = $("#bundleName").val();
if (bundleName == '') {
common.util.__tip('套餐名称必填', 'warning');
return false;
}
var startTime = toSeconds($("#beginTimeStr").val());
var endTime = toSeconds($("#endTimeStr").val());
if (!startTime || !endTime || startTime == '' || endTime == '') {
common.util.__tip('套餐有效时间必填', 'warning');
return false;
}
var flag = true;
// 判断每一行内的skn不能重复
$('#budle-table').find('tr').each(function(){
var sknArr = new Array();
$(this).find('input[name=productSkn]').each(function(index){
if ($(this).val() != '') {
sknArr.push($(this).val());
if (parseInt($(this).val()) != $(this).val()) {
common.util.__tip('不合法的SKN为' + $(this).val(), 'warning');
flag = false;
return;
}
}
})
var s = sknArr.join(",")+",";
for(var i=0;i<sknArr.length;i++) {
if(s.replace(sknArr[i]+",","").indexOf(sknArr[i]+",")>-1) {
common.util.__tip('重复的SKN为' + sknArr[i], 'warning');
flag = false;
break;
}
}
});
if (!flag) {
return false;
}
var shopId = $("#shopId").val();
var id = $("#id").val();
var bundleArray = [];
$("#budle-table").find("tr").each(function(){
var bundle = {};
var sknList = [];
$(this).find("input[name='productSkn']").each(function(){
if ($(this).val() && $(this).val()!= '') {
sknList.push($(this).val());
}
});
bundle.productSkn = sknList.join(",");
bundle.discount = $(this).find("input[name='bundleDiscount']").val();
bundle.bundleName=bundleName;
bundle.startTime=startTime;
bundle.endTime=endTime;
bundle.shopId=shopId;
bundle.id=id;
bundleArray.push(bundle);
})
$.ajax({
type: 'POST',
dataType: 'json',
url: '/product/bundle/save',
data: {"boListStr":JSON.stringify(bundleArray)},
success: function (rs) {
var data = rs;
// $('.historyDetail').html($(common.util.__template2($("#template2").html(), data.data)));
if(data.code == 200){
common.util.__tip(data.message, 'success');
history.go(-1)
}else{
var msg = data.message;
if (msg.indexOf(',') == -1) {
common.util.__tip(msg, 'warning');
} else {
msg = msg.substring(1, msg.length - 1);
common.util.__tip(msg.replace(/,/g, '<br/>').replace(/=/g, ' : '), 'warning');
}
}
},
error: function (rs) {
// $('.historyDetail').html($(common.util.__template2($("#template2").html(), {})));
common.util.__tip(rs.message, 'danger');
}
});
/*e.submit($('#add-form').attr('action'), function(option) {
var data = option.data;
// convert date
data.startTime = toSeconds(data.beginTimeStr);
data.endTime = toSeconds(data.endTimeStr);
option.beforeSend = function() {
$('#add-btn').addClass('disabled');
console.log(data);
data.zw="123";
// analyzeBundleTable();
};
option.success = function(res) {
if (res.code == "200") {
e.$tip('提交成功', function() {
location.href = "/product/bundle/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;
}
$(".add-bundle-btn").click(function() {
var bundleHtml = "";
bundleHtml += "<tr>";
bundleHtml += "<td>";
bundleHtml += "<input type=\"text\" name=\"productSkn\" value=\"\" style=\"margin-left:5px;width:23%\"><input name=\"productSkn\" type=\"text\" value=\"\" style=\"margin-left:9px;width:23%\">";
bundleHtml += "<input type=\"text\" name=\"productSkn\" value=\"\" style=\"margin-left:9px;width:23%\"><input name=\"productSkn\" type=\"text\" value=\"\" style=\"margin-left:9px;width:23%\"></td>";
bundleHtml += "<td align=\"center\"><input type=\"text\" name=\"bundleDiscount\" placeholder=\"折扣\" class=\"form-control\" required maxlength=\"10\" value=\"0.95\" style=\"width:40%;padding:4px;\">";
bundleHtml += "</td><td align=\"center\"><input class=\"btn btn-danger delete-bundle-btn\" type=\"button\" value=\"删除\" style=\"margin:5px\"></input>";
bundleHtml += "</td></tr> ";
$("#budle-table").append(bundleHtml);
$(".delete-bundle-btn").click(function() {
$(this).parent().parent().remove();
});
});
$("#shop").change(function(){
// console.log(dropDown.getValue().text);
$("#shopId").val(dropDown.getValue().id);
$("#shopLable").text(dropDown.getValue().text);
})
$("#discount").blur(function(){
var discount = $("#discount").val();
if (!/^1|0\.[0-9]{0,2}$/.test(discount) || discount >= 1.0 || discount <= 0.0) {
common.util.__tip("折扣格式不正确", 'warning');
return;
}
$("input[name='bundleDiscount']").each(function(){
$(this).val($("#discount").val());
})
})
// function analyzeBundleTable(){
// $("#budle-table").find("tr").each(function(){
// })
// }
//新版本控制
//$("#basicInfo").html(common.util.__template2($("#template2").html(),RESPONSEDATA));
// bundleTemplate
/*[
{"bundleDiscount":12,"bundleConfig":[{"skn":1234,"discount":0.9},{"skn":1234,"discount":"0.8"}]}
]*/
/*var bundleTemplateData = [];
*/
/***/ }
]);