register-controller.js
9.92 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
/**
* 注册-首页
*/
define(
"user/register-controller",
[
'mk7/controller',
'mk7/url',
'mk7/utils',
'mk7/uploadjs',
],
function(ctrl, url, utils, uploadjs) {
var $$ = Dom7;
var t7 = Template7;
var ctrl = new ctrl();
var registerUrl = '/user/login/register';
var uploadURL = '/user/default/upload-file';
var getCodeURL = '/user/login/get-code';
var loginURL = '/user/login/do-login';
var clickGetCode = true;
var registerClick = true;
var tt = null
ctrl.run = function () {
var me = this;
me.setPageTitle("注册");
//me.hideAllNonBaseMenuItem(window.$site);
me.codeDuration = 60;
if (!isGuest) {
window.location.href = url.to('order/#index');
return '';
}
me.render();
}
ctrl.bindEvents = function () {
var me = this;
console.log("bindEvents");
me.uploadEvent();
me.getCodeEvent();
me.registerEvent();
me.gotoLoginEvent();
me.checkAgreement();
}
ctrl.uploadEvent = function() {
$$('#register .upload-input-cls').change(function() {
if ('' == $$(this).val() || null == $$(this).val()) {
return ;
}
var id = $$(this).attr('id');
var parent = $$(this).parent();
uploadjs.uploadFile({
selector:'#'+id,
url:url.to(uploadURL),
processAppendTo:'#register',
success:function(response, e) {
try {
if(response.success) {
var imgUrl = response.tmpUrl;
parent.css("background-image", 'url('+response.tmpMinUrl+')');
parent.attr('data', response.tmpFile);
parent.attr('data-url', imgUrl);
} else {
utils.toast({content:response.message, closeDelay:5000});
}
} catch(ex) {
utils.toast({content:'出错', closeDelay:5000});
}
}
});
})
}
ctrl.getCodeEvent = function() {
var me = this;
$$('#register .get-code-cls').click(function() {
var mobile = utils.trim($$('#register .mobile').val());
if ('' == mobile) {
utils.toast({content:'手机号码必填'})
return false;
}
if (!utils.isMobile(mobile)) {
utils.toast({content:'手机号码不合格'})
return false;
}
if (false == clickGetCode) {
return false;
}
clearInterval(tt);
clickGetCode = false;
var pData = me.csrf({action:'register', mobile:mobile})
utils.httpGet(url.to(getCodeURL), pData, function(res) {
if (!res.success) {
utils.toast({content:res.message,closeDelay:3000})
clickGetCode = true;
return false;
}
utils.toast({content:res.message});
if(res.testCode) {
$$('#register .code').val(res.testCode);
}
var codeDuration = res.codeDuration
me.codeDuration = codeDuration;
tt = setInterval(function(e) {
me.codeDuration--;
if (0 == me.codeDuration) {
$$('#register .get-code-cls').html('获取验证码');
clearInterval(tt);
me.codeDuration = codeDuration;
clickGetCode = true;
} else {
$$('#register .get-code-cls').html('<span class="count-down-cls">' +me.codeDuration+'s后重新获取</span>');
}
}, 1000)
})
})
}
ctrl.registerEvent = function() {
var me = this;
$$('#register .register-btn').click(function(e) {
var name = utils.trim($$('#register .name').val());
var mobile = utils.trim($$('#register .mobile').val());
var code = utils.trim($$('#register .code').val());
var emergencyContact = utils.trim($$('#register .emergency_contact').val());
var emergencyPerson = utils.trim($$('#register .emergency_person').val());
if ('' == name) {
utils.toast({content:'车厂名称必填'})
return false;
}
if ('' == mobile) {
utils.toast({content:'手机号码必填'})
return false;
}
if (!utils.isMobile(mobile)) {
utils.toast({content:'手机号码不合格'})
return false;
}
if ('' == code) {
utils.toast({content:'验证码必填'})
return false;
}
if ('' == emergencyPerson) {
utils.toast({content:'紧急联系人必填'})
return false;
}
if ('' == emergencyContact) {
utils.toast({content:'紧急联系电话必填'})
return false;
}
if (!utils.isMobile(emergencyContact) && !utils.isTelephone(emergencyContact)) {
utils.toast({content:'紧急联系电话不合格'})
return false;
}
if (emergencyContact == mobile) {
utils.toast({content:'紧急联系电话不能和注册手机一样'})
return false;
}
var licensePic = $$('#register .licensePic').attr('data');
if (undefined === licensePic || null == licensePic) {
utils.toast({content:'请上传营业执照'})
return false;
}
var headPic = $$('#register .headPic').attr('data');
if (undefined === headPic || null == headPic) {
utils.toast({content:'请上传维修厂门头照'})
return false;
}
var techChargePic = $$('#register .techChargePic').attr('data');
if (undefined === techChargePic || null == techChargePic) {
utils.toast({content:'请上传维修技术负责人证书'})
return false;
}
var QAChargePic = $$('#register .QAChargePic').attr('data');
if (undefined === QAChargePic || null == QAChargePic) {
utils.toast({content:'请上传质检负责人证书'})
return false;
}
if (!$$('#register .check-agreement').hasClass('checked-active')) {
utils.toast({content:'请阅读同意《平台车管家服务条款》'})
return false;
}
if (false == registerClick) {
return false;
}
registerClick = false;
var pData = me.csrf({
name:name, mobile:mobile,code:code,
emergencyContact:emergencyContact,emergencyPerson:emergencyPerson,
licensePic:licensePic,
headPic:headPic,
techChargePic:techChargePic,
QAChargePic:QAChargePic,
})
utils.httpPost(url.to(registerUrl),pData, function(res) {
if (!res.success) {
utils.toast({content:res.message,closeDelay:3000})
registerClick = true;
return false;
} else {
var closeDelay = 3000;
utils.toast({content:res.message, closeDelay:closeDelay})
setTimeout(function(){
window.location.href = url.to('order/#index');
}, closeDelay)
}
})
})
}
ctrl.gotoLoginEvent = function() {
$$('#register .login-btn').click(function(e){
window.location.href = url.to('user/#login');
})
}
ctrl.checkAgreement = function() {
$$('#register .check-agreement').click(function(e) {
if($$(this).hasClass('checked-active')) {
$$(this).removeClass('checked-active');
} else {
$$(this).addClass('checked-active');
}
})
$$('#register .agreement-cls').click(function(e){
$$('#agreement-wrapper').remove();
var page = $$('#register');
var ele = $$('script#agreement-template');
var compiled = t7.compile(ele.html());
var doms = compiled({});
page.append(doms);
})
$$('#register').on('click','.agree-btn', function(e){
$$('#agreement-wrapper').remove();
var checkAgreement = $$('#register .check-agreement');
if(!checkAgreement.hasClass('checked-active')) {
checkAgreement.addClass('checked-active');
}
})
}
return ctrl;
}
);