index.js 3.3 KB

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