index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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: "/packageA/saleClue/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/target/index",
  98. icon: "icon-xiaochengxu_xiaoshoumubiao",
  99. apps: v.apps
  100. })
  101. break;
  102. case "公海线索":
  103. gridList.push({
  104. name: "公海线索",
  105. path: "/packageA/publicClue/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-kehu",
  123. apps: {}
  124. })
  125. gridList.push({
  126. name: "项目商机",
  127. path: "/packageA/project/index",
  128. icon: "icon-xiangmushangji",
  129. apps: {}
  130. })
  131. gridList.push({
  132. name: "报价单",
  133. path: "/packageA/offers/index",
  134. icon: "icon-xiangmubaojia",
  135. apps: {}
  136. })
  137. gridList.push({
  138. name: "合同",
  139. path: "/packageA/contract/index",
  140. icon: "icon-hetong",
  141. apps: {}
  142. })
  143. gridList.push({
  144. name: "市场活动",
  145. path: "/packageA/activity/index",
  146. icon: "icon-xiaochengxutongxunlu",
  147. apps: {}
  148. }),
  149. gridList.push({
  150. name: "公海线索",
  151. path: "/packageA/publicClue/index",
  152. icon: "icon-xiaochengxu_xiaoshoumubiao",
  153. apps: {}
  154. })
  155. gridList.push({
  156. name: "竞争对手",
  157. path: "/packageA/opponent/index",
  158. icon: "icon-xiaochengxutongxunlu",
  159. apps: {}
  160. })
  161. gridList.push({
  162. name: "公海客户",
  163. path: "/packageA/publicCustomer/index",
  164. icon: "icon-xiaochengxutongxunlu",
  165. apps: {}
  166. })
  167. gridList.push({
  168. name: "销售预测",
  169. path: "/packageA/salesForecasting/index",
  170. icon: "icon-xiaochengxu_xiaoshouyuce",
  171. apps: {}
  172. })
  173. gridList.push({
  174. name: "任务",
  175. path: "/packageA/work/index",
  176. icon: "icon-xiaochengxu_xiaoshouyuce",
  177. apps: {}
  178. })
  179. }
  180. /* 首页小组件查询 */
  181. try {
  182. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  183. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  184. } catch (e) {
  185. this.setData({
  186. gridList,
  187. subassembly: []
  188. })
  189. }
  190. this.setData({
  191. gridList,
  192. subassembly
  193. })
  194. } else {
  195. setTimeout(this.refreshData, 10);
  196. return;
  197. }
  198. /* 获取首页banner */
  199. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  200. if (banner) this.setData({
  201. bannerList: banner.ads
  202. })
  203. this.queryNoticeList(0); //获取通告列表
  204. },
  205. /* 销售线索待办 */
  206. getCount() {
  207. const index = this.data.gridList.findIndex(v => v.name == '销售线索');
  208. if (index == -1) return;
  209. _Http.basic({
  210. "classname": "saletool.orderclue.web.orderclue",
  211. "method": "getCount",
  212. "content": {
  213. "nocache": true,
  214. "status": "待跟进"
  215. }
  216. }, false).then(res => {
  217. if (res.data.count == 0) res.data.count = '';
  218. if (res.data.count > 99) res.data.count = '99+';
  219. try {
  220. this.data.gridList[index].count = res.data.count;
  221. } catch (e) {
  222. }
  223. this.setData({
  224. gridList: this.data.gridList
  225. })
  226. })
  227. },
  228. /* 查看通告详情 */
  229. toAnnunciateDetails(e) {
  230. const {
  231. item
  232. } = e.currentTarget.dataset;
  233. let authList = this.data.annunciateAuthList;
  234. wx.navigateTo({
  235. url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
  236. })
  237. },
  238. /* 获取通告列表 */
  239. queryNoticeList(i) {
  240. if (i == 5) return;
  241. let obj = this.data.gridList.find(v => v.name == '通告');
  242. if (!obj || obj.apps.length == 0) return;
  243. _Http.basic({
  244. id: 20221111090904,
  245. "content": {
  246. "nocache": true,
  247. "pageNumber": 1,
  248. "pageSize": 3
  249. }
  250. }, false).then(res => {
  251. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  252. this.setData({
  253. annunciateList: res.data,
  254. unreadNum: res.total - res.tips.readNum
  255. })
  256. });
  257. },
  258. /* 获取最新信息 */
  259. queryMessage(i = 0) {
  260. _Http.basic({
  261. "classname": "system.message.Message",
  262. "method": "queryMessage",
  263. content: {
  264. nocache: true,
  265. pageNumber: 1,
  266. pageSize: 5,
  267. pageTotal: 1,
  268. type: "",
  269. where: {}
  270. },
  271. }, false).then(res => {
  272. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  273. title: res.msg,
  274. icon: "none"
  275. })
  276. this.setData({
  277. msgList: res.data,
  278. notice: res.data[0]
  279. })
  280. if (this.data.msgList.length > 2) this.startDataCarousel();
  281. })
  282. },
  283. /* 开启消息轮播 */
  284. startDataCarousel() {
  285. clearInterval(DataCarousel);
  286. DataCarousel = setInterval(() => {
  287. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  288. this.setData({
  289. msgCount: count + 1,
  290. notice: this.data.msgList[count]
  291. })
  292. }, 5000)
  293. },
  294. /* 宫格区域应用程序 */
  295. applications(e) {
  296. const {
  297. item
  298. } = e.currentTarget.dataset;
  299. const url = `${item.path}?auth=${JSON.stringify(item.apps)}`
  300. if (item.name == "营销物料") {
  301. wx.switchTab({
  302. url
  303. });
  304. } else {
  305. wx.navigateTo({
  306. url
  307. });
  308. }
  309. },
  310. /* 去消息详情 */
  311. toMsg(e) {
  312. const {
  313. item
  314. } = e.currentTarget.dataset;
  315. wx.navigateTo({
  316. url: '/pages/tabbar/message/details?id=' + item.messageid,
  317. })
  318. },
  319. /* 去通告 */
  320. toAnnunciate() {
  321. this.applications({
  322. currentTarget: {
  323. dataset: {
  324. item: this.data.gridList.find(v => v.name == '通告')
  325. }
  326. }
  327. })
  328. },
  329. /* banner */
  330. bannerClick(e) {
  331. const {
  332. item
  333. } = e.currentTarget.dataset,
  334. hyperlink = item.hyperlink.split(":");
  335. if (hyperlink[0] == 'path') wx.navigateTo({
  336. url: hyperlink[1]
  337. })
  338. },
  339. onShow() {
  340. this.getTabBar().init();
  341. if (this.data.msgList.length > 2) this.startDataCarousel();
  342. this.getCount(); //更新徽标数据
  343. this.queryMessage(0); //更新最新消息
  344. this.queryNoticeList(0); //获取通告列表
  345. },
  346. onHide() {
  347. clearInterval(DataCarousel);
  348. },
  349. onShareAppMessage() {}
  350. })