1
0

newuser.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var api = require('../../../config/api.js');
  2. var util = require('../../../utils/util.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. phone: '',
  10. smscode: '',
  11. second: '发送验证码',
  12. disabled: false
  13. },
  14. clearPhone(){
  15. this.setData({
  16. phone: ''
  17. });
  18. },
  19. clearCode(){
  20. this.setData({
  21. smscode: ''
  22. });
  23. },
  24. bindPhoneInput: function (e) {
  25. this.setData({
  26. phone: e.detail.value
  27. });
  28. },
  29. bindSmscodeInput: function (e) {
  30. this.setData({
  31. smscode: e.detail.value
  32. });
  33. },
  34. /**
  35. * 用户领券
  36. */
  37. getCoupon: function () {
  38. var that = this;
  39. let regular = /^1[3|4|5|7|8]\d{9}$/;
  40. if (!regular.test(that.data.phone)) {
  41. util.showErrorToast('手机格式不正确')
  42. return false;
  43. }
  44. if (that.data.smscode.length < 4) {
  45. util.showErrorToast('短信码至少是4位')
  46. return false;
  47. }
  48. util.request(api.newUserCoupn, {
  49. smscode: that.data.smscode,
  50. phone: that.data.phone
  51. }, 'POST').then(function (res) {
  52. if (res.errno === 0) {
  53. wx.redirectTo({ url: '/pages/ucenter/coupon/coupon' });
  54. } else if (res.errno === 1) {
  55. // util.showErrorToast(res.errmsg);
  56. wx.showModal({
  57. title: '提示信息',
  58. content: res.errmsg,
  59. showCancel: false
  60. });
  61. }
  62. });
  63. },
  64. /**
  65. * 发送短信
  66. */
  67. smscode: function () {
  68. var that = this;
  69. let regular = /^1[3|4|5|7|8]\d{9}$/;
  70. if (!regular.test(that.data.phone)) {
  71. util.showErrorToast('手机格式不正确')
  72. return false;
  73. }
  74. util.request(api.smscodeSend, {
  75. mobile: that.data.phone
  76. }, 'POST').then(function (res) {
  77. let n = 59;
  78. var timer = setInterval(function () {
  79. if (n == 0) {
  80. clearInterval(timer);
  81. that.setData({
  82. second: '发送验证码',
  83. disabled: false
  84. });
  85. } else {
  86. that.setData({
  87. second: n-- +'s后重新获取',
  88. disabled: true
  89. });
  90. }
  91. }, 1000);
  92. if (res.errno == 0) {
  93. wx.showToast({
  94. title: '短信发送成功'
  95. })
  96. } else if (res.errno == 1) {
  97. wx.showToast({
  98. title: '短信已发送'
  99. })
  100. }
  101. });
  102. },
  103. /**
  104. * 生命周期函数--监听页面加载
  105. */
  106. onLoad: function (options) {
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload: function () {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh: function () {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function () {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage: function () {
  142. }
  143. })