h5-cli
Version:
hello
159 lines (140 loc) • 4.61 kB
JavaScript
"use strict";
define(function (require, exports, module) {
var md5 = require("libs/md5");
var PageModule = require("component/PageModule");
var page = PageModule.render({
init: function init() {
var self = this;
this.redirecturl = this.query.redirecturl;
this.unionId = this.query.unionId;
this.regEvent();
},
regEvent: function regEvent() {
var self = this;
$('#J_Submit').click(function () {
//send
self.submit();
$('#J_Uiform').removeClass("focus");
});
$('#J_MobileNumber').focus(function () {
$('#J_Uiform').addClass("focus");
});
if (this.redirecturl) {
var signin = $('.go-signin');
signin.attr("href", signin.attr("href") + "?redirecturl=" + this.redirecturl);
}
},
submit: function submit() {
var phoneNumber = $.trim($('#J_MobileNumber').val());
var code = $.trim($('#J_Code').val());
var pwd = $.trim($('#J_Pwd').val());
if (!/^\d{11}$/.test(phoneNumber)) {
this.util.alert("\u8bf7\u8f93\u516511\u4f4d\u624b\u673a\u53f7");
return;
}
if (!(code && code.length == 6)) {
this.util.alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u9a8c\u8bc1\u7801");
return;
}
if (!(pwd && pwd.length >= 6 && pwd.length <= 50)) {
this.util.alert("\u8bf7\u8f93\u51656-50\u4e2a\u5b57\u7b26\u7684\u5bc6\u7801");
return;
}
this.get("/user-web/restapi/common/ytUsers/reg", {
phoneNum: phoneNumber,
password: md5(pwd),
valCode: code,
//corpId:this.corpId,
unionId: this.query.unionId
});
//
},
onSuccess: function onSuccess(result) {
var util = this.util;
var redirecturl = this.redirecturl || "";
if (result.success) {
this.util.alert("\u6ce8\u518c\u6210\u529f");
//ios\u5927\u4e8e2.1.7\u7248\u672c\u6ce8\u518c\u6210\u529f\u8df3\u8f6c\u56de\u4e0a\u4e00\u4e2anative\u754c\u9762
setTimeout(function () {
util.goBack();
}, 2000);
} else {
this.util.alert(result.msg);
}
},
onError: function onError(result) {
this.util.alert(result.msg);
}
});
//\u53d1\u9001\u9a8c\u8bc1\u7801\u6a21\u5757
var sendCodeModule = PageModule.render({
isLoading: false,
init: function init() {
this.countTime = 0;
this.unionId = this.query.unionId;
var self = this;
$('#J_SendCode').click(function () {
if (self.isLoading) {
return;
}
self.isLoading = true;
var phoneNumber = $.trim($('#J_MobileNumber').val());
if (/^\d{11}$/.test(phoneNumber)) {
//\u9a8c\u8bc1\u662f\u5426\u5df2\u7ecf\u6ce8\u518c
self.checkIsReg(phoneNumber, function () {
self.sendCode(phoneNumber);
});
} else {
self.isLoading = false;
self.util.alert("\u8bf7\u8f93\u516511\u4f4d\u624b\u673a\u53f7");
}
});
},
checkIsReg: function checkIsReg(phoneNumber, success) {
var self = this;
this.io.get("/user-web/restapi/common/ytUsers/checkIsReg", { phoneNum: phoneNumber, unionId: self.unionId }, function (result) {
if (!result.data) {
success();
} else {
self.isLoading = false;
self.util.alert("\u8be5\u624b\u673a\u5df2\u6ce8\u518c");
}
}, success);
},
//\u5012\u8ba1\u65f6
countdown: function countdown() {
var self = this;
this.countTime = 60;
var a = setInterval(function () {
$('#J_SendCode').text(--self.countTime + "s");
if (self.countTime <= 0) {
self.isLoading = false;
$('#J_SendCode').text("\u91cd\u65b0\u53d1\u9001");
clearInterval(a);
}
}, 1000);
},
sendCode: function sendCode(phoneNum) {
var self = this;
//\u53d1\u9001\u9a8c\u8bc1\u7801
this.util.waitAlert("\u6b63\u5728\u53d1\u9001\u9a8c\u8bc1\u7801...");
this.get("/user-web/restapi/common/ytUsers/getValidateCode", {
phoneNum: phoneNum,
isApp: self.util.isInYuantuApp(),
unionId: this.unionId
});
},
onSuccess: function onSuccess() {
this.countdown();
},
onError: function onError(result) {
this.isLoading = false;
this.util.alert(result.msg || "\u7f51\u7edc\u9519\u8bef\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5");
}
});
//\u624b\u673a\u9a8c\u8bc1\u7801\u6a21\u5757
sendCodeModule.init();
//\u9875\u9762
page.init();
module.exports = page;
});