index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // pages/bind-phone/index.js
  2. const api = require('../../utils/api.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. phone: ''
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. },
  15. formSubmit: e => {
  16. if(!e.detail.value.phone) {
  17. wx.showToast({
  18. icon: 'none',
  19. title: '手机号不能为空',
  20. })
  21. } else {
  22. wx.request({
  23. url: api.bindPhoneUrl,
  24. method: 'GET',
  25. data: {
  26. 'id': wx.getStorageSync('we_chat_user_id'),
  27. 'phone': e.detail.value.phone
  28. },
  29. success: res => {
  30. if (res.data.status == 'success') {
  31. wx.setStorageSync('pt_student', res.data.data)
  32. wx.switchTab({
  33. url: '/pages/index/index',
  34. })
  35. } else if (res.data.status == 'fail') {
  36. wx.showToast({
  37. icon: 'none',
  38. title: res.data.info,
  39. })
  40. }
  41. }
  42. })
  43. }
  44. },
  45. getPhoneNumber: function(e) {
  46. var that = this;
  47. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  48. wx.request({
  49. url: api.getPhoneUrl,
  50. method: 'POST',
  51. data: {
  52. 'id': wx.getStorageSync('we_chat_user_id'),
  53. 'iv': e.detail.iv,
  54. 'encryptedData': e.detail.encryptedData,
  55. },
  56. success: res => {
  57. if(res.data.status == 'success') {
  58. that.setData({
  59. phone: res.data.phone
  60. })
  61. } else if(res.data.status == 'fail') {
  62. wx.showToast({
  63. title: res.data.info,
  64. })
  65. }
  66. }
  67. })
  68. }
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage: function () {
  104. }
  105. })