index.js 8.7 KB

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