123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- import { $wuxCountDown } from '../../components/dist/index'
- import {
- get, post,
- } from '../../utils/http';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- status: 0,
- phone: '',
- phoneVal: '',
- codeVal: '',
- sms_token: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options)
- this.setData({
- phone: options.phone
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- if(this.c1) this.c1.stop()
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- /**
- * 监听输入手机号
- */
- onChangePhone(e) {
- this.setData({
- phoneVal: e.detail.value
- })
- },
- /**
- * 监听输入验证码
- */
- onChangeCode(e) {
- this.setData({
- codeVal: e.detail.value
- })
- },
- /**
- * 获取验证码
- * api/sms/send_verify_code
- */
- getCode() {
- let { phoneVal,status,sms_token } = this.data;
- if(phoneVal == '') {
- wx.showToast({
- title: '请输入手机号',
- icon: 'none'
- })
- return;
- }
- if (this.c1 && this.c1.interval) return !1
- post('api/sms/send_verify_code',{
- type: status == 0 ? 1 : 2,
- mobile: phoneVal,
- sms_token
- },(res) => {
- wx.showToast({
- title: res.msg,
- })
- this.c1 = new $wuxCountDown({
- date: +(new Date) + 60000,
- onEnd() {
- this.setData({
- c1: '重新获取验证码',
- })
- },
- render(date) {
- const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
- date.sec !== 0 && this.setData({
- c1: sec,
- })
- },
- })
- })
- },
- /**
- * 校验
- */
- onCheck() {
- if(this.data.status == 0) {
- this.verifyMobile();
- } else {
- this.changeMobile()
- }
- // this.setData({
- // status: ++this.data.status,
- // phoneVal: '',
- // codeVal: ''
- // })
- },
- /**
- * 校验旧手机号的验证码
- * /api/user/verify_mobile
- */
- verifyMobile() {
- return new Promise((resolve,reject) => {
- post('api/user/verify_mobile',{
- verify_code: this.data.codeVal
- },(res) => {
- if(this.c1){
- this.c1.stop()
- this.setData({
- c1: null
- })
- }
- wx.showToast({
- title: res.msg,
- })
- this.setData({
- status: ++this.data.status,
- phoneVal: '',
- codeVal: '',
- sms_token: res.data.sms_token
- })
- resolve()
- })
- })
- },
- /**
- * 更换新手机
- * api/user/change_mobile
- */
- changeMobile() {
- let { phoneVal,codeVal,sms_token } = this.data;
- post('api/user/change_mobile',{
- verify_code:codeVal,
- mobile:phoneVal,
- sms_token
- },(res) => {
- if(this.c1){
- this.c1.stop()
- this.setData({
- c1: null
- })
- }
- wx.showToast({
- title: res.msg,
- })
- this.setData({
- status: ++this.data.status,
- phoneVal: '',
- codeVal: '',
- })
- })
- }
- })
|