97 lines
2.4 KiB
JavaScript
97 lines
2.4 KiB
JavaScript
let webapi = require('./utils/webapi');
|
|
let stringUtil = require('./utils/string.util');
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
closeBtn: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
submitBtn: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
captchaBtn: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
resultPrefab: {
|
|
default: null,
|
|
type: cc.Prefab
|
|
},
|
|
mobileInput: {
|
|
default: null,
|
|
type: cc.EditBox
|
|
},
|
|
captchaInput: {
|
|
default: null,
|
|
type: cc.EditBox
|
|
},
|
|
codeInput: {
|
|
default: null,
|
|
type: cc.EditBox
|
|
},
|
|
codeImg: {
|
|
default: null,
|
|
type: cc.Sprite
|
|
}
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
onLoad () {
|
|
let self = this;
|
|
if (this.top.needCode) {
|
|
this.showCaptchaInput();
|
|
this.codeImg.node.on('click', function () {
|
|
self.showCaptchaInput();
|
|
})
|
|
}
|
|
this.closeBtn.on('click', function () {
|
|
self.node.removeFromParent(true);
|
|
});
|
|
this.submitBtn.on('click', function () {
|
|
let mobile = self.mobileInput.string;
|
|
});
|
|
this.captchaBtn.on('click', function () {
|
|
console.log(self.mobileInput.string);
|
|
let mobile = self.mobileInput.string;
|
|
if (!stringUtil.checkMobile(mobile)) {
|
|
alert('请输入有效的手机号码。');
|
|
return false;
|
|
}
|
|
webapi.sendSms(mobile)
|
|
.then(res => {
|
|
console.log(res);
|
|
})
|
|
.catch(err => {
|
|
console.log(err);
|
|
})
|
|
})
|
|
},
|
|
|
|
start () {
|
|
},
|
|
|
|
showResultView() {
|
|
let result = cc.instantiate(this.resultPrefab);
|
|
this.top.node.addChild(result, 11);
|
|
this.node.removeFromParent(true);
|
|
},
|
|
|
|
showCaptchaInput() {
|
|
let self = this;
|
|
cc.loader.load({
|
|
url: webapi.captchaUrl()+'?'+new Date(),
|
|
type: 'jpg'
|
|
}, function (err, texture) {
|
|
if (err) {
|
|
console.log('load avatar error === ', err);
|
|
return;
|
|
}
|
|
self.codeImg.spriteFrame = new cc.SpriteFrame(texture);
|
|
});
|
|
}
|
|
});
|