forget.js 5.8 KB

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