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

204 lines
4.5KB

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