index.js 8.0 KB

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