index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. const _Http = getApp().globalData.http;
  2. let DataCarousel = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. site: getApp().globalData.site,
  9. bannerList: [], //banner列表
  10. user: {},
  11. annunciateList: [], //通告列表
  12. gridList: [],
  13. unreadNum: 0, //通告未读
  14. notice: "",
  15. msgCount: 1,
  16. subassembly: [], //首页部件
  17. msgList: [], //消息列表
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. this.refreshData() //更新权限等信息
  24. this.setData({ //获取胶囊位置信息
  25. capsule: wx.getMenuButtonBoundingClientRect()
  26. })
  27. },
  28. /* 更新站点信息 */
  29. refreshData() {
  30. this.setData({
  31. user: wx.getStorageSync('userMsg')
  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/tabbar/smartStore/index",
  80. icon: "icon-a-shouyejingangquyingxiaowuliao",
  81. apps: v.apps
  82. })
  83. break;
  84. case "销售线索":
  85. gridList.push({
  86. name: "销售线索",
  87. path: "/pages/threadedTree/index",
  88. icon: "icon-xiaoshouxiansuo",
  89. apps: v.apps
  90. })
  91. //获取销售线索待办数量
  92. setTimeout(this.getCount, 100);
  93. break;
  94. case "销售预测":
  95. gridList.push({
  96. name: "销售预测",
  97. path: "/packageA/forecast/index",
  98. icon: "icon-xiaochengxu_xiaoshouyuce",
  99. apps: v.apps
  100. })
  101. break;
  102. case "销售目标":
  103. gridList.push({
  104. name: "销售目标",
  105. path: "/packageA/target/index",
  106. icon: "icon-xiaochengxu_xiaoshoumubiao",
  107. apps: v.apps
  108. })
  109. break;
  110. };
  111. });
  112. if (!['美大'].includes(this.data.site)) {
  113. gridList.push({
  114. name: "联系人",
  115. path: "/packageA/contacts/index",
  116. icon: "icon-xiaochengxutongxunlu",
  117. apps: {}
  118. })
  119. gridList.push({
  120. name: "客户管理",
  121. path: "/packageA/setclient/index",
  122. icon: "icon-xiaochengxutongxunlu",
  123. apps: {}
  124. })
  125. gridList.push({
  126. name: "项目管理",
  127. path: "/packageA/project/index",
  128. icon: "icon-xiaochengxutongxunlu",
  129. apps: {}
  130. })
  131. }
  132. /* 首页小组件查询 */
  133. try {
  134. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  135. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  136. } catch (e) {
  137. this.setData({
  138. gridList,
  139. subassembly: []
  140. })
  141. }
  142. this.setData({
  143. gridList,
  144. subassembly
  145. })
  146. } else {
  147. setTimeout(this.refreshData, 10);
  148. return;
  149. }
  150. /* 获取首页banner */
  151. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  152. if (banner) this.setData({
  153. bannerList: banner.ads
  154. })
  155. this.queryNoticeList(0); //获取通告列表
  156. },
  157. /* 销售线索待办 */
  158. getCount() {
  159. const index = this.data.gridList.findIndex(v => v.name == '销售线索');
  160. if (index == -1) return;
  161. _Http.basic({
  162. "classname": "saletool.orderclue.web.orderclue",
  163. "method": "getCount",
  164. "content": {
  165. "nocache": true,
  166. "status": "待跟进"
  167. }
  168. }, false).then(res => {
  169. if (res.data.count == 0) res.data.count = '';
  170. if (res.data.count > 99) res.data.count = '99+';
  171. try {
  172. this.data.gridList[index].count = res.data.count;
  173. } catch (e) {
  174. }
  175. this.setData({
  176. gridList: this.data.gridList
  177. })
  178. })
  179. },
  180. /* 查看通告详情 */
  181. toAnnunciateDetails(e) {
  182. const {
  183. item
  184. } = e.currentTarget.dataset;
  185. let authList = this.data.annunciateAuthList;
  186. wx.navigateTo({
  187. url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
  188. })
  189. },
  190. /* 获取通告列表 */
  191. queryNoticeList(i) {
  192. if (i == 5) return;
  193. let obj = this.data.gridList.find(v => v.name == '通告');
  194. if (!obj || obj.apps.length == 0) return;
  195. _Http.basic({
  196. "classname": "saletool.notice.notice",
  197. "method": "queryNoticeList",
  198. "content": {
  199. "nocache": true,
  200. "pageNumber": 1,
  201. "pageSize": 3
  202. }
  203. }, false).then(res => {
  204. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  205. this.setData({
  206. annunciateList: res.data,
  207. unreadNum: res.total - res.tips.readNum
  208. })
  209. });
  210. },
  211. /* 获取最新信息 */
  212. queryMessage(i = 0) {
  213. _Http.basic({
  214. "classname": "system.message.Message",
  215. "method": "queryMessage",
  216. content: {
  217. nocache: true,
  218. pageNumber: 1,
  219. pageSize: 5,
  220. pageTotal: 1,
  221. type: "",
  222. where: {}
  223. },
  224. }, false).then(res => {
  225. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  226. title: res.msg,
  227. icon: "none"
  228. })
  229. this.setData({
  230. msgList: res.data,
  231. notice: res.data[0]
  232. })
  233. if (this.data.msgList.length > 2) this.startDataCarousel();
  234. })
  235. },
  236. /* 开启消息轮播 */
  237. startDataCarousel() {
  238. clearInterval(DataCarousel);
  239. DataCarousel = setInterval(() => {
  240. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  241. this.setData({
  242. msgCount: count + 1,
  243. notice: this.data.msgList[count]
  244. })
  245. }, 5000)
  246. },
  247. /* 宫格区域应用程序 */
  248. applications(e) {
  249. const {
  250. item
  251. } = e.currentTarget.dataset;
  252. const url = `${item.path}?auth=${JSON.stringify(item.apps)}`
  253. if (item.name == "营销物料") {
  254. wx.switchTab({
  255. url
  256. });
  257. } else {
  258. wx.navigateTo({
  259. url
  260. });
  261. }
  262. },
  263. /* 去消息详情 */
  264. toMsg(e) {
  265. const {
  266. item
  267. } = e.currentTarget.dataset;
  268. wx.navigateTo({
  269. url: '/pages/tabbar/message/details?id=' + item.messageid,
  270. })
  271. },
  272. /* 去通告 */
  273. toAnnunciate() {
  274. this.applications({
  275. currentTarget: {
  276. dataset: {
  277. item: this.data.gridList.find(v => v.name == '通告')
  278. }
  279. }
  280. })
  281. },
  282. /* banner */
  283. bannerClick(e) {
  284. const {
  285. item
  286. } = e.currentTarget.dataset,
  287. hyperlink = item.hyperlink.split(":");
  288. if (hyperlink[0] == 'path') wx.navigateTo({
  289. url: hyperlink[1]
  290. })
  291. },
  292. onShow() {
  293. this.getTabBar().init();
  294. if (this.data.msgList.length > 2) this.startDataCarousel();
  295. this.getCount(); //更新徽标数据
  296. this.queryMessage(0); //更新最新消息
  297. this.queryNoticeList(0); //获取通告列表
  298. },
  299. onHide() {
  300. clearInterval(DataCarousel);
  301. },
  302. onShareAppMessage() {}
  303. })