index.js 9.7 KB

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