帮你贷的小程序

getPhone.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // pages/logs_to/logs_to.js
  2. var app = getApp();
  3. Page({
  4. data: {
  5. from: '',
  6. preid: ''
  7. },
  8. onLoad: function (options) {
  9. },
  10. getPhoneNumber: function(e) {
  11. var that = this;
  12. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  13. console.log(e.detail.errMsg === 'getPhoneNumber:fail user deny');
  14. app.noticeModal('不绑定手机号的话就不能申请了哦');
  15. }else{
  16. let token = wx.getStorageSync('user').token;
  17. that.telHost(token, e.detail.iv, e.detail.encryptedData)
  18. }
  19. },
  20. goSignup () {
  21. var that = this;
  22. var id = that.data.preid;
  23. wx.redirectTo({
  24. url: '/pages/signup/signup?from='+that.data.from+'&preid='+ that.data.preid
  25. })
  26. },
  27. telHost (token, iv, encryptedData) {
  28. var that = this;
  29. wx.request({
  30. url: app.globalData.HOST + '/user/wx/getUserPhone',
  31. method: 'POST',
  32. data: {token: token, iv: iv, encryptedData: encryptedData},
  33. success: function (res) {
  34. var data = res.data
  35. // console.log(data);
  36. if (data.errno == '0'){
  37. var tel = data.rst.phone_number;
  38. wx.setStorage({key:"tel", data: tel})
  39. wx.switchTab({
  40. url: '/pages/index/index'
  41. })
  42. }else{
  43. // app.noticeModal(data.err);
  44. }
  45. }
  46. });
  47. },
  48. onReady: function () {
  49. },
  50. onShow: function () {
  51. },
  52. onHide: function () {
  53. },
  54. onUnload: function () {
  55. }
  56. })