index.js 7.8 KB

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