settled.js
10.4 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/**
* 商家入驻
* @author: xuqi<qi.xu@yoho>
* @date: 2016/3/24
*/
var $ = require('yoho-jquery');
var reg = require('../passport/mail-phone-regx'),
dialog = require('../common/dialog'),
Alert = dialog.Alert;
require('yoho-jquery-placeholder');
require('../plugins/jquery.qupload');
// 入口页
(function() {
var $mask,
$dialog;
if ($('.settled-page').length === 0) {
return;
}
$mask = $('#mask');
$dialog = $('#notice-container');
function showNotice() {
var wh = $(window).height();
$mask.removeClass('hide');
$dialog.css({
'max-height': wh - 60
}).removeClass('hide');
}
function hideNotice() {
$mask.addClass('hide');
$dialog.addClass('hide');
}
$('#fake-link').click(showNotice);
$('#fake-close').click(hideNotice);
$('#mask').click(hideNotice);
}());
// 申请页
(function() {
var $otherBr,
$otherNp,
$otherRp,
$categoryUl,
$shopListTr,
$shops,
$panel;
var $postcode,
$email,
$phoneNum,
$upKey,
$styleCount;
var categoryHtml = $('#category-tpl').html();
var Dialog = require('../common/dialog').Dialog;
var successDialog,
SWFUpload = window.SWFUpload,
upKey;
if ($('.settled-apply-page').length < 0) {
return;
}
$('[placeholder]').placeholder();
$otherBr = $('#other-brand-relation');
$otherNp = $('#other-new-period');
$otherRp = $('#other-replenishment-period');
$categoryUl = $('#category-list');
$shopListTr = $('#shop-list');
$shops = $('#shops');
$panel = $('#mask, #submit-success');
$postcode = $('#postcode');
$email = $('#email');
$phoneNum = $('#phone-number');
$upKey = $('#upload-key');
$styleCount = $('#style-count');
upKey = $upKey.val();
$upKey.remove();
function initUpload(arr) {
$.each(arr, function(k, v) {
$('#' + v.dom).qupload({
uploadKey: upKey,
button_image_url: '',
button_text: '<span class="btn_upload_text">上传</span>',
button_text_style:
'.btn_upload_text{color:#000;margin-left:30px;' +
'line-height: 2em;font-size:14px;}',
button_text_left_padding: 32,
button_text_top_padding: 8,
button_width: 160,
button_height: 35,
button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE, // 单选
file_size_limit: '10240',
file_types: v.type,
uploadSuccessed: function(serverData) {
var data = JSON.parse(serverData);
if (data.code !== 12) {
new Alert(data.message).show();
return false;
}
v.callback(data.data.hit.Filedata.return_file_path);
}
});
});
}
function validate() {
var pass = true,
postcodeReg = /[0-9]\d{5}(?!\d)/,
emailReg = reg.emailRegx,
phoneReg = reg.phoneRegx['+86'],
styleCountReg = /^(0|[1-9][0-9]*)$/;
$('.va, .category-item select, .for-other, .category-item').removeClass('error');
$('.va-null').each(function() {
if ($(this).val() === '') {
$(this).addClass('error');
pass = false;
}
});
if ($postcode.val() === '' || !postcodeReg.test($postcode.val())) {
$postcode.addClass('error');
pass = false;
}
if ($email.val() === '' || !emailReg.test($email.val())) {
$email.addClass('error');
pass = false;
}
if ($phoneNum.val() === '' || !(phoneReg.test($phoneNum.val()))) {
$phoneNum.addClass('error');
pass = false;
}
if ($styleCount.val() === '' || !(styleCountReg.test($styleCount.val()))) {
$styleCount.addClass('error');
pass = false;
}
$('.category-item').each(function() {
if ($(this).get(0).selectedIndex === 0) {
$(this).addClass('error');
pass = false;
}
});
if ($('input[name="seller-role"]:checked').index() === 3 &&
$otherBr.val() === '') {
pass = false;
$otherBr.addClass('error');
}
if ($('input[name="new_cycle"]:checked').index() === 5 &&
$otherNp.val() === '') {
pass = false;
$otherNp.addClass('error');
}
if ($('input[name="supply_cycle"]:checked').index() === 5 &&
$otherRp.val() === '') {
pass = false;
$otherRp.addClass('error');
}
return pass;
}
function addCategoryUI() {
$categoryUl.closest('tr').removeClass('hide');
$categoryUl.append('<li>' + categoryHtml + '</li>');
}
// 获取二级分类的方法
function getCategoryTwo() {
var id = $(this).val();
var $categoryTwo = $(this).parent().find('.category-two');
var html = '<option>选择二级分类</option>';
if (id === '') {
$categoryTwo.html(html);
return;
}
$.ajax({
url: '/shop/getTwoCategory',
type: 'GET',
data: {
id: id
}
}).then(function(data) {
var res = [];
var key;
if (data.code === 200) {
res = data.data;
for (key = 0; key < res.length; key++) {
html += '<option value="' + res[key].id + '" >' + res[key].name + '</option>';
}
}
$categoryTwo.html(html);
});
}
// 初始化上传插件
initUpload([
{
dom: 'upload-brand-material',
type: '*.ppt;*.pdf;*.zip;*.rar',
callback: function(data) {
$('#brand-material').val(data);
$('.brand-tip').html('上传成功');
new Alert('上传成功!').show();
}
},
{
dom: 'upload-goods-material',
type: '*.xls;*.xlsx;*.zip;*.rar',
callback: function(data) {
$('#goods-material').val(data);
$('.goods-tip').html('上传成功');
new Alert('上传成功!').show();
}
}
]);
// 提交成功
// if (location.search.indexOf('state=1') > -1) {
// successDialog = new Dialog({
// className: 'settled-success',
// closeIcon: false,
// content: '<h1 class="main-title">恭喜您已提交成功</h1><h2 class="sub-title">我们将尽快与您联系</h2>',
// btns: [
// {
// id: 'apply-success-ok',
// btnClass: ['apply-success-ok'],
// name: '确认',
// cb: function() {
// location.href = '/shop';
// }
// }
// ]
// });
// successDialog.show();
// return;
// }
$('input[name="seller_role"]').change(function() {
if ($(this).index() === 3) {
$otherBr.removeClass('hide');
} else {
$otherBr.addClass('hide');
}
});
$('input[name="new-cycle"]').change(function() {
if ($(this).index() === 5) {
$otherNp.removeClass('hide');
} else {
$otherNp.addClass('hide');
}
});
$('input[name="supply-cycle"]').change(function() {
if ($(this).index() === 5) {
$otherRp.removeClass('hide');
} else {
$otherRp.addClass('hide');
}
});
$('input[name="have-store"]').change(function() {
if ($(this).index() === 1) {
$shopListTr.addClass('hide');
} else {
$shopListTr.removeClass('hide');
}
});
$('.form-container').on('change', '.category-one', getCategoryTwo);
$('#category-add').click(addCategoryUI);
$shops.delegate('.shop-add', 'click', function() {
$shops.append(
'<li>' +
'<input class="shop-addres" name="store-address[]" type="text" placeholder="输入店铺地址">' +
'<span>月均销售:</span>' +
'<input class="shop-sales-volume" type="text" name="store-sales-volume[]" placeholder="输入价格">' +
'<span>元</span>' +
'</li>'
);
});
$('#apply-post').click(function() {
var scrollTo;
if (validate()) {
$panel.removeClass('hide');
$.ajax({
url: '/shop/applysave',
type: 'post',
data: $('form').serialize()
}).then(function(data) {
if (data.code && data.code === 200) {
successDialog = new Dialog({
className: 'settled-success',
closeIcon: false,
content: '<h1 class="main-title">恭喜您已提交成功</h1><h2 class="sub-title">我们将尽快与您联系</h2>',
btns: [
{
id: 'apply-success-ok',
btnClass: ['apply-success-ok'],
name: '确认',
cb: function() {
location.href = '//shop.yohobuy.com/settled';
}
}
]
});
successDialog.show();
return;
} else {
new Alert(data.message).show();
}
});
} else {
$('.error').first().focus();
scrollTo = $('.error').first().offset().top;
$(window).scrollTop(scrollTo - 10);
}
});
if (navigator.userAgent.indexOf('MSIE') >= 0) {
$('[placeholder]').focus(function() {
var $input = $(this);
$input.removeClass('placeholder');
}).blur(function() {
var $input = $(this);
if ($input.val() === '') {
$input.addClass('placeholder');
}
});
}
}());