东风启辰小程序端
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.

mobileVerification.js 5.2KB

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