帮你贷的小程序

signup.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. const app = getApp()
  2. Page({
  3. data: {
  4. mobile: '',
  5. code: '',
  6. showErrMsg: false,
  7. errorMsg: '',
  8. showIcon: false,
  9. codeNotice: '获取验证码',
  10. count: 0,
  11. counting: false,
  12. from: '',
  13. preid: 0
  14. },
  15. onLoad: function (options) {
  16. var from = options.from, preid = options.preid || 0
  17. this.setData({from: from, preid: preid})
  18. console.log(from, preid);
  19. },
  20. onReady: function () {
  21. },
  22. onShow: function () {
  23. },
  24. onHide: function () {
  25. },
  26. onUnload: function () {
  27. },
  28. phoneUpdate: function (e) {
  29. var that = this, value = e.detail.value;
  30. if (value != '') {
  31. that.setData({
  32. mobile: value,
  33. showIcon: true
  34. })
  35. } else {
  36. that.setData({
  37. mobile: value,
  38. showIcon: false
  39. })
  40. }
  41. },
  42. // 点击x号清空input
  43. clearPhone: function(e){
  44. this.setData({
  45. mobile: '',
  46. showIcon: false
  47. })
  48. },
  49. codeUpdate: function (e) {
  50. this.setData({
  51. code: e.detail.value
  52. })
  53. },
  54. hideErrMsg () {
  55. this.setData({
  56. showErrMsg: false
  57. })
  58. },
  59. countDown: function (count) {
  60. var that = this;
  61. that.setData({
  62. counting: true,
  63. codeNotice: count + ' 秒后重新获取'
  64. })
  65. setTimeout(function () {
  66. if (count > 1) {
  67. count--;
  68. that.countDown(count);
  69. that.setData({
  70. counting: true,
  71. codeNotice: count + ' 秒后重新获取'
  72. })
  73. return;
  74. } else if (count == 1) {
  75. that.setData({
  76. codeNotice: '获取验证码',
  77. counting: false
  78. })
  79. return;
  80. }
  81. }, 1000);
  82. },
  83. getCode: function (e) {
  84. var that = this, token = wx.getStorageSync('user').token;
  85. var phone = that.data.mobile, codeNotice = that.data.codeNotice;
  86. if (token) {
  87. if (!(/^1[34578]\d{9}$/.test(phone))) {
  88. that.setData({
  89. showErrMsg: true,
  90. errorMsg: '手机号格式不正确'
  91. })
  92. } else {
  93. if (codeNotice == '获取验证码') {
  94. that.countDown(60);
  95. const dataParam = Object.assign({}, app.globalData.common, {
  96. phone: phone
  97. })
  98. wx.request({
  99. url: app.globalData.HOST + '/user/wx/sendCode',
  100. method: 'POST',
  101. data: dataParam,
  102. success: function (errno) {
  103. if (errno.data.errno == '0') {
  104. }
  105. }
  106. });
  107. }else{
  108. that.setData({
  109. showErrMsg: true,
  110. errorMsg: '请在计时结束后,再重新获取'
  111. })
  112. }
  113. }
  114. } else {
  115. app.login(that);
  116. }
  117. },
  118. // 提交登录
  119. goLogin: function (e) {
  120. var that = this;
  121. var token = wx.getStorageSync('user').token, phone = that.data.mobile, code = that.data.code,
  122. from = that.data.from, preid = that.data.preid;
  123. phone = phone.replace(/(^\s*)|(\s*$)/g, "");
  124. code = code.replace(/(^\s*)|(\s*$)/g, "");
  125. // 信息不为空
  126. if (phone && code && token) {
  127. // 手机号格式正确
  128. if (!(/^1[34578]\d{9}$/.test(phone))) {
  129. that.setData({
  130. showErrMsg: true,
  131. errorMsg: '手机号格式不正确'
  132. })
  133. }else{
  134. const dataParam = Object.assign({}, app.globalData.common, {
  135. phone: phone,
  136. code: code
  137. })
  138. wx.request({
  139. url: app.globalData.HOST + '/user/wx/bindMobile',
  140. method: 'POST',
  141. data: dataParam,
  142. success: function (res) {
  143. if (res.data.errno == '0') {
  144. wx.setStorage({key:"tel", data: phone})
  145. if (from === 'mine') {
  146. wx.redirectTo({
  147. url: '/pages/application/application?tel=' + phone
  148. })
  149. }else if(from === 'mineFeedback'){
  150. wx.redirectTo({
  151. url: '/pages/feedback/feedback?tel=' + phone
  152. })
  153. }else{
  154. wx.redirectTo({
  155. url: '/pages/getIt/getIt?from='+ from +'&preid='+ preid +'&tel=' + phone
  156. })
  157. }
  158. }else{
  159. that.setData({
  160. showErrMsg: true,
  161. errorMsg: res.data.err
  162. })
  163. }
  164. }
  165. });
  166. }
  167. }else{
  168. that.setData({
  169. showErrMsg: true,
  170. errorMsg: '信息填写不完整'
  171. })
  172. }
  173. }
  174. })