index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. console.log(auth)
  39. auth.forEach(v => {
  40. switch (v.systemmodulename) {
  41. case "通告":
  42. gridList.push({
  43. name: "通告",
  44. path: "/pages/annunciate/index",
  45. icon: "icon-a-shouyejingangqutonggao",
  46. apps: v.apps
  47. });
  48. if (v.apps[0].meta.wedgits.some(value => value.wedgit == 'homenoticelist')) subassembly.push('homenoticelist');
  49. this.setData({
  50. annunciateAuthList: v.apps[0].meta.auth.map(v => v.optionname)
  51. });
  52. break;
  53. case "推广素材":
  54. gridList.push({
  55. name: "推广素材",
  56. path: "/pages/promotional/index",
  57. icon: "icon-a-shouyejingangqutuiguangsucai",
  58. apps: v.apps
  59. })
  60. break;
  61. case "商学院":
  62. gridList.push({
  63. name: "商学院",
  64. path: "/pages/college/index",
  65. icon: "icon-a-shangxueyuanxuexi",
  66. apps: v.apps
  67. })
  68. break;
  69. case "提报":
  70. gridList.push({
  71. name: "提报",
  72. path: "/pages/submission/index",
  73. icon: "icon-a-tibaoguanlitibao",
  74. apps: v.apps
  75. })
  76. break;
  77. case "营销物料":
  78. gridList.push({
  79. name: "营销物料",
  80. path: "/pages/tabbar/smartStore/index",
  81. icon: "icon-a-shouyejingangquyingxiaowuliao",
  82. apps: v.apps
  83. })
  84. break;
  85. case "销售目标":
  86. gridList.push({
  87. name: "销售目标",
  88. path: "/packageA/target/index",
  89. icon: "icon-xiaochengxu_xiaoshoumubiao",
  90. apps: v.apps
  91. })
  92. break;
  93. case "公海线索":
  94. gridList.push({
  95. name: "公海线索",
  96. path: "/packageA/publicClue/index",
  97. icon: "icon-xiaochengxu_xiaoshoumubiao",
  98. apps: v.apps
  99. })
  100. break;
  101. /* 二期应用分界线 */
  102. case "客户管理":
  103. v.apps.forEach(value => {
  104. switch (value.name) {
  105. //客户
  106. case "wCustomer":
  107. if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
  108. name: "客户",
  109. path: "/packageA/setclient/index",
  110. icon: "icon-kehu",
  111. apps: {}
  112. })
  113. getApp().globalData.auth.wCustomer = {
  114. options: value.meta.auth.map(a => a.option),
  115. optionnames: value.meta.auth.map(a => a.optionname),
  116. }
  117. break;
  118. //公海客户
  119. case "wPublicCustomer":
  120. if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
  121. name: "公海客户",
  122. path: "/packageA/publicCustomer/index",
  123. icon: "icon-xiaochengxutongxunlu",
  124. apps: {}
  125. })
  126. getApp().globalData.auth.wPublicCustomer = {
  127. options: value.meta.auth.map(a => a.option),
  128. optionnames: value.meta.auth.map(a => a.optionname),
  129. }
  130. break;
  131. }
  132. })
  133. break;
  134. case "项目管理":
  135. v.apps.forEach(value => {
  136. switch (value.name) {
  137. //项目商机
  138. case "wproject":
  139. if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
  140. name: "项目商机",
  141. path: "/packageA/project/index",
  142. icon: "icon-xiangmushangji",
  143. apps: {}
  144. })
  145. getApp().globalData.auth.wproject = {
  146. options: value.meta.auth.map(a => a.option),
  147. optionnames: value.meta.auth.map(a => a.optionname),
  148. }
  149. break;
  150. //竞争对手
  151. case "wcompetitor":
  152. if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
  153. name: "竞争对手",
  154. path: "/packageA/opponent/index",
  155. icon: "icon-xiaochengxutongxunlu",
  156. apps: {}
  157. })
  158. getApp().globalData.auth.wcompetitor = {
  159. options: value.meta.auth.map(a => a.option),
  160. optionnames: value.meta.auth.map(a => a.optionname),
  161. }
  162. break;
  163. //报价单
  164. case "woffer":
  165. if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
  166. name: "报价单",
  167. path: "/packageA/offers/index",
  168. icon: "icon-xiangmubaojia",
  169. apps: {}
  170. })
  171. getApp().globalData.auth.woffer = {
  172. options: value.meta.auth.map(a => a.option),
  173. optionnames: value.meta.auth.map(a => a.optionname),
  174. }
  175. break;
  176. //合同
  177. case "wcontract":
  178. if (value.meta.auth.some(r => r.option == 'read')) gridList.push({
  179. name: "合同",
  180. path: "/packageA/contract/index",
  181. icon: "icon-hetong",
  182. apps: {}
  183. })
  184. getApp().globalData.auth.wcontract = {
  185. options: value.meta.auth.map(a => a.option),
  186. optionnames: value.meta.auth.map(a => a.optionname),
  187. }
  188. break;
  189. };
  190. });
  191. break;
  192. case "销售线索":
  193. v.apps.forEach(value => {
  194. switch (value.name) {
  195. //销售线索
  196. case "worderclue":
  197. if (value.meta.auth.some(r => r.option == 'read')) {
  198. gridList.push({
  199. name: "销售线索",
  200. path: "/packageA/saleClue/index",
  201. icon: "icon-xiaoshouxiansuo",
  202. apps: {}
  203. })
  204. setTimeout(this.getCount, 100);
  205. }
  206. getApp().globalData.auth.worderclue = {
  207. options: value.meta.auth.map(a => a.option),
  208. optionnames: value.meta.auth.map(a => a.optionname),
  209. }
  210. break;
  211. //公海线索
  212. case "worderclue_public":
  213. if (value.meta.auth.some(r => r.option == 'read')) {
  214. gridList.push({
  215. name: "公海线索",
  216. path: "/packageA/publicClue/index",
  217. icon: "icon-xiaochengxu_xiaoshoumubiao",
  218. apps: {}
  219. })
  220. }
  221. getApp().globalData.auth.worderclue_public = {
  222. options: value.meta.auth.map(a => a.option),
  223. optionnames: value.meta.auth.map(a => a.optionname),
  224. }
  225. break;
  226. //市场活动
  227. case "wmarketing_activity":
  228. if (value.meta.auth.some(r => r.option == 'read')) {
  229. gridList.push({
  230. name: "市场活动",
  231. path: "/packageA/activity/index",
  232. icon: "icon-xiaochengxutongxunlu",
  233. apps: {}
  234. })
  235. }
  236. getApp().globalData.auth.wmarketing_activity = {
  237. options: value.meta.auth.map(a => a.option),
  238. optionnames: value.meta.auth.map(a => a.optionname),
  239. }
  240. break;
  241. };
  242. });
  243. break;
  244. case "销售预测":
  245. v.apps.forEach(value => {
  246. switch (value.name) {
  247. //销售线索
  248. case "forecast":
  249. if (value.meta.auth.some(r => r.option == 'read')) {
  250. gridList.push({
  251. name: "销售预测",
  252. path: "/packageA/salesForecasting/index",
  253. icon: "icon-xiaochengxu_xiaoshouyuce",
  254. apps: {}
  255. })
  256. }
  257. getApp().globalData.auth.forecast = {
  258. options: value.meta.auth.map(a => a.option),
  259. optionnames: value.meta.auth.map(a => a.optionname),
  260. }
  261. break;
  262. };
  263. });
  264. break;
  265. default:
  266. console.log(v);
  267. break;
  268. };
  269. });
  270. if (!['美大'].includes(this.data.site)) {
  271. gridList.push({
  272. name: "联系人",
  273. path: "/packageA/contacts/index",
  274. icon: "icon-xiaochengxutongxunlu",
  275. apps: {}
  276. })
  277. /* gridList.push({
  278. name: "任务",
  279. path: "/packageA/work/index",
  280. icon: "icon-xiaochengxu_xiaoshouyuce",
  281. apps: {}
  282. }) */
  283. }
  284. /* 首页小组件查询 */
  285. try {
  286. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  287. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  288. } catch (e) {
  289. this.setData({
  290. gridList,
  291. subassembly: []
  292. })
  293. }
  294. this.setData({
  295. gridList,
  296. subassembly
  297. })
  298. } else {
  299. setTimeout(this.refreshData, 10);
  300. return;
  301. }
  302. /* 获取首页banner */
  303. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  304. if (banner) this.setData({
  305. bannerList: banner.ads
  306. })
  307. this.queryNoticeList(0); //获取通告列表
  308. },
  309. /* 销售线索待办 */
  310. getCount() {
  311. const index = this.data.gridList.findIndex(v => v.name == '销售线索');
  312. if (index == -1) return;
  313. _Http.basic({
  314. "classname": "saletool.orderclue.web.orderclue",
  315. "method": "getCount",
  316. "content": {
  317. "nocache": true,
  318. "status": "待跟进"
  319. }
  320. }, false).then(res => {
  321. if (res.data.count == 0) res.data.count = '';
  322. if (res.data.count > 99) res.data.count = '99+';
  323. try {
  324. this.data.gridList[index].count = res.data.count;
  325. } catch (e) {
  326. }
  327. this.setData({
  328. gridList: this.data.gridList
  329. })
  330. })
  331. },
  332. /* 查看通告详情 */
  333. toAnnunciateDetails(e) {
  334. const {
  335. item
  336. } = e.currentTarget.dataset;
  337. let authList = this.data.annunciateAuthList;
  338. wx.navigateTo({
  339. url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
  340. })
  341. },
  342. /* 获取通告列表 */
  343. queryNoticeList(i) {
  344. if (i == 5) return;
  345. let obj = this.data.gridList.find(v => v.name == '通告');
  346. if (!obj || obj.apps.length == 0) return;
  347. _Http.basic({
  348. id: 20221111090904,
  349. "content": {
  350. "nocache": true,
  351. "pageNumber": 1,
  352. "pageSize": 3
  353. }
  354. }, false).then(res => {
  355. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  356. this.setData({
  357. annunciateList: res.data,
  358. unreadNum: res.total - res.tips.readNum
  359. })
  360. });
  361. },
  362. /* 获取最新信息 */
  363. queryMessage(i = 0) {
  364. _Http.basic({
  365. "classname": "system.message.Message",
  366. "method": "queryMessage",
  367. content: {
  368. nocache: true,
  369. pageNumber: 1,
  370. pageSize: 5,
  371. pageTotal: 1,
  372. type: "",
  373. where: {}
  374. },
  375. }, false).then(res => {
  376. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  377. title: res.msg,
  378. icon: "none"
  379. })
  380. this.setData({
  381. msgList: res.data,
  382. notice: res.data[0]
  383. })
  384. if (this.data.msgList.length > 2) this.startDataCarousel();
  385. })
  386. },
  387. /* 开启消息轮播 */
  388. startDataCarousel() {
  389. clearInterval(DataCarousel);
  390. DataCarousel = setInterval(() => {
  391. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  392. this.setData({
  393. msgCount: count + 1,
  394. notice: this.data.msgList[count]
  395. })
  396. }, 5000)
  397. },
  398. /* 宫格区域应用程序 */
  399. applications(e) {
  400. const {
  401. item
  402. } = e.currentTarget.dataset;
  403. const url = `${item.path}?auth=${JSON.stringify(item.apps)}`
  404. if (item.name == "营销物料") {
  405. wx.switchTab({
  406. url
  407. });
  408. } else {
  409. wx.navigateTo({
  410. url
  411. });
  412. }
  413. },
  414. /* 去消息详情 */
  415. toMsg(e) {
  416. const {
  417. item
  418. } = e.currentTarget.dataset;
  419. wx.navigateTo({
  420. url: '/pages/tabbar/message/details?id=' + item.messageid,
  421. })
  422. },
  423. /* 去通告 */
  424. toAnnunciate() {
  425. this.applications({
  426. currentTarget: {
  427. dataset: {
  428. item: this.data.gridList.find(v => v.name == '通告')
  429. }
  430. }
  431. })
  432. },
  433. /* banner */
  434. bannerClick(e) {
  435. const {
  436. item
  437. } = e.currentTarget.dataset,
  438. hyperlink = item.hyperlink.split(":");
  439. if (hyperlink[0] == 'path') wx.navigateTo({
  440. url: hyperlink[1]
  441. })
  442. },
  443. onShow() {
  444. this.getTabBar().init();
  445. if (this.data.msgList.length > 2) this.startDataCarousel();
  446. this.getCount(); //更新徽标数据
  447. this.queryMessage(0); //更新最新消息
  448. this.queryNoticeList(0); //获取通告列表
  449. },
  450. onHide() {
  451. clearInterval(DataCarousel);
  452. },
  453. onShareAppMessage() {}
  454. })