user.js
5.15 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
/**
*
*/
QUser = {
oldBoxId : 1,
init:function(year, monthon, day)
{
this.crateDay(year, monthon, day);
$("#box_2").hide();
$("#box_3").hide();
$("#box_4").hide();
},
changeMonth : function() {
var year = $("#year").val();
var month = $("#month").val();
var day = $("#day").val();
this.crateDay(year, month, day);
},
changeYear : function() {
var year = $("#year").val();
var month = $("#month").val();
var day = $("#day").val();
this.crateDay(year, month, day);
},
crateDay : function(year, month, day) {
if(parseInt(year) == 0)
{
year = 0;
}
if(parseInt(month) == 0)
{
month = 0;
}
$("#year").val(year);
$("#month").val(month);
var html = '<select name="day" id="day">';
html += '<option value="0">日</option>';
if(year > 0 && month > 0){
var monthArray = new Array(4, 6, 9, 11);
var dayNum = 31;
if (jQuery.inArray(month, monthArray) != -1) {
dayNum = 30;
} else if (month == 2 ) {
dayNum = 28;
if(0 == year % 4 && (year % 100 != 0 || year % 400 == 0))
{
dayNum = 29;
}
}
for ( var i = 1; i <= dayNum; i++) {
var select = '';
if (parseInt(day) == i) {
select = 'selected';
}
html += '<option value="' + i + '" ' + select + '>' + i + '日</option>';
}
}
html += '</select>';
$("#day").replaceWith(html);
},
showBox: function(id)
{
if(parseInt(id) == 0 || parseInt(this.oldBoxId) == 0)
{
return false;
}
$("#box_" + id).slideDown('slow');
$("#box_" + this.oldBoxId).hide();
this.oldBoxId = id;
if(id == 2)
{
this.checkContactForm();
}else if(id == 1)
{
this.checkBaseForm();
}
},
save: function (postUrl,formId, box_id){
if(typeof(postUrl) == 'undefined' || postUrl == '' || typeof(formId) == 'undefined' || formId == '')
{
alert('参数错误');
return false;
}
$.post(postUrl,$('#'+formId).serialize(),
function(data){
if(data.code == 200){
alert(data.message);
if(parseInt(box_id) != 0)
{
QUser.showBox(box_id);
}
return true;
}
alert(data.message);
return false;
}, 'json');
},
delBrand: function(brand_id, flag)
{
if(parseInt(brand_id) == 0)
{
return false;
}
var brand = $("#likebrand").val();
$("#likebrand").val(brand.replace(','+brand_id+',', ','));
$("#pp_" + brand_id).attr('checked', false);
$("#brand_" + brand_id).remove();
},
addBrand: function(obj, brand_id, brand_name)
{
if(parseInt(brand_id) == 0)
{
return false;
}
var brandInfo = $('#brand_' + brand_id).html();
if(typeof obj != 'undefined' && obj != '' && obj.checked == false)
{
this.delBrand(brand_id);
return false;
}
if(brandInfo != null)
{
alert('您已经选择了该品牌.');
return false;
}
var html = '<li id="brand_'+brand_id+'">'+ brand_name +' <a href="javascript:void(0);" onclick="QUser.delBrand('+brand_id+', this);" class="btn_del"></a></li>';
$("#brandBox").append(html);
var brandStr = $("#likebrand").val();
brandStr += brand_id + ',';
$("#likebrand").val(brandStr);
},
checkBrand: function()
{
$.post('/home/user/checkbrand',{keywords:$('#keywords').val()},
function(data){
if(data.code == 200){
QUser.addBrand('',data.data.id, data.data.brand_name);
$('#keywords').val('');
return true;
}
alert(data.message);
return false;
}, 'json');
},
checkBaseForm: function()
{
return false;
jQuery.formValidator.initConfig({
formid : "userBaseInfo"
});
jQuery("#nickname").formValidator({
onshow : "请填写昵称",
onfocus : "昵称必须大于2而小于20个字符",
oncorrect : "昵称输入正确"
}).inputValidator({
min : 2,
max : 20,
onerror : "您输入的昵称不正确"
});
jQuery("#user_name").formValidator({
onshow : "请填写申请人的真实姓名",
onfocus : "真实姓名只能为中文",
oncorrect : "输入正确"
}).regexValidator({
regexp : "^[\u4e00-\u9fa5]{2,5}$",
onerror : "真实姓名至少2个中文,最多5个中文"
});
},
checkContactForm: function()
{
return false;
jQuery.formValidator.initConfig({
formid : "userContactInfo"
});
$('#mobile').formValidator({
onshow : "填写手机号便于接收发货和收货通知",
onfocus : "填写手机号便于接收发货和收货通知",
oncorrect : "输入正确"
}).regexValidator({
regexp : regexEnum.mobile,
onerror : "您输入的手机号码格式不正确"
});
$('#full_address').formValidator({
onshow : "请填写详细地址",
onfocus : "请填写详细地址",
oncorrect : "输入正确",
onempty: "请填写详细地址",
empty: false
}).inputValidator({
min : 10,
onerror : "请填写详细地址"
});
//邮编
$('#zip_code').formValidator({
onshow : "请输入收货人所在地邮编号",
onfocus : "请输入收货人所在地邮编号",
oncorrect : "输入正确",
onempty: "请输入收货人所在地邮编号",
empty: false
}).regexValidator({
regexp : regexEnum.zipcode,
onerror : "您输入的邮编式不正确"
});
},
checkShoppingForm: function()
{
if($('#brandStr').val() == '')
{
alert('请添加您喜欢的品牌');
return false;
}
return true;
}
};