Connect.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // pages/mine/wxml/Connect/Connect.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. dataObj: {},
  9. phonename: "",
  10. verificationname: "",
  11. setInformation: true,
  12. countdown: 30,
  13. sendType: true
  14. },
  15. phone: function (e) {
  16. var _this = this;
  17. _this.setData({
  18. phonename: e.detail.value
  19. })
  20. },
  21. verification: function (e) {
  22. var _this = this;
  23. _this.setData({
  24. verificationname: e.detail.value
  25. })
  26. },
  27. //发送验证码
  28. obtain: function (e) {
  29. var _this = this;
  30. var phonenames = this.data.phonename;
  31. var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
  32. if (reg.test(phonenames)) {
  33. wx.getStorage({
  34. key: 'key',
  35. success: function (cookies) {
  36. console.log(cookies.data.ydw_token)
  37. wx.request({
  38. url: app.globalData.prodUrl + 'web-pm/wx/pm/send_mobile_wx',
  39. data: {
  40. mobile: phonenames
  41. },
  42. header: {
  43. 'ydw-token': cookies.data.ydw_token
  44. },
  45. success: function (data) {
  46. if (data.data.success){
  47. wx.showToast({
  48. title: '发送成功',
  49. icon: 'none',
  50. duration: 2000
  51. });
  52. _this.setData({
  53. sesstionid: data.data.sessionid
  54. })
  55. _this.setData({
  56. setInformation: false
  57. })
  58. var num = 30;
  59. var time = setInterval(function () {
  60. num -= 1;
  61. _this.setData({
  62. countdown: num
  63. })
  64. if (num === 0) {
  65. clearInterval(time)
  66. _this.setData({
  67. setInformation: true
  68. })
  69. }
  70. }, 1000)
  71. }else{
  72. wx.showToast({
  73. title: '手机已被注册',
  74. icon: 'none',
  75. duration: 2000
  76. })
  77. }
  78. },
  79. Error: function (data) {
  80. wx.showToast({
  81. title: '发送失败,请重新发送验证码',
  82. icon: 'none',
  83. duration: 2000
  84. })
  85. }
  86. });
  87. }
  88. });
  89. } else {
  90. wx.showToast({
  91. title: '请正确输入手机号',
  92. icon: 'none',
  93. duration: 2000
  94. })
  95. // clearInterval(time)
  96. _this.setData({
  97. setInformation: true
  98. });
  99. }
  100. },
  101. //绑定手机号
  102. signin: function () {
  103. var _this = this;
  104. var verificationname = this.data.verificationname;
  105. var regs = /^\d{4}$/;
  106. var phonenames = this.data.phonename;
  107. var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
  108. if (reg.test(phonenames) && regs.test(verificationname)) {
  109. wx.getStorage({
  110. key: 'key',
  111. success: function (cookies) {
  112. wx.request({
  113. url: app.globalData.prodUrl + 'web-pm/wx/pm/check_mobile_and_code_wx',
  114. data: {
  115. mobile: phonenames,
  116. code: verificationname
  117. },
  118. header: {
  119. 'ydw-token': cookies.data.ydw_token,
  120. 'Cookie': 'JSESSIONID=' + _this.data.sesstionid
  121. },
  122. success: function (data) {
  123. if (data.data.success) {
  124. wx.setStorageSync('persion', { 'persion': data.data.persion });
  125. wx.navigateBack({
  126. delta:1,
  127. success: function () {
  128. var pages = getCurrentPages();
  129. var page = getCurrentPages().pop();
  130. if (page == undefined || page == null) return;
  131. pages[0].onLoad();
  132. }
  133. });
  134. }else{
  135. wx.showToast({
  136. title: '验证码错误',
  137. icon: 'none',
  138. duration: 2000
  139. })
  140. }
  141. }
  142. });
  143. }
  144. });
  145. } else {
  146. wx.showToast({
  147. title: '请正确输入验证码或手机号',
  148. icon: 'none',
  149. duration: 2000
  150. })
  151. }
  152. },
  153. /**
  154. * 生命周期函数--监听页面加载
  155. */
  156. onLoad: function (options) {
  157. },
  158. /**
  159. * 生命周期函数--监听页面初次渲染完成
  160. */
  161. onReady: function () {
  162. },
  163. /**
  164. * 生命周期函数--监听页面显示
  165. */
  166. onShow: function () {
  167. },
  168. /**
  169. * 生命周期函数--监听页面隐藏
  170. */
  171. onHide: function () {
  172. },
  173. /**
  174. * 生命周期函数--监听页面卸载
  175. */
  176. onUnload: function () {
  177. },
  178. /**
  179. * 页面相关事件处理函数--监听用户下拉动作
  180. */
  181. onPullDownRefresh: function () {
  182. },
  183. /**
  184. * 页面上拉触底事件的处理函数
  185. */
  186. onReachBottom: function () {
  187. }
  188. })