东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

211 Zeilen
4.7KB

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