index.js 8.1 KB

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