index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. const _Http = getApp().globalData.http;
  2. let DataCarousel = null,
  3. funs = {};
  4. Page({
  5. data: {
  6. msgCount: 1,
  7. subassembly: [], //首页部件
  8. msgList: [], //消息列表
  9. capsule: wx.getMenuButtonBoundingClientRect(), //胶囊位置信息
  10. },
  11. onLoad(options) {
  12. this.refreshData() //更新权限等信息
  13. getApp().globalData.http.refreshData = this.refreshData.bind(this);
  14. },
  15. /* 更新站点信息 */
  16. refreshData() {
  17. this.setData({
  18. user: wx.getStorageSync('userMsg')
  19. })
  20. if (wx.getStorageSync('userauth').length != 0) {
  21. let authList = {},
  22. gridList = [];
  23. const apps = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索', '营销物料']),
  24. paths = [{
  25. label: "通告",
  26. name: "wnotice",
  27. path: "/pages/annunciate/index",
  28. icon: "icon-a-shouyejingangqutonggao"
  29. }, {
  30. label: "商学院",
  31. name: "warchives_sc",
  32. path: "/pages/classroom/index",
  33. icon: "icon-a-shangxueyuanxuexi"
  34. }, {
  35. label: "营销物料",
  36. name: "warchives",
  37. path: "/pages/tabbar/smartStore/index",
  38. icon: "icon-a-shouyejingangquyingxiaowuliao"
  39. }, {
  40. label: "销售线索",
  41. name: "worderclue",
  42. path: "/pages/threadedTree/index",
  43. icon: "icon-xiaoshouxiansuo"
  44. }, {
  45. label: "推广素材",
  46. name: "wpopularize",
  47. path: "/pages/promotional/index",
  48. icon: "icon-a-shouyejingangqutuiguangsucai"
  49. }, {
  50. label: "提报",
  51. name: "wsubmitedit",
  52. path: "/pages/submission/index",
  53. icon: "icon-a-tibaoguanlitibao"
  54. }];
  55. apps.forEach(v => {
  56. v.apps.forEach(s => {
  57. authList[s.name] = {
  58. options: s.meta.auth.map(a => a.option),
  59. optionnames: s.meta.auth.map(a => a.optionname),
  60. }
  61. if (authList[s.name].options.some(s => s == "read")) {
  62. if (s.name == "worderclue") {
  63. //更新销售线索徽标数据
  64. funs.getCount = () => {
  65. const index = this.data.gridList.findIndex(v => v.label == '销售线索');
  66. if (index == -1) return;
  67. _Http.basic({
  68. "classname": "saletool.orderclue.web.orderclue",
  69. "method": "getCount",
  70. "content": {
  71. "nocache": true,
  72. "status": "待跟进"
  73. }
  74. }, false).then(res => {
  75. if (res.data.count == 0) res.data.count = '';
  76. if (res.data.count > 99) res.data.count = '99+';
  77. try {
  78. this.data.gridList[index].count = res.data.count;
  79. } catch (e) {}
  80. this.setData({
  81. gridList: this.data.gridList
  82. })
  83. })
  84. };
  85. } else if (s.name == "wnotice" && s.meta.wedgits.find(a => a.wedgit == 'homenoticelist')) {
  86. //更新通告数据
  87. funs.queryNoticeList = () => {
  88. _Http.basic({
  89. "classname": "saletool.notice.notice",
  90. "method": "queryNoticeList",
  91. "content": {
  92. "nocache": true,
  93. "pageNumber": 1,
  94. "pageSize": 3
  95. }
  96. }, false).then(res => {
  97. if (res.msg != '成功') return;
  98. this.setData({
  99. annunciateList: res.data,
  100. unreadNum: res.total - res.tips.readNum
  101. })
  102. });
  103. };
  104. }
  105. let data = paths.find(k => {
  106. return k.name == s.name
  107. });
  108. if (data) {
  109. data.isneedpay = s.isneedpay;
  110. gridList.push(data)
  111. }
  112. }
  113. })
  114. });
  115. this.setData({
  116. gridList
  117. });
  118. for (const key in funs) {
  119. funs[key]()
  120. };
  121. /* 获取首页banner */
  122. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  123. if (banner) this.setData({
  124. bannerList: banner.ads
  125. });
  126. wx.setStorageSync('authList', authList)
  127. wx.setStorageSync('gridList', gridList)
  128. } else {
  129. setTimeout(this.refreshData, 10);
  130. }
  131. },
  132. /* 宫格区域应用程序 */
  133. applications(e) {
  134. getApp().globalData.evidence(e.currentTarget.dataset.item)
  135. },
  136. /* 去消息详情 */
  137. toMsg(e) {
  138. const {
  139. item
  140. } = e.currentTarget.dataset;
  141. wx.navigateTo({
  142. url: '/pages/tabbar/message/details?id=' + item.messageid,
  143. })
  144. },
  145. /* 去通告 */
  146. toAnnunciate() {
  147. this.applications({
  148. currentTarget: {
  149. dataset: {
  150. item: this.data.gridList.find(v => v.name == '通告')
  151. }
  152. }
  153. })
  154. },
  155. /* banner */
  156. bannerClick(e) {
  157. const {
  158. item
  159. } = e.currentTarget.dataset,
  160. hyperlink = item.hyperlink.split(":");
  161. if (hyperlink[0] == 'path') wx.navigateTo({
  162. url: hyperlink[1]
  163. })
  164. },
  165. onShow() {
  166. this.getTabBar().init();
  167. for (const key in funs) {
  168. funs[key]()
  169. }
  170. /* 获取最新信息 */
  171. _Http.basic({
  172. "classname": "system.message.Message",
  173. "method": "queryMessage",
  174. content: {
  175. nocache: true,
  176. pageSize: 5,
  177. type: "",
  178. where: {}
  179. },
  180. }, false).then(res => {
  181. if (res.msg != '成功') return wx.showToast({
  182. title: res.msg,
  183. icon: "none"
  184. })
  185. this.setData({
  186. msgList: res.data,
  187. notice: res.data[0]
  188. })
  189. if (this.data.msgList.length > 2) {
  190. clearInterval(DataCarousel);
  191. DataCarousel = setInterval(() => {
  192. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  193. this.setData({
  194. msgCount: count + 1,
  195. notice: this.data.msgList[count]
  196. })
  197. }, 5000)
  198. }
  199. });
  200. },
  201. onHide() {
  202. clearInterval(DataCarousel);
  203. },
  204. })