|
- const config = require('../../../config/config.js')
- const Common = require('../../../common/common.js')
- const app = getApp()
- var interval = null //倒计时函数
-
- Page({
- data: {
- phone: '',
- yzm: '',
- flag: true,
- retry: false,
- time: 60,
- phones: "",
- date: '请选择日期',
- fun_id: 2,
- time: '获取验证码', //倒计时
- currentTime: 61,
- disabled: false,
- setInter: ''
- },
- getCode: function (options) {
- var that = this;
- var currentTime = that.data.currentTime
- that.data.setInter = setInterval(function () {
- currentTime--;
- that.setData({
- time: currentTime + '秒'
- })
- if (currentTime <= 0) {
- clearInterval(that.data.setInter)
- that.setData({
- time: '获取验证码',
- currentTime: 61,
- disabled: false
- })
- }
- console.log(that.data.time)
- }, 1000)
- },
- onHide: function () {
- let that = this;
- clearInterval(that.data.setInter);
- that.setData({
- time: '获取验证码',
- currentTime: 61,
- disabled: false
- })
- },
- onUnload: function () {
- let that = this;
- clearInterval(that.data.setInter)
- that.setData({
- time: '获取验证码',
- currentTime: 61,
- disabled: false
- })
- },
- onLoad: function (options) {
- if (options.flags == 'reset') {
- wx.setNavigationBarTitle({
- title: '修改密码'
- })
- this.setData({
- flags: options.flags
- })
- } else {
- wx.setNavigationBarTitle({
- title: '忘记密码'
- })
- }
-
- },
- onShow: function () {
- let that = this;
- that.setData({
- phones: wx.getStorageSync("phone"),
- disabled: false
- });
- console.log(that.data.phones)
- },
- getYZM(e) {
- console.log(e, "999");
- if (e.detail.value.phone) {
- this.setData({
- phone: e.detail.value.phone,
- yzm: e.detail.value.yzm
- })
- wx.setStorageSync('phone', e.detail.value.phone)
- } else {
- this.setData({
- phone: wx.getStorageSync("phone"),
- yzm: e.detail.value.yzm
- })
- }
- },
- next() {
- setTimeout(() => {
- console.log(this.data)
- Common.hasValidationCode(this.data.phone, this.data.yzm)
- .then(res => {
- console.log(res)
- setTimeout(() => {
- console.log(res)
- if (res.code == 200) {
- wx.navigateTo({
- url: `../setpwd/setpwd?phone=${this.data.phone}&code=${this.data.yzm}`
- })
- } else {
- wx.showToast({
- title: "验证码错误",
- icon: "none",
- duration: 2000
- })
- }
- }, 500)
- })
- }, 1000)
- },
- // 发送验证码
- send(e) {
- console.log(e);
- var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
- let that = this;
- console.log(this.data.phone, "手机号");
- console.log(wx.getStorageSync("phone"), "本地存储手机号")
- // setTimeout(() => {
- let tel = wx.getStorageSync("phone") || this.data.phone;
- if (phoneReg.test(tel)) {
- that.setData({
- disabled: true
- })
- Common.sendValidationCode(tel)
- .then(res => {
- console.log(res);
- if (res.code == 200) {
- that.getCode();
- wx.showToast({
- title: res.message,
- image: './../../../static/images/success.png'
- })
- } else if (res.code == 12061) {
- wx.showToast({
- title: res.message,
- icon: "none",
- })
- } else {
- wx.showToast({
- title: res.message,
- icon: "none",
- })
- }
- })
- } else {
- if (!tel.length) {
- wx.showToast({
- title: '请输入手机号',
- icon: "none",
- })
- } else {
- wx.showToast({
- title: '手机号格式错误',
- icon: "none",
- })
- }
- }
- // }, 500)
- }
- })
|