index.js 6.4 KB

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