index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. phoneNumber: '',
  56. },
  57. /**
  58. * 组件的方法列表
  59. */
  60. methods: {
  61. /* tabbar */
  62. onChange(event) {
  63. if (this.data.phoneNumber == '') this.setData({
  64. phoneNumber: getApp().globalData.servicehotline
  65. });
  66. if (event.target.dataset.index == 1) return this.setData({
  67. show: true
  68. })
  69. this.setData({
  70. active: event.target.dataset.index
  71. });
  72. wx.switchTab({
  73. url: this.data.tabbarList[event.target.dataset.index].url
  74. });
  75. },
  76. init() {
  77. const page = getCurrentPages().pop();
  78. this.setData({
  79. active: this.data.tabbarList.findIndex(item => item.url === `/${page.route}`)
  80. });
  81. },
  82. /* 呼叫电话 */
  83. CallOut() {
  84. wx.makePhoneCall({
  85. phoneNumber: getApp().globalData.servicehotline
  86. }).catch((e) => {})
  87. },
  88. onClose() {
  89. this.setData({
  90. show: false
  91. })
  92. },
  93. /* 获取未阅读消息数量查询 */
  94. unReadMessageCount() {
  95. _Http.basic({
  96. "accesstoken": wx.getStorageSync('userData').token,
  97. "classname": "system.message.Message",
  98. "method": "unReadMessageCount",
  99. "content": {}
  100. }).then(res => {
  101. if (res.msg != '成功') console.log('未读消息数量查询失败')
  102. if (res.data[0].fcount == 0) return this.setData({
  103. "tabbarList[3].fcount": ""
  104. })
  105. this.setData({
  106. "tabbarList[3].fcount": res.data[0].fcount
  107. })
  108. })
  109. }
  110. }
  111. })