index.js 9.3 KB

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