index.js 6.9 KB

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