123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- const app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- title:{
- type:String,
- value:'绑定手机号'
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- phone:'',
- yzm:'',
- minute:60,
- timeMsg:'获取验证码',
- timer:1,
- },
- /**
- * 组件的方法列表
- */
- methods: {
- closeHint(){
- this.triggerEvent("closeHint")
- },
- bindPhoneEvent(){//绑定手机号,点击确定
- if(!(/^1[3456789]\d{9}$/.test(this.data.phone))){
- wx.showToast({
- title: '请输入正确的手机号',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- if(this.data.yzm == ''){
- wx.showToast({
- title: '请输入验证码',
- icon: 'none',
- duration: 2000
- })
- return
- }
- wx.showLoading({ title: '加载中', })
- app.func.req(app.func.api.bind_phone, 'post', {
- code:this.data.yzm,
- phone:this.data.phone,
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- wx.showToast({
- title: '绑定成功',
- icon: 'success',
- duration: 2000
- })
- wx.setStorageSync('phone', this.data.phone)
- this.triggerEvent("bindPhoneEvent")
- }else{
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- bindPhone: function(e){//绑定手机号
- this.setData({
- phone: e.detail.value
- })
- },
- bindYzm: function(e){//验证码
- this.setData({
- yzm: e.detail.value
- })
- },
- getYzmButton(){//获取验证码
- if(this.data.timeMsg!='获取验证码'){
- return
- }
- if(!(/^1[3456789]\d{9}$/.test(this.data.phone))){
- wx.showToast({
- title: '请输入正确的手机号',
- icon: 'none',
- duration: 2000
- })
- return;
- }
- if(this.data.title == '换绑手机号' && (this.data.phone == wx.getStorageSync('phone'))){
- wx.showToast({
- title: '不可重复绑定同一手机号',
- icon: 'none',
- duration: 2000
- })
- return
- }
- wx.showLoading({ title: '加载中', })
- app.func.req(app.func.api.verification_code, 'get', {
- type:'bind',
- phone:this.data.phone,
- }, (res) => {
- wx.hideLoading()
- if(res && res.errno == 0){
- this.CountDown()
- }else{
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },()=>{
- wx.hideLoading()
- })
- },
- CountDown() {//倒计时
- var maxtime = this.data.minute
- this.setData({timeMsg:'获取验证码'})
- var timer = setInterval(()=>{
- if (maxtime >= 0) {
- this.setData({timeMsg: maxtime + "s"});
- --maxtime;
- } else{
- this.setData({timeMsg:'获取验证码'})
- clearInterval(this.data.timer);
- }
- },1000)
- this.setData({timer:timer})
- },
- }
- })
|