tab-bar.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // components/house-item/house-item.js
  2. import { isPhoneX } from './../../utils/tools'
  3. let app = getApp()
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. inactiveColor: {
  10. type: String,
  11. value: '#79868F'
  12. },
  13. activeColor: {
  14. type: String,
  15. value: '#1FE4DC'
  16. }
  17. },
  18. /**
  19. * 组件的初始数据
  20. */
  21. data: {
  22. active: 0,
  23. tabItems: [
  24. {
  25. title: '房源',
  26. url: '/pages/index/index',
  27. icon: {
  28. normal: '/image/4Dage/tab/icon_tab_hose_normal@2x.png',
  29. active: '/image/4Dage/tab/icon_tab_hose_active@2x.png'
  30. }
  31. },
  32. {
  33. title: '客源',
  34. url: '/pages/client/client',
  35. icon: {
  36. normal: '/image/4Dage/tab/icon_atab_customer_normal@2x.png',
  37. active: '/image/4Dage/tab/icon_atab_customer_active@2x.png'
  38. }
  39. },
  40. {
  41. title: '消息',
  42. url: '/pages/chat-list/chat-list',
  43. info: 0,
  44. icon: {
  45. normal: '/image/4Dage/tab/icon_atab_msg_normal@2x.png',
  46. active: '/image/4Dage/tab/icon_atab_msg_active@2x.png'
  47. }
  48. },
  49. {
  50. title: '我的',
  51. url: '/pages/my/my',
  52. icon: {
  53. normal: '/image/4Dage/tab/icon_atab_me_normal@2x.png',
  54. active: '/image/4Dage/tab/icon_atab_me_active@2x.png'
  55. }
  56. },
  57. ],
  58. isPhoneX: false
  59. },
  60. attached: function() {
  61. // const currentRoute = getCurrentPages()[0].route
  62. // const { tabItems } = this.data
  63. // tabItems.forEach((item, index) => {
  64. // if (item.url.indexOf(currentRoute) !== -1) {
  65. // this.setData({
  66. // active: index
  67. // })
  68. // }
  69. // })
  70. },
  71. pageLifetimes: {
  72. show () {
  73. const currentRoute = getCurrentPages()[0].route
  74. const { tabItems } = this.data
  75. tabItems[2].info = app.globalData.unViewMsg
  76. console.log('show', app.globalData.unViewMsg)
  77. tabItems.forEach((item, index) => {
  78. if (item.url.indexOf(currentRoute) !== -1) {
  79. this.setData({
  80. active: index,
  81. tabItems: tabItems
  82. })
  83. }
  84. })
  85. isPhoneX().then(res => {
  86. this.setData({
  87. isPhoneX: res
  88. })
  89. })
  90. this.init()
  91. },
  92. hide () {
  93. getApp().getIMHandler().removeOnReceiveMessageListener({listener: this.fn})
  94. }
  95. },
  96. /**
  97. * 组件的方法列表
  98. */
  99. methods: {
  100. onChange(e) {
  101. const index = e.detail, { tabItems } = this.data
  102. getApp().autoSubcrebe()
  103. wx.switchTab({
  104. url: tabItems[index].url,
  105. })
  106. },
  107. init () {
  108. this.fn = (msg) => {
  109. const { tabItems } = this.data
  110. app.globalData.unViewMsg = app.globalData.unViewMsg ? app.globalData.unViewMsg+1 : 1
  111. tabItems[2].info = app.globalData.unViewMsg
  112. this.setData({
  113. tabItems
  114. })
  115. app.getNewMessage(msg)
  116. }
  117. getApp().getIMHandler().setOnReceiveMessageListener({
  118. listener: this.fn
  119. });
  120. }
  121. }
  122. })