forget.js 6.5 KB

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