my.js 3.5 KB

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