my.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {loginByUserInfo ,Login}from './../../utils/login'
  2. console.log(Login)
  3. import Toast from '../../components/vant-ui/toast/toast';
  4. import {
  5. subcribe
  6. } from '../../utils/utils'
  7. const app = getApp();
  8. Page({
  9. options: {
  10. addGlobalClass: true,
  11. },
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. cu_items: [{
  17. title: '我关注的房源',
  18. icon: 'house',
  19. value: '/pages/follow-list/follow-list'
  20. },
  21. {
  22. title: '关于我们',
  23. icon: 'about',
  24. value: '/pages/about/about'
  25. },
  26. {
  27. title: '消息订阅',
  28. icon: 'guanzhu',
  29. action: 'dingyue',
  30. value: 'null'
  31. }
  32. ],
  33. user_code: '',
  34. isLogined: app.globalData.token ? true : false,
  35. userinfo: app.globalData.userinfo
  36. },
  37. Navigator_to(e) {
  38. const {
  39. value,
  40. action
  41. } = e.currentTarget.dataset
  42. if (value) {
  43. if (action === 'dingyue') {
  44. this.subscribeMessage()
  45. return
  46. }
  47. wx.navigateTo({
  48. url: value,
  49. })
  50. }
  51. },
  52. toModifyUser() {
  53. if (!this.data.isLogined) {
  54. return
  55. }
  56. wx.navigateTo({
  57. url: '/pages/user-info/user-info',
  58. })
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad: function (e) {
  64. this.getSubscribeStatus()
  65. wx.login({
  66. success: (res) => {
  67. this.setData({
  68. user_code: res.code
  69. })
  70. }
  71. })
  72. },
  73. onShow: function () {
  74. this.setData({
  75. isLogined: app.globalData.token ? true : false,
  76. userinfo: app.globalData.userinfo
  77. });
  78. },
  79. getPhoneNumber(e) {
  80. Login(e, this.data.user_code, true).then(res => {
  81. this.setData({
  82. isLogined: app.globalData.token ? true : false,
  83. userinfo: app.globalData.userinfo
  84. })
  85. })
  86. },
  87. bindgetuserinfo(e) {
  88. // login(e, this.data.user_code, true).then(res => {
  89. loginByUserInfo(e, this.data.user_code, true).then(res => {
  90. this.setData({
  91. isLogined: app.globalData.token ? true : false,
  92. userinfo: app.globalData.userinfo
  93. })
  94. })
  95. },
  96. getSubscribeStatus() {
  97. wx.getSetting({
  98. withSubscriptions: true,
  99. success: (setting) => {
  100. // if (setting.subscriptionsSetting.itemSettings && setting.subscriptionsSetting.itemSettings['GApxDrE3tPhysRxHEmGHRn-0mvNJXqtZ4znZ8PJnQ8Q']) {
  101. if (setting.subscriptionsSetting.itemSettings && setting.subscriptionsSetting.itemSettings['zWTBJFpALA3KR3qx1keYJCzJdVtRjFbxrnOJc_Htn-g']) {
  102. this.setData({
  103. cu_items: [{
  104. title: '我关注的房源',
  105. icon: 'house',
  106. value: '/pages/follow-list/follow-list'
  107. },
  108. {
  109. title: '关于我们',
  110. icon: 'about',
  111. value: '/pages/about/about'
  112. }
  113. ]
  114. })
  115. }
  116. },
  117. })
  118. },
  119. subscribeMessage() {
  120. subcribe().then(res => {
  121. wx.getSetting({
  122. withSubscriptions: true,
  123. success: (setting) => {
  124. if (setting.subscriptionsSetting.itemSettings && setting.subscriptionsSetting.itemSettings[res.subId]) {
  125. this.setData({
  126. cu_items: [{
  127. title: '我关注的房源',
  128. icon: 'house',
  129. value: '/pages/follow-list/follow-list'
  130. },
  131. {
  132. title: '关于我们',
  133. icon: 'about',
  134. value: '/pages/about/about'
  135. }
  136. ]
  137. })
  138. return
  139. }
  140. Toast({
  141. message: '请勾选:总是保持以上选择,不再询问'
  142. });
  143. },
  144. })
  145. })
  146. return
  147. }
  148. })