index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. console.log(s.name)
  68. //更新销售线索徽标数据
  69. funs.getCount = () => {
  70. const index = this.data.gridList.findIndex(v => v.label == '销售线索');
  71. if (index == -1) return;
  72. _Http.basic({
  73. "classname": "saletool.orderclue.web.orderclue",
  74. "method": "getCount",
  75. "content": {
  76. "nocache": true,
  77. "status": "待跟进",
  78. content: Date.now()
  79. }
  80. }, false).then(res => {
  81. if (res.data.count == 0) res.data.count = '';
  82. if (res.data.count > 99) res.data.count = '99+';
  83. try {
  84. this.data.gridList[index].count = res.data.count;
  85. } catch (e) {}
  86. this.setData({
  87. gridList: this.data.gridList
  88. })
  89. })
  90. };
  91. } else if (s.name == "wnotice" && s.meta.wedgits.find(a => a.wedgit == 'homenoticelist')) {
  92. //更新通告数据
  93. funs.queryNoticeList = () => {
  94. _Http.basic({
  95. "classname": "saletool.notice.notice",
  96. "method": "queryNoticeList",
  97. "content": {
  98. "nocache": true,
  99. "pageNumber": 1,
  100. "pageSize": 3,
  101. content: Date.now()
  102. }
  103. }, false).then(res => {
  104. if (res.msg != '成功') return;
  105. this.setData({
  106. annunciateList: res.data,
  107. unreadNum: res.total - res.tips.readNum
  108. })
  109. });
  110. };
  111. }
  112. let data = paths.find(k => {
  113. return k.name == s.name
  114. });
  115. if (data) {
  116. data.isneedpay = s.isneedpay;
  117. gridList.push(data)
  118. }
  119. }
  120. })
  121. });
  122. this.setData({
  123. gridList
  124. });
  125. for (const key in funs) {
  126. funs[key]()
  127. };
  128. /* 获取首页banner */
  129. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  130. if (banner) this.setData({
  131. bannerList: banner.ads
  132. });
  133. wx.setStorageSync('authList', authList)
  134. wx.setStorageSync('gridList', gridList)
  135. } else {
  136. setTimeout(this.refreshData, 10);
  137. }
  138. },
  139. /* 宫格区域应用程序 */
  140. applications(e) {
  141. getApp().globalData.evidence(e.currentTarget.dataset.item)
  142. },
  143. /* 去消息详情 */
  144. toMsg(e) {
  145. const {
  146. item
  147. } = e.currentTarget.dataset;
  148. wx.navigateTo({
  149. url: '/pages/tabbar/message/details?id=' + item.messageid,
  150. })
  151. },
  152. /* 去通告 */
  153. toAnnunciate() {
  154. this.applications({
  155. currentTarget: {
  156. dataset: {
  157. item: this.data.gridList.find(v => v.label == '通告')
  158. }
  159. }
  160. })
  161. },
  162. /* banner */
  163. bannerClick(e) {
  164. const {
  165. item
  166. } = e.currentTarget.dataset,
  167. hyperlink = item.hyperlink.split(":");
  168. if (hyperlink[0] == 'path') wx.navigateTo({
  169. url: hyperlink[1]
  170. })
  171. },
  172. onShow() {
  173. this.getTabBar().init();
  174. for (const key in funs) {
  175. funs[key]()
  176. }
  177. /* 获取最新信息 */
  178. _Http.basic({
  179. "classname": "system.message.Message",
  180. "method": "queryMessage",
  181. content: {
  182. nocache: true,
  183. pageSize: 5,
  184. type: "",
  185. where: {}
  186. },
  187. }, false).then(res => {
  188. if (res.msg != '成功') return wx.showToast({
  189. title: res.msg,
  190. icon: "none"
  191. })
  192. this.setData({
  193. msgList: res.data,
  194. notice: res.data[0]
  195. })
  196. if (this.data.msgList.length > 2) {
  197. clearInterval(DataCarousel);
  198. DataCarousel = setInterval(() => {
  199. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  200. this.setData({
  201. msgCount: count + 1,
  202. notice: this.data.msgList[count]
  203. })
  204. }, 5000)
  205. }
  206. });
  207. },
  208. onHide() {
  209. clearInterval(DataCarousel);
  210. },
  211. })