index.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. gridList.push({
  97. name: "联系人",
  98. path: "/packageA/contacts/index",
  99. icon: "icon-xiaochengxutongxunlu",
  100. apps: {}
  101. })
  102. gridList.push({
  103. name: "销售预测",
  104. path: "/packageA/forecast/index",
  105. icon: "icon-xiaochengxu_xiaoshouyuce",
  106. apps: {}
  107. })
  108. /* 首页小组件查询 */
  109. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  110. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  111. this.setData({
  112. gridList,
  113. subassembly
  114. })
  115. } else {
  116. setTimeout(this.refreshData, 10);
  117. return;
  118. }
  119. /* 获取首页banner */
  120. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  121. if (banner) this.setData({
  122. bannerList: banner.ads
  123. })
  124. this.queryNoticeList(0); //获取通告列表
  125. },
  126. /* 销售线索待办 */
  127. getCount() {
  128. const index = this.data.gridList.findIndex(v => v.name == '销售线索');
  129. if (!index) return;
  130. _Http.basic({
  131. "classname": "saletool.orderclue.web.orderclue",
  132. "method": "getCount",
  133. "content": {
  134. "nocache": true,
  135. "status": "待跟进"
  136. }
  137. }, false).then(res => {
  138. if (res.data.count == 0) return;
  139. if (res.data.count > 99) res.data.count = '99+';
  140. this.data.gridList[index].count = res.data.count;
  141. this.setData({
  142. gridList: this.data.gridList
  143. })
  144. })
  145. },
  146. /* 查看通告详情 */
  147. toAnnunciateDetails(e) {
  148. const {
  149. item
  150. } = e.currentTarget.dataset;
  151. let authList = this.data.annunciateAuthList;
  152. wx.navigateTo({
  153. url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
  154. })
  155. },
  156. /* 获取通告列表 */
  157. queryNoticeList(i) {
  158. if (i == 5) return;
  159. let obj = this.data.gridList.find(v => v.name == '通告');
  160. if (!obj || obj.apps.length == 0) return;
  161. _Http.basic({
  162. "classname": "saletool.notice.notice",
  163. "method": "queryNoticeList",
  164. "content": {
  165. "nocache": true,
  166. "pageNumber": 1,
  167. "pageSize": 3
  168. }
  169. }, false).then(res => {
  170. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  171. this.setData({
  172. annunciateList: res.data,
  173. unreadNum: res.total - res.tips.readNum
  174. })
  175. });
  176. },
  177. /* 获取最新信息 */
  178. queryMessage(i = 0) {
  179. _Http.basic({
  180. "classname": "system.message.Message",
  181. "method": "queryMessage",
  182. content: {
  183. nocache: true,
  184. pageNumber: 1,
  185. pageSize: 5,
  186. pageTotal: 1,
  187. type: "",
  188. where: {}
  189. },
  190. }, false).then(res => {
  191. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  192. title: res.msg,
  193. icon: "none"
  194. })
  195. this.setData({
  196. msgList: res.data,
  197. notice: res.data[0]
  198. })
  199. if (this.data.msgList.length > 2) this.startDataCarousel();
  200. })
  201. },
  202. /* 开启消息轮播 */
  203. startDataCarousel() {
  204. clearInterval(DataCarousel);
  205. DataCarousel = setInterval(() => {
  206. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  207. this.setData({
  208. msgCount: count + 1,
  209. notice: this.data.msgList[count]
  210. })
  211. }, 5000)
  212. },
  213. /* 宫格区域应用程序 */
  214. applications(e) {
  215. const {
  216. item
  217. } = e.currentTarget.dataset;
  218. const url = `${item.path}?auth=${JSON.stringify(item.apps)}`
  219. if (item.name == "营销物料") {
  220. wx.switchTab({
  221. url
  222. });
  223. } else {
  224. wx.navigateTo({
  225. url
  226. });
  227. }
  228. },
  229. /* 去消息详情 */
  230. toMsg(e) {
  231. const {
  232. item
  233. } = e.currentTarget.dataset;
  234. wx.navigateTo({
  235. url: '/pages/tabbar/message/details?id=' + item.messageid,
  236. })
  237. },
  238. /* 去通告 */
  239. toAnnunciate() {
  240. this.applications({
  241. currentTarget: {
  242. dataset: {
  243. item: this.data.gridList.find(v => v.name == '通告')
  244. }
  245. }
  246. })
  247. },
  248. /* banner */
  249. bannerClick(e) {
  250. const {
  251. item
  252. } = e.currentTarget.dataset,
  253. hyperlink = item.hyperlink.split(":");
  254. if (hyperlink[0] == 'path') wx.navigateTo({
  255. url: hyperlink[1]
  256. })
  257. },
  258. onShow() {
  259. this.getTabBar().init();
  260. if (this.data.msgList.length > 2) this.startDataCarousel();
  261. this.getCount(); //更新徽标数据
  262. this.queryMessage(0); //更新最新消息
  263. this.queryNoticeList(0); //获取通告列表
  264. },
  265. onHide() {
  266. clearInterval(DataCarousel);
  267. },
  268. onShareAppMessage() {}
  269. })