index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. let _Http = getApp().globalData.http,
  2. DataCarousel = null;
  3. import {
  4. initWorkbench,
  5. isHistory,
  6. isRemindChangePassword
  7. } from "../../../utils/work/work";
  8. Page({
  9. data: {
  10. appid: 'wxc1b6ae925ac1d06a',
  11. bannerList: [], //banner列表
  12. gridList: [],
  13. notice: "",
  14. msgCount: 1,
  15. msgList: [], //消息列表
  16. },
  17. onLoad(options) {
  18. this.setData({ //获取胶囊位置信息
  19. capsule: wx.getMenuButtonBoundingClientRect()
  20. })
  21. this.refreshData() //更新权限等信息
  22. this.getTabBar().unReadMessageCount(); //更新信息数量
  23. isHistory();
  24. isRemindChangePassword();
  25. },
  26. /* 更新站点信息 */
  27. refreshData() {
  28. this.setData({
  29. user: wx.getStorageSync('userMsg')
  30. })
  31. if (wx.getStorageSync('userauth').length != 0) {
  32. initWorkbench(this)
  33. } else {
  34. setTimeout(this.refreshData, 10);
  35. return;
  36. }
  37. },
  38. /* 获取最新信息 */
  39. queryMessage(i = 0) {
  40. _Http.basic({
  41. "classname": "system.message.Message",
  42. "method": "queryMessage",
  43. content: {
  44. nocache: true,
  45. pageNumber: 1,
  46. pageSize: 5,
  47. pageTotal: 1,
  48. type: "",
  49. where: {}
  50. },
  51. }, false).then(res => {
  52. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  53. title: res.msg,
  54. icon: "none"
  55. })
  56. const authComparison = wx.getStorageSync('authComparison');
  57. res.data = res.data.map(v => {
  58. let data = authComparison.find(s => (s.objectname || "") == v.objectname);
  59. if (data) {
  60. switch (data.objectname) {
  61. case "sa_customers":
  62. data.name = '客户'
  63. //客户
  64. break;
  65. case "sat_orderclue":
  66. data.name = '线索'
  67. //线索
  68. break;
  69. case "sa_order":
  70. data.name = '订单'
  71. break;
  72. }
  73. return Object.assign(v, data)
  74. }
  75. return v
  76. })
  77. this.setData({
  78. msgList: res.data,
  79. notice: res.data[0]
  80. })
  81. if (this.data.msgList.length > 2) this.startDataCarousel();
  82. })
  83. },
  84. /* 开启消息轮播 */
  85. startDataCarousel() {
  86. clearInterval(DataCarousel);
  87. DataCarousel = setInterval(() => {
  88. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  89. this.setData({
  90. msgCount: count + 1,
  91. notice: this.data.msgList[count]
  92. })
  93. }, 5000)
  94. },
  95. /* 去消息详情 */
  96. toMsg(e) {
  97. const {
  98. item
  99. } = e.currentTarget.dataset;
  100. wx.navigateTo({
  101. url: '/pages/tabbar/message/details?item=' + JSON.stringify(item)
  102. })
  103. },
  104. /* banner */
  105. bannerClick(e) {
  106. const {
  107. item
  108. } = e.currentTarget.dataset,
  109. hyperlink = item.hyperlink.split(":");
  110. if (hyperlink[0] == 'path') wx.navigateTo({
  111. url: hyperlink[1]
  112. })
  113. },
  114. onShow() {
  115. this.getTabBar().init();
  116. if (this.data.msgList.length > 2) this.startDataCarousel();
  117. this.queryMessage(0); //更新最新消息
  118. },
  119. onHide() {
  120. clearInterval(DataCarousel);
  121. },
  122. /* 设置页面高度 */
  123. setListHeight() {
  124. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  125. }
  126. })