forget.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // pages/forget/forget.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. // userName: null,
  8. // email: null,
  9. // checkPass: false,
  10. phone: null,
  11. vcode: null,
  12. checkCode: false,
  13. checkPhone: false,
  14. vcodeFlag: true,
  15. errorMsg: '',
  16. varificatCodeFocus:false,
  17. vcode_button_text: '获取验证码',
  18. scene: "FORGET_PWD",
  19. vcodeTimeOut: 0,
  20. vcodeTimeOutDefault: 0,
  21. vcodeLen: 2,
  22. errorMsg: ''
  23. },
  24. goNext(e){
  25. let that = this;
  26. let { phone, vcode } = this.data;
  27. //跳转到下一步
  28. wx.request({
  29. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/forget',
  30. data: {
  31. phonenumber: phone,
  32. vcode
  33. },
  34. method: 'POST',
  35. success(res) {
  36. if (res.data.code == 1) {
  37. wx.showModal({
  38. title: '提示',
  39. content: res.data.msg,
  40. showCancel: false,
  41. confirmColor:'#00AADD',
  42. });
  43. } else {
  44. //跳转到下一步
  45. let url = `/pages/reset_password/reset_password?phone=`+phone;
  46. wx.redirectTo({
  47. url
  48. });
  49. }
  50. }
  51. });
  52. },
  53. inputPhone(e) {
  54. this.setData({
  55. phone: e.detail.value
  56. });
  57. this.checkAll();
  58. },
  59. inputVerificatrCode(e) {
  60. this.setData({
  61. vcode: e.detail.value
  62. });
  63. this.checkAll();
  64. },
  65. checkAll() {
  66. if (!this.checkPhoneNumber()) {
  67. this.setData({
  68. errorMsg: '手机号输入有误,请重新输入',
  69. checkPhone: false,
  70. checkCode: false
  71. });
  72. return;
  73. } else {
  74. this.setData({
  75. checkPhone: true,
  76. errorMsg: ''
  77. });
  78. }
  79. if (!this.checkVcode()) {
  80. this.setData({
  81. errorMsg: '验证码格式不正确'
  82. });
  83. this.setData({
  84. checkCode: false
  85. });
  86. return;
  87. } else {
  88. this.setData({
  89. errorMsg: ''
  90. });
  91. }
  92. if (this.data.phone && this.data.vcode) {
  93. this.setData({
  94. checkCode: true
  95. });
  96. } else {
  97. this.setData({
  98. checkCode: false
  99. });
  100. }
  101. },
  102. checkPhoneNumber() {
  103. if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
  104. return false;
  105. }
  106. return true;
  107. },
  108. checkVcode() {
  109. if (this.data.vcode==undefined || this.data.vcode=="") {
  110. return false;
  111. }
  112. if(this.data.vcode.length==this.data.vcodeLen){
  113. return true;
  114. }
  115. return false;
  116. },
  117. getVerificateCode(){
  118. let vcodeFlag = this.data.vcodeFlag;
  119. let checkPhone = this.data.checkPhone;
  120. let phone = this.data.phone;
  121. let that = this;
  122. if (!vcodeFlag) {
  123. return;
  124. }
  125. if (!checkPhone) {
  126. that.setData({
  127. errorMsg: '手机号输入有误,请重新输入',
  128. checkCode: false
  129. });
  130. return;
  131. } else {
  132. that.setData({
  133. errorMsg: ''
  134. });
  135. }
  136. this.setData({
  137. vcodeTimeOut:this.data.vcodeTimeOutDefault
  138. })
  139. wx.request({
  140. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/sendPhoneVcodeNoUnique',
  141. data: {
  142. scene: that.data.scene,
  143. terminal: phone,
  144. },
  145. method: 'POST',
  146. success(res) {
  147. if (res.data.code == 1) {
  148. wx.showModal({
  149. title: '提示',
  150. content:res.data.msg,
  151. showCancel:false,
  152. confirmColor:'#00AADD',
  153. });
  154. }else if (res.data.code == 2) {
  155. // 跳转
  156. wx.showModal({
  157. title: '提示',
  158. content: '手机号未绑定账户。若您已注册,请检查手机号是否填写正确或联系客服',
  159. showCancel:false,
  160. confirmText: '确认',
  161. confirmColor:'#00AADD',
  162. success: function (res1) {
  163. }
  164. });
  165. }else if (res.data.code == 200) {
  166. wx.showToast({
  167. title: '验证码已发送',
  168. icon: 'success',
  169. duration: 1000 //持续的时间
  170. })
  171. let vcodeInterval = setInterval(function () {
  172. if (that.data.vcodeTimeOut <= 0) {
  173. that.setData({
  174. vcodeFlag: true,
  175. vcode_button_text: '获取验证码'
  176. })
  177. clearInterval(vcodeInterval);
  178. }else{
  179. let str = '获取验证码'+'(' + that.data.vcodeTimeOut + 's)'
  180. that.setData({
  181. vcodeTimeOut:that.data.vcodeTimeOut-1,
  182. vcodeFlag: false,
  183. vcode_button_text: str
  184. })
  185. }
  186. }, 1000);
  187. }
  188. }
  189. });
  190. },
  191. /**
  192. * 生命周期函数--监听页面加载
  193. */
  194. onLoad: function(options) {
  195. let scene = this.data.scene;
  196. let that = this
  197. wx.request({
  198. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/vcodeInfo',
  199. data: {
  200. scene,
  201. },
  202. method: 'POST',
  203. success(res) {
  204. that.setData({
  205. vcodeInfo:false,
  206. vcodeTimeOut:res.data.result.expire,
  207. vcodeTimeOutDefault:res.data.result.expire,
  208. vcodeLen:res.data.result.len
  209. })
  210. }
  211. });
  212. },
  213. /**
  214. * 生命周期函数--监听页面初次渲染完成
  215. */
  216. onReady: function() {
  217. },
  218. /**
  219. * 生命周期函数--监听页面显示
  220. */
  221. onShow: function() {
  222. },
  223. /**
  224. * 生命周期函数--监听页面隐藏
  225. */
  226. onHide: function() {
  227. },
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function() {
  232. },
  233. /**
  234. * 页面相关事件处理函数--监听用户下拉动作
  235. */
  236. onPullDownRefresh: function() {
  237. },
  238. /**
  239. * 页面上拉触底事件的处理函数
  240. */
  241. onReachBottom: function() {
  242. },
  243. /**
  244. * 用户点击右上角分享
  245. */
  246. onShareAppMessage: function() {
  247. }
  248. })