index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import {
  2. ApiModel
  3. } from "../utils/api";
  4. const _Http = new ApiModel();
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {},
  10. lifetimes: {
  11. attached() {},
  12. ready: function () {
  13. // 在组件实例进入页面节点树时执行
  14. this.unReadMessageCount();
  15. },
  16. },
  17. /**
  18. * 组件的初始数据
  19. */
  20. data: {
  21. active: 0,
  22. tabbarList: [{
  23. icon: '/static/tabbar-icon/home.png',
  24. iconA: '/static/tabbar-icon/home-a.png',
  25. text: '首页',
  26. url: '/pages/tabbar-pages/home/index'
  27. },
  28. {
  29. icon: '/static/tabbar-icon/service.png',
  30. iconA: '/static/tabbar-icon/service-a.png',
  31. text: '在线客服',
  32. url: '/pages/tabbar-pages/customer-service-staff/index'
  33. },
  34. {
  35. icon: '/static/tabbar-icon/bazaar.png',
  36. iconA: '/static/tabbar-icon/bazaar-a.png',
  37. text: '供需广场',
  38. url: '/pages/tabbar-pages/supplyAndDemand/index'
  39. },
  40. {
  41. icon: '/static/tabbar-icon/message.png',
  42. iconA: '/static/tabbar-icon/message-a.png',
  43. text: '消息',
  44. url: '/pages/tabbar-pages/message/index',
  45. fcount: ""
  46. },
  47. {
  48. icon: '/static/tabbar-icon/user.png',
  49. iconA: '/static/tabbar-icon/user-a.png',
  50. text: '我的',
  51. url: '/pages/tabbar-pages/user/index'
  52. }
  53. ],
  54. show: false
  55. },
  56. /**
  57. * 组件的方法列表
  58. */
  59. methods: {
  60. /* tabbar */
  61. onChange(event) {
  62. if (event.target.dataset.index == 1) return this.setData({
  63. show: true
  64. })
  65. this.setData({
  66. active: event.target.dataset.index
  67. });
  68. wx.switchTab({
  69. url: this.data.tabbarList[event.target.dataset.index].url
  70. });
  71. },
  72. init() {
  73. const page = getCurrentPages().pop();
  74. this.setData({
  75. active: this.data.tabbarList.findIndex(item => item.url === `/${page.route}`)
  76. });
  77. },
  78. /* 呼叫电话 */
  79. CallOut() {
  80. wx.makePhoneCall({
  81. phoneNumber: getApp().globalData.servicehotline
  82. }).catch((e) => {
  83. })
  84. },
  85. onClose() {
  86. this.setData({
  87. show: false
  88. })
  89. },
  90. /* 获取未阅读消息数量查询 */
  91. unReadMessageCount() {
  92. _Http.basic({
  93. "accesstoken": wx.getStorageSync('userData').token,
  94. "classname": "system.message.Message",
  95. "method": "unReadMessageCount",
  96. "content": {}
  97. }).then(res => {
  98. if (res.msg != '成功') console.log('未读消息数量查询失败')
  99. if (res.data[0].fcount == 0) return this.setData({
  100. "tabbarList[3].fcount": ""
  101. })
  102. this.setData({
  103. "tabbarList[3].fcount": res.data[0].fcount
  104. })
  105. })
  106. }
  107. }
  108. })