index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. /* 首页宫格授权查询 */
  22. if (wx.getStorageSync('userauth').length != 0) {
  23. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索']),
  24. gridList = [],
  25. subassembly = [];
  26. auth.forEach(v => {
  27. switch (v.systemmodulename) {
  28. case "通告":
  29. gridList.push({
  30. name: "通告",
  31. path: "/pages/annunciate/index",
  32. icon: "icon-a-shouyejingangqutonggao",
  33. apps: v.apps
  34. });
  35. if (v.apps[0].meta.wedgits.some(value => value.wedgit == 'homenoticelist')) subassembly.push('homenoticelist');
  36. this.setData({
  37. annunciateAuthList: v.apps[0].meta.auth.map(v => v.optionname)
  38. });
  39. break;
  40. case "推广素材":
  41. gridList.push({
  42. name: "推广素材",
  43. path: "/pages/promotional/index",
  44. icon: "icon-a-shouyejingangqutuiguangsucai",
  45. apps: v.apps
  46. })
  47. break;
  48. case "商学院":
  49. gridList.push({
  50. name: "商学院",
  51. path: "/pages/college/index",
  52. icon: "icon-a-shangxueyuanxuexi",
  53. apps: v.apps
  54. })
  55. break;
  56. case "提报":
  57. gridList.push({
  58. name: "提报",
  59. path: "/pages/submission/index",
  60. icon: "icon-a-tibaoguanlitibao",
  61. apps: v.apps
  62. })
  63. break;
  64. case "销售线索":
  65. console.log(v.apps)
  66. gridList.push({
  67. name: "销售线索",
  68. path: "/pages/threadedTree/index",
  69. icon: "icon-xiaoshouxiansuo",
  70. apps: v.apps
  71. })
  72. break;
  73. };
  74. });
  75. /* 首页小组件查询 */
  76. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  77. console.log("首页", home)
  78. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  79. this.setData({
  80. gridList,
  81. subassembly
  82. })
  83. }
  84. /* 获取banner */
  85. this.setData({
  86. bannerList: wx.getStorageSync('banner_list')[0].ads
  87. })
  88. this.refreshData(wx.getStorageSync('userMsg'))
  89. this.setData({ //获取胶囊位置信息
  90. capsule: wx.getMenuButtonBoundingClientRect()
  91. })
  92. },
  93. /* 查看通告详情 */
  94. toAnnunciateDetails(e) {
  95. const {
  96. item
  97. } = e.currentTarget.dataset;
  98. let authList = this.data.annunciateAuthList;
  99. wx.navigateTo({
  100. url: `/pages/annunciate/details?id=${item.sat_noticeid}&feedback=${authList.includes('反馈')}&auth=${authList}`,
  101. })
  102. },
  103. /* 获取通告列表 */
  104. queryNoticeList(i) {
  105. if (i == 5) return;
  106. _Http.basic({
  107. "classname": "saletool.notice.notice",
  108. "method": "queryNoticeList",
  109. "content": {
  110. "pageNumber": 1,
  111. "pageSize": 3
  112. }
  113. }).then(res => {
  114. console.log("通告列表", res)
  115. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  116. this.setData({
  117. annunciateList: res.data,
  118. unreadNum: res.total - res.tips.readNum
  119. })
  120. })
  121. },
  122. /* 获取最新信息 */
  123. queryMessage(i) {
  124. if (i == 5) return;
  125. _Http.basic({
  126. "classname": "system.message.Message",
  127. "method": "queryMessage",
  128. content: {
  129. nocache: true,
  130. pageNumber: 1,
  131. pageSize: 3,
  132. pageTotal: 1,
  133. type: "系统"
  134. },
  135. }).then(res => {
  136. if (res.msg != '成功') return this.queryMessage(i + 1);
  137. this.setData({
  138. msgList: res.data,
  139. notice: res.data[0]
  140. })
  141. this.startDataCarousel();
  142. })
  143. },
  144. startDataCarousel() {
  145. clearInterval(DataCarousel);
  146. DataCarousel = setInterval(() => {
  147. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  148. this.setData({
  149. msgCount: count + 1,
  150. notice: this.data.msgList[count]
  151. })
  152. }, 5000)
  153. },
  154. /* 更新站点信息 */
  155. refreshData(item) {
  156. this.setData({
  157. user: item
  158. })
  159. this.queryNoticeList(0); //获取通告列表
  160. this.queryMessage(0)
  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. })