index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. handleFieldChange: function(e) {
  16. console.log(this.data.phone)
  17. console.log(e)
  18. },
  19. formSubmit: e => {
  20. if(!e.detail.value.phone) {
  21. wx.showToast({
  22. title: '手机号不能为空',
  23. })
  24. // wx.request({
  25. // url: api.bindPhoneUrl,
  26. // method: 'GET',
  27. // data: {
  28. // 'id': wx.getStorageSync('we_chat_user_id'),
  29. // 'phone': e.detail.value.phone
  30. // }
  31. // })
  32. }
  33. },
  34. getPhoneNumber: function(e) {
  35. var that = this;
  36. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  37. wx.request({
  38. url: api.getPhoneUrl,
  39. method: 'POST',
  40. data: {
  41. 'id': wx.getStorageSync('we_chat_user_id'),
  42. 'iv': e.detail.iv,
  43. 'encryptedData': e.detail.encryptedData,
  44. },
  45. success: res => {
  46. console.log(res)
  47. if(res.data.status == 'success') {
  48. that.setData({
  49. phone: res.data.phone
  50. })
  51. } else if(res.data.status == 'fail') {
  52. wx.showToast({
  53. title: res.data.info,
  54. })
  55. }
  56. }
  57. })
  58. }
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. },
  80. /**
  81. * 页面相关事件处理函数--监听用户下拉动作
  82. */
  83. onPullDownRefresh: function () {
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. }
  95. })