123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- const app = getApp()
- Page({
- data: {
- mobile: '',
- code: '',
- showErrMsg: false,
- errorMsg: '',
- showIcon: false,
- codeNotice: '获取验证码',
- count: 0,
- counting: false,
- from: '',
- preid: 0
- },
- onLoad: function (options) {
- var from = options.from, preid = options.preid || 0
- this.setData({from: from, preid: preid})
- console.log(from, preid);
- },
- onReady: function () {
- },
- onShow: function () {
- },
- onHide: function () {
- },
- onUnload: function () {
- },
- phoneUpdate: function (e) {
- var that = this, value = e.detail.value;
- if (value != '') {
- that.setData({
- mobile: value,
- showIcon: true
- })
- } else {
- that.setData({
- mobile: value,
- showIcon: false
- })
- }
- },
- // 点击x号清空input
- clearPhone: function(e){
- this.setData({
- mobile: '',
- showIcon: false
- })
- },
- codeUpdate: function (e) {
- this.setData({
- code: e.detail.value
- })
- },
- hideErrMsg () {
- this.setData({
- showErrMsg: false
- })
- },
- countDown: function (count) {
- var that = this;
- that.setData({
- counting: true,
- codeNotice: count + ' 秒后重新获取'
- })
- setTimeout(function () {
- if (count > 1) {
- count--;
- that.countDown(count);
- that.setData({
- counting: true,
- codeNotice: count + ' 秒后重新获取'
- })
- return;
- } else if (count == 1) {
- that.setData({
- codeNotice: '获取验证码',
- counting: false
- })
- return;
- }
- }, 1000);
- },
- getCode: function (e) {
- var that = this, token = wx.getStorageSync('user').token;
- var phone = that.data.mobile, codeNotice = that.data.codeNotice;
- if (token) {
- if (!(/^1[34578]\d{9}$/.test(phone))) {
- that.setData({
- showErrMsg: true,
- errorMsg: '手机号格式不正确'
- })
- } else {
- if (codeNotice == '获取验证码') {
- that.countDown(60);
- const dataParam = Object.assign({}, app.globalData.common, {
- phone: phone
- })
- wx.request({
- url: app.globalData.HOST + '/user/wx/sendCode',
- method: 'POST',
- data: dataParam,
- success: function (errno) {
- if (errno.data.errno == '0') {
- }
- }
- });
- }else{
- that.setData({
- showErrMsg: true,
- errorMsg: '请在计时结束后,再重新获取'
- })
- }
- }
- } else {
- app.login(that);
- }
- },
- // 提交登录
- goLogin: function (e) {
- var that = this;
- var token = wx.getStorageSync('user').token, phone = that.data.mobile, code = that.data.code,
- from = that.data.from, preid = that.data.preid;
- phone = phone.replace(/(^\s*)|(\s*$)/g, "");
- code = code.replace(/(^\s*)|(\s*$)/g, "");
- // 信息不为空
- if (phone && code && token) {
- // 手机号格式正确
- if (!(/^1[34578]\d{9}$/.test(phone))) {
- that.setData({
- showErrMsg: true,
- errorMsg: '手机号格式不正确'
- })
- }else{
- const dataParam = Object.assign({}, app.globalData.common, {
- phone: phone,
- code: code
- })
- wx.request({
- url: app.globalData.HOST + '/user/wx/bindMobile',
- method: 'POST',
- data: dataParam,
- success: function (res) {
- if (res.data.errno == '0') {
- wx.setStorage({key:"tel", data: phone})
- if (from === 'mine') {
- wx.redirectTo({
- url: '/pages/application/application?tel=' + phone
- })
- }else if(from === 'mineFeedback'){
- wx.redirectTo({
- url: '/pages/feedback/feedback?tel=' + phone
- })
- }else{
- wx.redirectTo({
- url: '/pages/getIt/getIt?from='+ from +'&preid='+ preid +'&tel=' + phone
- })
- }
- }else{
- that.setData({
- showErrMsg: true,
- errorMsg: res.data.err
- })
- }
- }
- });
- }
- }else{
- that.setData({
- showErrMsg: true,
- errorMsg: '信息填写不完整'
- })
- }
- }
- })
|