register.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // pages/login/register.js
  2. let util = require('../../utils/util.js')
  3. const api = require('../../utils/o2Api.js');
  4. Page({
  5. /**
  6. * Page initial data
  7. */
  8. data: {
  9. name: '',
  10. password: '',
  11. confirmPassword: '',
  12. mobile: '',
  13. codeAnswer: '',
  14. genderType: 'm',
  15. focusLabel: '',
  16. sending: false //是否正在发送验证码
  17. },
  18. /**
  19. * Lifecycle function--Called when page load
  20. */
  21. onLoad: function (options) {
  22. },
  23. bindfocusFun: function(event) {
  24. var label = event.currentTarget.dataset.label;
  25. if (label) {
  26. this.setData({
  27. focusLabel: label
  28. });
  29. }
  30. },
  31. bindInputFun: function(event) {
  32. var label = event.currentTarget.dataset.label;
  33. if (label == 'name') {
  34. this.data.name = event.detail.value;
  35. }else if (label == 'password') {
  36. this.data.password = event.detail.value;
  37. }else if (label == 'confirmPassword') {
  38. this.data.confirmPassword = event.detail.value;
  39. }else if (label == 'mobile') {
  40. this.data.mobile = event.detail.value;
  41. }else if (label == 'codeAnswer') {
  42. this.data.codeAnswer = event.detail.value;
  43. }
  44. },
  45. bindSendCode: function(event) {
  46. if (!this.data.mobile || this.data.mobile == '') {
  47. util.toast('请先输入手机号码!');
  48. }else {
  49. api.sendSms(this.data.mobile).then(res => {
  50. console.log('发送验证码', res);
  51. if (res.value) {
  52. util.toast('发送成功!');
  53. }else {
  54. util.toast('发送失败!');
  55. }
  56. }).catch( err => {
  57. api.o2Error(err);
  58. })
  59. }
  60. },
  61. bindTapRegister: function() {
  62. if (this.data.name.length == 0) {
  63. util.toast("请输入用户名!");
  64. return;
  65. }
  66. if (this.data.password.length == 0) {
  67. util.toast("请输入密码!");
  68. return;
  69. }
  70. if (this.data.confirmPassword.length == 0) {
  71. util.toast("请输入确认密码!");
  72. return;
  73. }
  74. if (this.data.confirmPassword != this.data.password) {
  75. util.toast("两次密码输入不一致!");
  76. return;
  77. }
  78. if (this.data.mobile.length == 0) {
  79. util.toast("请输入手机号码!");
  80. return;
  81. }
  82. if (this.data.codeAnswer.length == 0) {
  83. util.toast("请输入手机验证码!");
  84. return;
  85. }
  86. api.register(this.data).then(res => {
  87. console.log(res);
  88. if (res.value) {
  89. util.toast('注册成功!')
  90. wx.navigateBack({
  91. delta: 1,
  92. });
  93. }else {
  94. util.toast('注册失败!')
  95. }
  96. }).catch(err => {
  97. api.o2Error(err, '注册失败!');
  98. })
  99. },
  100. toLogin: function() {
  101. wx.navigateBack({
  102. delta: 1,
  103. });
  104. },
  105. /**
  106. * Lifecycle function--Called when page is initially rendered
  107. */
  108. onReady: function () {
  109. },
  110. /**
  111. * Lifecycle function--Called when page show
  112. */
  113. onShow: function () {
  114. },
  115. /**
  116. * Lifecycle function--Called when page hide
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * Lifecycle function--Called when page unload
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * Page event handler function--Called when user drop down
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * Called when page reach bottom
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * Called when user click on the top right corner to share
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })