emailEdit.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const app = getApp();
  2. Page({
  3. data: {
  4. smsCode:'',
  5. email:'',
  6. codeBtnTxt: "发送验证码",
  7. },
  8. onLoad(options){
  9. var userId = options.userId;
  10. this.setData({
  11. userId,
  12. })
  13. },
  14. submitEmail(){
  15. const that = this
  16. let email = that.data.email;
  17. let smsCode = that.data.smsCode;
  18. if(!email){
  19. app.showToptip(that, "worning", "邮箱输入不能为空")
  20. return;
  21. }else if(!smsCode){
  22. app.showToptip(that, "worning", "邮箱验证码输入不能为空")
  23. }
  24. wx.showLoading({
  25. mask: true
  26. })
  27. app.requestP({
  28. url : "/user/editEmail",
  29. contentType:"application/json",
  30. method:'post',
  31. data: {
  32. email,smsCode,userId:that.data.userId
  33. }
  34. }).then((res) => {
  35. app.showToptip(that,"success", res.data.msg)
  36. wx.switchTab({
  37. url: '/pages/my/my',
  38. })
  39. }).catch((res) => {
  40. app.showToptip(that,"error", res.data.msg)
  41. });
  42. },
  43. getEmailCode(){
  44. var that = this;
  45. let email = that.data.email;
  46. if(!email){
  47. app.showToptip(that, "worning", "邮箱输入不能为空")
  48. return;
  49. }
  50. app.requestP({
  51. url:'/sms/getEmailGetAuthCode',
  52. method:'post',
  53. contentType:"application/json",
  54. data:{
  55. email,
  56. }
  57. }).then(res=>{
  58. app.showToptip(that, "worning", res.data.msg);
  59. that.data.lastSendTime = Date.now()
  60. that.setData({
  61. canClick: false
  62. })
  63. //定时器触发倒计时,
  64. var times = 60
  65. var i = setInterval(function () {
  66. times--
  67. if (times == 0) {
  68. that.setData({
  69. canClick: true,
  70. codeBtnTxt: "获取验证码",
  71. })
  72. clearInterval(i)
  73. } else {
  74. that.setData({
  75. codeBtnTxt: "重新获取" + times + "s",
  76. })
  77. }
  78. }, 1000)
  79. wx.navigateTo({
  80. url: '/pages/my/my',
  81. })
  82. }).catch(err=>{
  83. app.showToptip(that, "worning", err.data.msg)
  84. })
  85. },
  86. setEmail(e){
  87. this.setData({
  88. email:e.detail.value
  89. })
  90. },
  91. setEmailCode(e){
  92. this.setData({
  93. smsCode:e.detail.value
  94. })
  95. }
  96. })