东风启辰小程序端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

mobileVerification.js 4.7KB

5 år sedan
5 år sedan
5 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // pages/mobileVerification/mobileVerification.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. isAgreement: true,//是否同意协议
  10. verificationCode: '获取验证码',//验证码文案
  11. sendCode: true,
  12. mobileText:"",//手机号
  13. verificationText:null,
  14. getMobileBtnShow:true,
  15. agreement:false,//是否显示协议
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. if (app.globalData.userMobile) {
  22. this.setData({
  23. getMobileBtnShow: false,
  24. mobileText: app.globalData.userMobile
  25. })
  26. }
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {
  47. },
  48. /**
  49. * 页面相关事件处理函数--监听用户下拉动作
  50. */
  51. onPullDownRefresh: function () {
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. return app.sharePack();
  63. },
  64. agreementState: function () {//协议
  65. this.setData({
  66. isAgreement: !this.data.isAgreement
  67. })
  68. },
  69. getCode: function (e) {//获取验证码
  70. if (!app.mobileVerify(this.data.mobileText)) {
  71. if (this.data.mobileText) {
  72. wx.showToast({
  73. title: '请输入正确的电话',
  74. icon: 'none'
  75. })
  76. } else {
  77. wx.showToast({
  78. title: '请输入电话',
  79. icon: 'none'
  80. })
  81. }
  82. return;
  83. }
  84. if (!this.data.sendCode) {
  85. return;
  86. }
  87. this.data.sendCode = false;
  88. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobileText }, res => {
  89. if (res.code == 200) {
  90. this.countDown();
  91. wx.showToast({
  92. title: '验证码获取成功',
  93. icon: "none"
  94. })
  95. this.setData({
  96. verificationCode: 60
  97. })
  98. } else {
  99. this.data.sendCode = true;
  100. wx.showToast({
  101. title: res.msg,
  102. icon: "none"
  103. })
  104. }
  105. }, this)
  106. },
  107. countDown: function () {//倒计时
  108. setTimeout(() => {
  109. this.setData({
  110. verificationCode: this.data.verificationCode - 1
  111. })
  112. if (this.data.verificationCode > 0) {
  113. this.countDown();
  114. } else {
  115. this.setData({
  116. verificationCode: "获取验证码"
  117. })
  118. this.data.sendCode = true;
  119. }
  120. }, 1000);
  121. },
  122. getMoblie:function(e){//获取用户输入的手机号
  123. this.data.mobileText = e.detail.value
  124. },
  125. getCodeText: function (e) {//获取用户输入的手机号
  126. this.data.verificationText = e.detail.value
  127. },
  128. submitMobile: function (){
  129. if (!app.mobileVerify(this.data.mobileText)) {
  130. if (this.data.mobileText) {
  131. wx.showToast({
  132. title: '请输入正确的电话',
  133. icon: 'none'
  134. })
  135. } else {
  136. wx.showToast({
  137. title: '请输入电话',
  138. icon: 'none'
  139. })
  140. }
  141. return;
  142. }
  143. if (!this.data.verificationText) {
  144. wx.showToast({
  145. title: '请输入验证码',
  146. icon: 'none'
  147. })
  148. return;
  149. }
  150. if (!this.data.isAgreement) {
  151. wx.showToast({
  152. title: '请同意协议',
  153. icon: 'none'
  154. })
  155. return;
  156. }
  157. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfo", { mobile: this.data.mobileText, captcha: this.data.verificationText }, res => {
  158. if (res.code == 200) {
  159. wx.setStorageSync('userMobile', this.data.mobileText );
  160. app.globalData.userMobile = this.data.mobileText ;
  161. if (res.data != null) {
  162. app.globalData.certificationState = res.data.certificationState;
  163. wx.redirectTo({
  164. url: '../scout/scout'
  165. })
  166. } else {
  167. wx.redirectTo({
  168. url: '../scout/register/register'
  169. })
  170. }
  171. }
  172. }, this);
  173. },
  174. getPhone(e) {
  175. this.setData({
  176. getMobileBtnShow:false
  177. })
  178. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  179. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  180. if (res.code == 200) {
  181. if (res.data && res.data.decodeData) {
  182. this.setData({
  183. mobileText: res.data.decodeData.phoneNumber
  184. })
  185. }
  186. }
  187. }, this)
  188. }
  189. },
  190. agreementControl:function(){
  191. this.setData({
  192. agreement: !this.data.agreement
  193. })
  194. }
  195. })