index.js 7.9 KB

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