index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. const _Http = getApp().globalData.http;
  2. let DataCarousel = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. bannerList: null, //banner列表
  9. user: {},
  10. annunciateList: [], //通告列表
  11. gridList: [],
  12. unreadNum: 0, //通告未读
  13. notice: "",
  14. msgCount: 1,
  15. subassembly: [], //首页部件
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. //this.getTabBar().monitor();开启socket监听
  22. this.refreshData(wx.getStorageSync('userMsg')) //更新权限等信息
  23. this.setData({ //获取胶囊位置信息
  24. capsule: wx.getMenuButtonBoundingClientRect()
  25. })
  26. },
  27. /* 更新站点信息 */
  28. refreshData(item) {
  29. this.setData({
  30. user: item
  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/threadedTree/index",
  79. icon: "icon-xiaoshouxiansuo",
  80. apps: v.apps
  81. })
  82. //获取销售线索待办数量
  83. setTimeout(this.getCount, 100);
  84. break;
  85. };
  86. });
  87. /* 首页小组件查询 */
  88. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  89. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  90. this.setData({
  91. gridList,
  92. subassembly
  93. })
  94. }
  95. /* 获取banner */
  96. this.setData({
  97. bannerList: wx.getStorageSync('banner_list')[0].ads
  98. })
  99. this.queryNoticeList(0); //获取通告列表
  100. },
  101. /* 销售线索待办 */
  102. getCount() {
  103. const index = this.data.gridList.findIndex(v => v.name == '销售线索');
  104. if (!index) return;
  105. _Http.basic({
  106. "classname": "saletool.orderclue.web.orderclue",
  107. "method": "getCount",
  108. "content": {
  109. "nocache": true,
  110. "status": "待跟进"
  111. }
  112. }).then(res => {
  113. if (res.data.count == 0) return;
  114. if (res.data.count > 99) res.data.count = '99+';
  115. this.data.gridList[index].count = res.data.count;
  116. this.setData({
  117. gridList: this.data.gridList
  118. })
  119. })
  120. },
  121. /* 查看通告详情 */
  122. toAnnunciateDetails(e) {
  123. const {
  124. item
  125. } = e.currentTarget.dataset;
  126. let authList = this.data.annunciateAuthList;
  127. wx.navigateTo({
  128. url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
  129. })
  130. },
  131. /* 获取通告列表 */
  132. queryNoticeList(i) {
  133. if (i == 5) return;
  134. _Http.basic({
  135. "classname": "saletool.notice.notice",
  136. "method": "queryNoticeList",
  137. "content": {
  138. "pageNumber": 1,
  139. "pageSize": 3
  140. }
  141. }, false).then(res => {
  142. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  143. this.setData({
  144. annunciateList: res.data,
  145. unreadNum: res.total - res.tips.readNum
  146. })
  147. })
  148. },
  149. /* 获取最新信息 */
  150. queryMessage(i = 0) {
  151. _Http.basic({
  152. "classname": "system.message.Message",
  153. "method": "queryMessage",
  154. content: {
  155. nocache: true,
  156. pageNumber: 1,
  157. pageSize: 5,
  158. pageTotal: 1,
  159. type: "",
  160. where: {}
  161. },
  162. }).then(res => {
  163. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  164. title: res.msg,
  165. icon: "none"
  166. })
  167. this.setData({
  168. msgList: res.data,
  169. notice: res.data[0]
  170. })
  171. this.startDataCarousel();
  172. })
  173. },
  174. startDataCarousel() {
  175. clearInterval(DataCarousel);
  176. DataCarousel = setInterval(() => {
  177. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  178. this.setData({
  179. msgCount: count + 1,
  180. notice: this.data.msgList[count]
  181. })
  182. }, 5000)
  183. },
  184. /* 宫格区域应用程序 */
  185. applications(e) {
  186. const {
  187. item
  188. } = e.currentTarget.dataset;
  189. wx.navigateTo({
  190. url: `${item.path}?auth=${JSON.stringify(item.apps)}`,
  191. });
  192. },
  193. /* 去消息详情 */
  194. toMsg(e) {
  195. const {
  196. item
  197. } = e.currentTarget.dataset;
  198. wx.navigateTo({
  199. url: '/pages/tabbar/message/details?id=' + item.messageid,
  200. })
  201. },
  202. /* 去通告 */
  203. toAnnunciate() {
  204. this.applications({
  205. currentTarget: {
  206. dataset: {
  207. item: this.data.gridList.find(v => v.name == '通告')
  208. }
  209. }
  210. })
  211. },
  212. /* banner */
  213. bannerClick(e) {
  214. const hyperlink = e.currentTarget.dataset.hyperlink.split(":");
  215. if (hyperlink[0] == 'path') {
  216. wx.navigateTo({
  217. url: hyperlink[1]
  218. })
  219. }
  220. },
  221. /**
  222. * 生命周期函数--监听页面显示
  223. */
  224. onShow() {
  225. this.getTabBar().init();
  226. this.startDataCarousel();
  227. this.getCount(); //更新徽标数据
  228. this.queryMessage(0); //更新最新消息
  229. },
  230. /**
  231. * 生命周期函数--监听页面隐藏
  232. */
  233. onHide() {
  234. clearInterval(DataCarousel);
  235. },
  236. })