|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- // pages/register/register.js
-
- const app = getApp()
- let time;
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- yesSend:false,//是否发送验证码
- minter: 60,//发送验证码60秒后才可再次发送
- num:60,
- phone: "",//手机号
- phoneCode: "",//验证码
- yesRegister:false,//防止重复点击注册
- userInfo:[],//用户信息
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- if (wx.canIUse('hideHomeButton')) {
- wx.hideHomeButton()
- }
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: "老门框爆肚会员",
- path: "/pages/register/register",
- success: res => {
- console.log(res, "转发成功")
- },
- }
- },
-
- yesCodeFn:function(){//验证码接口
- app.wxRequest(app.globalData.httpUrl + 'smscode', { user_phone: this.data.phone }, e => {
- console.log(e)
- if (e.code == 200) {
- wx.showToast({
- title: e.message,
- icon: 'success',
- duration: 500
- })
- }else{
- wx.showToast({
- title: e.message,
- icon: 'none',
- duration: 500
- })
- }
- }, this)
- },
- sendTouch:function(){//发送验证码
- if (this.data.phone){
- if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
- wx.showToast({
- title: '手机号错误',
- icon: 'none',
- duration: 500
- })
- return;
- }
- }else{
- wx.showToast({
- title: '请先输入手机号',
- icon: 'none',
- duration: 500
- })
- return;
- }
-
- this.setData({
- yesSend: true,
- })
- if (this.data.yesSend) {
- time = setInterval(this.setIntervalFn,1000)
- }
-
- if (app.globalData.openId) {
- this.yesCodeFn();
- } else {
- app.globalData.openidSuccessFuc = this.yesCodeFn;
- }
-
- },
- setIntervalFn:function(){//定时器
- if (this.data.num > 0) {
- this.data.num--;
- if (this.data.num == 0) {
- this.setData({
- yesSend: false,
- })
- if (!this.data.yesSend){
- this.setData({
- num: 60,
- minter: 60,
- })
- }
- clearInterval(time);
- }
- }
- this.setData({
- minter: this.data.num
- })
- console.log(this.data.minter)
- },
- submitUser: function () {//提交用户信息
- if(this.data.userInfo && this.data.userInfo.province){
- var params = {
- "province": this.data.userInfo.province,
- "language": this.data.userInfo.language,
- "city": this.data.userInfo.city,
- "gender": this.data.userInfo.gender,
- "nickname": this.data.userInfo.nickName,
- "headimgurl": this.data.userInfo.avatarUrl,
- }
- app.wxRequest(app.globalData.httpUrl + 'submit', params, e => {
- console.log(e)
- if (e.code == 200) {
-
- }
- }, this, "POST")
- }
-
- },
- getUserFn:function(e){//点击按钮注册
- console.log(e)
- this.data.userInfo = e.detail.userInfo;
- if(e.detail.userInfo){
- app.globalData.userInfo = e.detail.userInfo
- }
- this.registerFn();
- // if (app.globalData.openId) {
-
- // } else {
- // app.globalData.openidSuccessFuc = this.registerFn;
- // }
- },
- registerFn:function(){//注册接口
- if (this.data.yesRegister){
- return;
- }
- if(this.data.phone){
- if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
- wx.showToast({
- title: '手机号错误',
- icon: 'none',
- duration: 500
- })
- return;
- }
- }else{
- wx.showToast({
- title: '请先输入手机号',
- icon: 'none',
- duration: 500
- })
- return;
- }
- if (!this.data.phoneCode){
- wx.showToast({
- title: '请先输入验证码',
- icon: 'none',
- duration: 500
- })
- return;
- }
- app.wxRequest(app.globalData.httpUrl + 'register', { user_phone: this.data.phone, code_num: this.data.phoneCode }, e => {
- console.log(e)
- this.data.yesRegister = true;
- if (e.code == 200) {
- clearInterval(time);
- wx.setStorageSync('user_phone', e.data.user_phone);
- wx.setStorageSync("userInfo", this.data.userInfo)
- wx.setStorageSync('state', 1);
- // app.globalData.userInfo = e.data;
- this.submitUser();
- this.setData({
- minter: 60,
- num: 60
- })
- if (app.globalData.present_id){
- wx.reLaunch({
- url: '/pages/receiveTicket/receiveTicket?shareId=' + app.globalData.present_id + "&number=" + app.globalData.number
- })
- } else {
- console.log(5555)
- wx.navigateBack();
- }
- } else {
- this.data.yesRegister = false;
- wx.showToast({
- title: e.message,
- icon:"none",
- duration:500
- })
- }
- }, this,"POST")
- },
- getPhone: function (e) {//获取手机号
- console.log(e.detail.value);
- this.setData({
- phone: e.detail.value
- })
- },
- getCode: function (e) {//获取验证码
- console.log(e.detail.value);
- this.setData({
- phoneCode: e.detail.value
- })
- },
- })
|