|
- // pages/forgetpwd/forgetpwd.js
- let config = require('../../config/config.js')
- let Http = require('../../utils/HttpBasics')
- const app = getApp()
-
- Page({
- data: {
- phone: '',
- yzm: '',
- retry: false,
- time: 60,
- couponChannelId: null,
- couponId:null,
- path:null,
- paramData: null
- },
- onLoad: function (options) {
- if(options.path=='index'){
- this.path = options.path
- }
- this.setData({
- paramData: options
- })
- var that = this;
- console.log(options);
- that.setData({
- couponChannelId: options.couponChannelId,
- couponId: options.couponId,
- })
- },
- getYZM(e) {
- this.setData({
- phone: e.detail.value.phone,
- yzm: e.detail.value.yzm
- })
- },
- next() {
- var that = this
- console.log(that.data.yzm)
- Http.get({
- url: config.api.validationCode,
- data: {
- phone: that.data.phone,
- code: that.data.yzm,
- type: 1,
- appid: app.globalData.appId
- }
- })
- .then(res => {
- if(that.path!=null){
- wx.redirectTo({
- url: "/pages/game/index?url=" + that.data.paramData.url + "&id=" + that.data.paramData.id + "&gameId=" + that.data.paramData.gameId,
- })
- }else{
- wx.redirectTo({
- url: '/pages/coupon/detail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId + "&flag=pay",
- })
- }
- })
- .catch(err => {
- wx.showToast({
- title: err.errMsg,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- },
- //计时器
- timerInfo() {
- var timer = setInterval(() => {
- this.data.time--
- this.setData({
- time: this.data.time
- })
- if (this.data.time == 0) {
- clearInterval(timer)
- this.setData({
- flag: true,
- retry: false,
- time: 60
- })
- }
- }, 1000)
- },
- send() {
- var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
- if (phoneReg.test(this.data.phone)) {
- this.setData({
- retry: true
- })
- Http.get({
- url: config.api.sendValidationCode,
- data: {
- phone: this.data.phone,
- code: this.data.yzm,
- type: 1,
- appid: app.globalData.appId
- }
- })
- .then(res => {
- console.log(res)
- that.timerInfo()
- if (res.code == 200) {
- console.log(res)
- } else {
- wx.showToast({
- title: res.message
- })
- }
- })
- .catch(err => {
- wx.showToast({
- title: err.errMsg,
- icon: 'none',
- duration: 2000,
- mask: false
- });
- })
- }
- }
- })
|