index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. const _Http = getApp().globalData.http;
  2. let DataCarousel = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. user: {},
  9. annunciateList: [], //通告列表
  10. gridList: [],
  11. showAnnunciate: false, //显示最新通告
  12. unreadNum: 0, //通告未读
  13. notice: "",
  14. msgCount: 1,
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. if (wx.getStorageSync('userauth').length != 0) {
  21. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报']);
  22. let gridList = [];
  23. auth.forEach(v => {
  24. switch (v.systemmodulename) {
  25. case "通告":
  26. gridList.push({
  27. name: "通告",
  28. path: "/pages/annunciate/index",
  29. icon: "icon-a-shouyejingangqutonggao",
  30. apps: v.apps
  31. });
  32. let annunciateAuthList = v.apps[0].meta.auth.map(v => v.optionname);
  33. this.setData({
  34. showAnnunciate: true,
  35. annunciateAuthList
  36. });
  37. break;
  38. case "推广素材":
  39. gridList.push({
  40. name: "推广素材",
  41. path: "/pages/promotional/index",
  42. icon: "icon-a-shouyejingangqutuiguangsucai",
  43. apps: v.apps
  44. })
  45. break;
  46. case "商学院":
  47. gridList.push({
  48. name: "商学院",
  49. path: "/pages/college/index",
  50. icon: "icon-a-shangxueyuanxuexi",
  51. apps: v.apps
  52. })
  53. break;
  54. case "提报":
  55. gridList.push({
  56. name: "提报",
  57. path: "/pages/submission/index",
  58. icon: "icon-a-tibaoguanlitibao",
  59. apps: v.apps
  60. })
  61. break;
  62. };
  63. });
  64. this.setData({
  65. gridList
  66. })
  67. }
  68. this.refreshData(wx.getStorageSync('userMsg'))
  69. this.setData({ //获取胶囊位置信息
  70. capsule: wx.getMenuButtonBoundingClientRect()
  71. })
  72. },
  73. /* 查看通告详情 */
  74. toAnnunciateDetails(e) {
  75. const {
  76. item
  77. } = e.currentTarget.dataset;
  78. let authList = this.data.annunciateAuthList;
  79. wx.navigateTo({
  80. url: `/pages/annunciate/details?id=${item.sat_noticeid}&feedback=${authList.includes('反馈')}&auth=${authList}`,
  81. })
  82. },
  83. /* 获取通告列表 */
  84. queryNoticeList(i) {
  85. if (i == 5) return;
  86. _Http.basic({
  87. "classname": "saletool.notice.notice",
  88. "method": "queryNoticeList",
  89. "content": {
  90. "pageNumber": 1,
  91. "pageSize": 3
  92. }
  93. }).then(res => {
  94. console.log("通告列表", res)
  95. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  96. this.setData({
  97. annunciateList: res.data,
  98. unreadNum: res.total - res.tips.readNum
  99. })
  100. })
  101. },
  102. /* 获取最新信息 */
  103. queryMessage(i) {
  104. if (i == 5) return;
  105. _Http.basic({
  106. "classname": "system.message.Message",
  107. "method": "queryMessage",
  108. content: {
  109. nocache: true,
  110. pageNumber: 1,
  111. pageSize: 3,
  112. pageTotal: 1,
  113. type: "系统"
  114. },
  115. }).then(res => {
  116. if (res.msg != '成功') return this.queryMessage(i + 1);
  117. this.setData({
  118. msgList: res.data,
  119. notice: res.data[0]
  120. })
  121. this.startDataCarousel();
  122. })
  123. },
  124. startDataCarousel() {
  125. clearInterval(DataCarousel);
  126. DataCarousel = setInterval(() => {
  127. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  128. console.log(count)
  129. this.setData({
  130. msgCount: count + 1,
  131. notice: this.data.msgList[count]
  132. })
  133. }, 5000)
  134. },
  135. /* 更新站点信息 */
  136. refreshData(item) {
  137. this.setData({
  138. user: item
  139. })
  140. this.queryNoticeList(0); //获取通告列表
  141. this.queryMessage(0)
  142. },
  143. /* 宫格区域应用程序 */
  144. applications(e) {
  145. const {
  146. item
  147. } = e.currentTarget.dataset;
  148. wx.navigateTo({
  149. url: `${item.path}?auth=${JSON.stringify(item.apps)}`,
  150. });
  151. },
  152. /* 去消息详情 */
  153. toMsg(e) {
  154. const {
  155. item
  156. } = e.currentTarget.dataset;
  157. wx.navigateTo({
  158. url: '/pages/tabbar/message/details?id=' + item.objectid,
  159. })
  160. },
  161. /* 去通告 */
  162. toAnnunciate() {
  163. this.applications({
  164. currentTarget: {
  165. dataset: {
  166. item: this.data.gridList.find(v => v.name == '通告')
  167. }
  168. }
  169. })
  170. },
  171. /**
  172. * 生命周期函数--监听页面显示
  173. */
  174. onShow() {
  175. this.getTabBar().init();
  176. this.startDataCarousel();
  177. },
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide() {
  182. clearInterval(DataCarousel);
  183. },
  184. })