bindphone.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. loading: false,
  8. phone_uid: '',
  9. },
  10. onShow:function(){
  11. let that = this;
  12. app.isLogin(function(rel){
  13. that.isUsrInfo();
  14. });
  15. },
  16. /**
  17. * 获取用户信息检测是否绑定手机号
  18. */
  19. isUsrInfo: function () {
  20. let that = this;
  21. app.api().Get('openapi/v1/user/getUserInfo', function (res) {
  22. if (res.code == 200) {
  23. that.setData({
  24. phone_uid: res.data.phone_uid
  25. })
  26. }
  27. })
  28. },
  29. /**
  30. * 设置输入手机号
  31. */
  32. getPhoneNumber: function (e) {
  33. let that = this;
  34. var detail = e.detail;
  35. if (detail.errMsg == 'getPhoneNumber:ok'){
  36. var parms = {
  37. encryptedData: detail.encryptedData,
  38. errMsg: detail.errMsg,
  39. iv: detail.iv
  40. }
  41. app.api().Post('openapi/v1/bindWechatPhone', parms, function (rel) {
  42. if (rel.code == 200) {
  43. wx.showModal({
  44. content: rel.msg, showCancel: false,
  45. })
  46. that.setData({
  47. phone_uid: rel.data.phone_uid
  48. })
  49. }
  50. })
  51. }
  52. }
  53. })