You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
3.9 KiB

  1. const config = require('../../../config/config.js')
  2. const Common = require('../../../common/common.js')
  3. const app = getApp()
  4. var interval = null //倒计时函数
  5. Page({
  6. data: {
  7. phone: '',
  8. yzm: '',
  9. flag: true,
  10. retry: false,
  11. time: 60,
  12. phones: "",
  13. date: '请选择日期',
  14. fun_id: 2,
  15. time: '获取验证码', //倒计时
  16. currentTime: 61,
  17. disabled: false,
  18. setInter: ''
  19. },
  20. getCode: function (options) {
  21. var that = this;
  22. var currentTime = that.data.currentTime
  23. that.data.setInter = setInterval(function () {
  24. currentTime--;
  25. that.setData({
  26. time: currentTime + '秒'
  27. })
  28. if (currentTime <= 0) {
  29. clearInterval(that.data.setInter)
  30. that.setData({
  31. time: '获取验证码',
  32. currentTime: 61,
  33. disabled: false
  34. })
  35. }
  36. console.log(that.data.time)
  37. }, 1000)
  38. },
  39. onHide: function () {
  40. let that = this;
  41. clearInterval(that.data.setInter);
  42. that.setData({
  43. time: '获取验证码',
  44. currentTime: 61,
  45. disabled: false
  46. })
  47. },
  48. onUnload: function () {
  49. let that = this;
  50. clearInterval(that.data.setInter)
  51. that.setData({
  52. time: '获取验证码',
  53. currentTime: 61,
  54. disabled: false
  55. })
  56. },
  57. onLoad: function (options) {
  58. if (options.flags == 'reset') {
  59. wx.setNavigationBarTitle({
  60. title: '修改密码'
  61. })
  62. this.setData({
  63. flags: options.flags
  64. })
  65. } else {
  66. wx.setNavigationBarTitle({
  67. title: '忘记密码'
  68. })
  69. }
  70. },
  71. onShow: function () {
  72. let that = this;
  73. that.setData({
  74. phones: wx.getStorageSync("phone"),
  75. disabled: false
  76. });
  77. console.log(that.data.phones)
  78. },
  79. getYZM(e) {
  80. console.log(e, "999");
  81. if (e.detail.value.phone) {
  82. this.setData({
  83. phone: e.detail.value.phone,
  84. yzm: e.detail.value.yzm
  85. })
  86. wx.setStorageSync('phone', e.detail.value.phone)
  87. } else {
  88. this.setData({
  89. phone: wx.getStorageSync("phone"),
  90. yzm: e.detail.value.yzm
  91. })
  92. }
  93. },
  94. next() {
  95. setTimeout(() => {
  96. console.log(this.data)
  97. Common.hasValidationCode(this.data.phone, this.data.yzm)
  98. .then(res => {
  99. console.log(res)
  100. setTimeout(() => {
  101. console.log(res)
  102. if (res.code == 200) {
  103. wx.navigateTo({
  104. url: `../setpwd/setpwd?phone=${this.data.phone}&code=${this.data.yzm}`
  105. })
  106. } else {
  107. wx.showToast({
  108. title: "验证码错误",
  109. icon: "none",
  110. duration: 2000
  111. })
  112. }
  113. }, 500)
  114. })
  115. }, 1000)
  116. },
  117. // 发送验证码
  118. send(e) {
  119. console.log(e);
  120. var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
  121. let that = this;
  122. console.log(this.data.phone, "手机号");
  123. console.log(wx.getStorageSync("phone"), "本地存储手机号")
  124. // setTimeout(() => {
  125. let tel = wx.getStorageSync("phone") || this.data.phone;
  126. if (phoneReg.test(tel)) {
  127. that.setData({
  128. disabled: true
  129. })
  130. Common.sendValidationCode(tel)
  131. .then(res => {
  132. console.log(res);
  133. if (res.code == 200) {
  134. that.getCode();
  135. wx.showToast({
  136. title: res.message,
  137. image: './../../../static/images/success.png'
  138. })
  139. } else if (res.code == 12061) {
  140. wx.showToast({
  141. title: res.message,
  142. icon: "none",
  143. })
  144. } else {
  145. wx.showToast({
  146. title: res.message,
  147. icon: "none",
  148. })
  149. }
  150. })
  151. } else {
  152. if (!tel.length) {
  153. wx.showToast({
  154. title: '请输入手机号',
  155. icon: "none",
  156. })
  157. } else {
  158. wx.showToast({
  159. title: '手机号格式错误',
  160. icon: "none",
  161. })
  162. }
  163. }
  164. // }, 500)
  165. }
  166. })