index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. let _Http = getApp().globalData.http,
  2. DataCarousel = null;
  3. Page({
  4. data: {
  5. appid: "wxc1b6ae925ac1d06a",
  6. bannerList: [], //banner列表
  7. gridList: [],
  8. notice: "",
  9. msgCount: 1,
  10. msgList: [], //消息列表
  11. },
  12. onLoad(options) {
  13. this.setData({ //获取胶囊位置信息
  14. capsule: wx.getMenuButtonBoundingClientRect()
  15. })
  16. this.refreshData() //更新权限等信息
  17. this.getTabBar().unReadMessageCount(); //更新信息数量
  18. },
  19. /* 更新站点信息 */
  20. refreshData() {
  21. this.setData({
  22. user: wx.getStorageSync('userMsg')
  23. })
  24. if (wx.getStorageSync('userauth').length != 0) {
  25. let authList = {},
  26. entrance = [{
  27. label: "通用",
  28. icon: "work-tongyong",
  29. appid: "wx197f219a82a89d7b",
  30. list: getapps()
  31. }, {
  32. label: "E-订单",
  33. appid: "wxc1b6ae925ac1d06a",
  34. icon: "work-E-dingdan",
  35. list: getedd()
  36. }, {
  37. label: "E-服务",
  38. appid: "wxc1b6ae925ac1d06a",
  39. icon: "work-E-fuwu",
  40. list: geteservice()
  41. }, {
  42. label: "营销工具",
  43. icon: "work-yingxiaogongju",
  44. appid: "wx197f219a82a89d7b",
  45. list: gettool()
  46. }, {
  47. label: "CRM",
  48. appid: "wx197f219a82a89d7b",
  49. icon: "work-CRM",
  50. list: getcrm()
  51. }];
  52. //通用
  53. function getapps() {
  54. const paths = [{
  55. name: "签到",
  56. path: "/packageA/clockIn/index",
  57. icon: "work-a-wodemendianxinxidizhi"
  58. }, {
  59. name: "任务",
  60. path: "/packageA/work/index",
  61. icon: "work-a-woderenwuzhongxin"
  62. }, {
  63. name: "通讯录",
  64. path: "/packageA/contacts/index",
  65. icon: "work-xiaochengxutongxunlu"
  66. }, {
  67. name: "工作汇报",
  68. path: "/packageA/report/index",
  69. icon: "work-gongzuohuibao"
  70. }];
  71. let app = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['通用']),
  72. list = [];
  73. app.forEach((v, i) => {
  74. v.apps.forEach(s => {
  75. authList[s.name] = {
  76. options: s.meta.auth.map(a => a.option),
  77. optionnames: s.meta.auth.map(a => a.optionname),
  78. }
  79. if (authList[s.name].options.some(s => s == "read")) {
  80. let i = paths.findIndex(k => k.name == s.meta.title);
  81. if (i != -1) {
  82. paths[i].index = i;
  83. list.push(paths[i])
  84. }
  85. }
  86. })
  87. });
  88. return dye(list)
  89. }
  90. //营销工具
  91. function gettool() {
  92. const paths = [{
  93. name: "通告",
  94. path: "/pages/annunciate/index",
  95. icon: "work-a-shouyejingangqutonggao"
  96. }, {
  97. name: "营销物料",
  98. path: "/pages/mediaLibrary/index",
  99. icon: "work-a-shouyejingangquyingxiaowuliao"
  100. }, {
  101. name: "推广素材",
  102. path: "/pages/promotional/index",
  103. icon: "work-a-shouyejingangqutuiguangsucai"
  104. }, {
  105. name: "商学院",
  106. path: "/pages/college/index",
  107. icon: "work-a-shangxueyuanxuexi"
  108. }, {
  109. name: "提报",
  110. path: "/pages/submission/index",
  111. icon: "work-a-tibaoguanlitibao"
  112. }];
  113. let tool = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], paths.map(v => v.name)),
  114. list = [];
  115. tool.forEach(v => {
  116. let auth = v.apps[0].meta.auth;
  117. if (!auth.some(r => r.option == 'read')) return;
  118. authList[v.apps[0].name] = {
  119. options: auth.map(a => a.option),
  120. optionnames: auth.map(a => a.optionname)
  121. };
  122. let item = paths.find(s => s.name == v.systemmodulename);
  123. item && list.push(item)
  124. });
  125. return dye(list)
  126. };
  127. //CRM
  128. function getcrm() {
  129. const paths = [{
  130. name: "市场活动",
  131. path: "/packageA/activity/index",
  132. icon: "work-shichanghuodong",
  133. }, {
  134. name: "公海线索",
  135. path: "/packageA/publicClue/index",
  136. icon: "work-xiaochengxu_xiaoshoumubiao"
  137. }, {
  138. name: "销售线索",
  139. path: "/packageA/saleClue/index",
  140. icon: "work-xiaoshouxiansuo"
  141. }, {
  142. name: "公海客户",
  143. path: "/packageA/publicCustomer/index",
  144. icon: "work-gonghaikehu"
  145. }, {
  146. name: "我的客户",
  147. path: "/packageA/setclient/index",
  148. icon: "work-kehu"
  149. }, {
  150. name: "项目商机",
  151. path: "/packageA/project/index",
  152. icon: "work-xiangmushangji"
  153. }, {
  154. name: "报价单",
  155. path: "/packageA/offers/index",
  156. icon: "work-xiangmubaojia"
  157. }, {
  158. name: "竞争对手",
  159. path: "/packageA/opponent/index",
  160. icon: "work-jingzhengduishou"
  161. }, {
  162. name: "合同",
  163. path: "/packageA/contract/index",
  164. icon: "work-hetong"
  165. }, {
  166. name: "销售目标",
  167. path: "/packageA/target/index",
  168. icon: "work-xiaochengxu_xiaoshoumubiao"
  169. }, {
  170. name: "销售预测",
  171. path: "/packageA/salesForecasting/index",
  172. icon: "work-xiaochengxu_xiaoshouyuce"
  173. }];
  174. let crm = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['CRM'], ['销售预测', '销售线索', '销售目标', '合同管理', '客户管理', '项目管理']),
  175. list = [];
  176. crm.forEach(v => {
  177. v.apps.forEach(s => {
  178. authList[s.name] = {
  179. options: s.meta.auth.map(a => a.option),
  180. optionnames: s.meta.auth.map(a => a.optionname),
  181. }
  182. if (authList[s.name].options.some(s => s == "read")) {
  183. let i = paths.findIndex(k => k.name == s.meta.title);
  184. if (i != -1) {
  185. paths[i].index = i;
  186. list.push(paths[i])
  187. }
  188. }
  189. })
  190. });
  191. return dye(list.sort((a, b) => a.index - b.index))
  192. };
  193. //E订单
  194. function getedd() {
  195. let paths = [{
  196. name: "商城",
  197. path: "/packageA/market/index",
  198. icon: "work-shangcheng"
  199. }, {
  200. name: "销售订单",
  201. path: "/packageA/orderForm/index",
  202. icon: "work-dingdan"
  203. }, {
  204. name: "收货",
  205. path: "/packageA/shipment/index",
  206. icon: "work-shouhuo"
  207. }, {
  208. name: "业绩目标",
  209. path: "/packageA/target/index",
  210. icon: "work-yejimubiao"
  211. }, {
  212. name: "账户",
  213. path: "/packageA/account/index",
  214. icon: "work-zhanghu"
  215. }, {
  216. name: "促销活动",
  217. path: "/packageA/activity/index",
  218. icon: "work-cuxiaohuodong"
  219. }, {
  220. name: "工具查询",
  221. path: "/packageA/tool/index",
  222. icon: "work-gongjuchaxun"
  223. }, {
  224. name: "购物车",
  225. path: "/packageA/shopping/index",
  226. icon: "work-gouwuche"
  227. }, {
  228. name: "开票",
  229. path: "/packageA/invoice/index",
  230. icon: "work-kaipiao"
  231. }, {
  232. name: "打款凭证",
  233. path: "/packageA/remitVoucher/index",
  234. icon: "work-dakuanpingzheng"
  235. }, {
  236. name: "工具借用",
  237. path: "/packageA/borrow/index",
  238. icon: "work-shujuchaxun"
  239. }, {
  240. name: "工具归还",
  241. path: "/packageA/toolBill/index",
  242. icon: "work-shujuchaxun"
  243. }, {
  244. name: "退返申请",
  245. path: "/packageA/returnOne/index",
  246. icon: "work-shujuchaxun"
  247. }, {
  248. name: "居间费结算",
  249. path: "/packageA/betweenFee/index",
  250. icon: "work-jujianfeijiesuan"
  251. }, ];
  252. /* {
  253. name: "数据查询",
  254. path: "#",
  255. icon: "work-shujuchaxun"
  256. } */
  257. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货与库存", "业绩查询"]),
  258. list = [];
  259. edd.forEach(v => {
  260. v.apps.forEach(s => {
  261. authList[s.name] = {
  262. options: s.meta.auth.map(a => a.option),
  263. optionnames: s.meta.auth.map(a => a.optionname),
  264. }
  265. if (authList[s.name].options.some(s => s == "read")) {
  266. let i = paths.findIndex(k => k.name == s.meta.title);
  267. if (i != -1) {
  268. paths[i].index = i;
  269. list.push(paths[i])
  270. }
  271. }
  272. })
  273. });
  274. return dye(list.sort((a, b) => a.index - b.index))
  275. };
  276. //E服务
  277. function geteservice() {
  278. let paths = [{
  279. name: "工单",
  280. path: "/Eservice/workOrder/index",
  281. icon: "work-gongdan"
  282. }, {
  283. name: "申请单",
  284. path: "/Eservice/agent/serviceBillList/index",
  285. icon: "work-shenqingdan"
  286. }, {
  287. name: "申请单管理",
  288. path: "/Eservice/workerLeader/serviceBillList/index",
  289. icon: "work-shenqingdanguanli"
  290. }, {
  291. name: "业务员服务申请单",
  292. path: "/Eservice/saler/serviceBillList/index",
  293. icon: "work-yewuyuanfuwushenqingdan"
  294. }];
  295. let eservice = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-服务"], ["工单管理"]),
  296. list = [];
  297. eservice.forEach(v => {
  298. v.apps.forEach(s => {
  299. authList[s.name] = {
  300. options: s.meta.auth.map(a => a.option),
  301. optionnames: s.meta.auth.map(a => a.optionname),
  302. }
  303. if (authList[s.name].options.some(s => s == "read")) {
  304. let i = paths.findIndex(k => k.name == s.meta.title);
  305. if (i != -1) {
  306. paths[i].index = i;
  307. list.push(paths[i])
  308. }
  309. }
  310. })
  311. });
  312. return dye(list.sort((a, b) => a.index - b.index))
  313. }
  314. //染色
  315. function dye(list) {
  316. let colorList = [{
  317. color: "#3874F6",
  318. bColor: "#F0F3FF",
  319. }, {
  320. color: "#5AB73F",
  321. bColor: "#F4FAEF",
  322. }, {
  323. color: "#F29C37",
  324. bColor: "#FCF6EF",
  325. }, {
  326. color: "#EB4B5C",
  327. bColor: "#FDF1ED",
  328. }, {
  329. color: "#3874F6",
  330. bColor: "#F0F3FF",
  331. }, {
  332. color: "#F29C37",
  333. bColor: "#FCF6EF",
  334. }, {
  335. color: "#EB4B5C",
  336. bColor: "#FDF1ED",
  337. }, {
  338. color: "#3874F6",
  339. bColor: "#F0F3FF",
  340. }, {
  341. color: "#5AB73F",
  342. bColor: "#F4FAEF",
  343. }, {
  344. color: "#F29C37",
  345. bColor: "#FCF6EF",
  346. }, {
  347. color: "#5AB73F",
  348. bColor: "#F4FAEF",
  349. }, {
  350. color: "#3874F6",
  351. bColor: "#F0F3FF",
  352. }, {
  353. color: "#F29C37",
  354. bColor: "#FCF6EF",
  355. }, {
  356. color: "#EB4B5C",
  357. bColor: "#FDF1ED",
  358. }, {
  359. color: "#5AB73F",
  360. bColor: "#F4FAEF",
  361. }];
  362. return list.map((v, i) => {
  363. return {
  364. ...v,
  365. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  366. }
  367. })
  368. };
  369. wx.setStorageSync('auth', authList)
  370. this.setData({
  371. entrance,
  372. auth: JSON.stringify(authList),
  373. userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
  374. site: JSON.stringify(wx.getStorageSync('siteP'))
  375. })
  376. /* 获取首页banner */
  377. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  378. if (banner) this.setData({
  379. bannerList: banner.ads
  380. })
  381. } else {
  382. setTimeout(this.refreshData, 10);
  383. return;
  384. }
  385. },
  386. /* 获取最新信息 */
  387. queryMessage(i = 0) {
  388. _Http.basic({
  389. "classname": "system.message.Message",
  390. "method": "queryMessage",
  391. content: {
  392. nocache: true,
  393. pageNumber: 1,
  394. pageSize: 5,
  395. pageTotal: 1,
  396. type: "",
  397. where: {}
  398. },
  399. }, false).then(res => {
  400. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  401. title: res.msg,
  402. icon: "none"
  403. })
  404. this.setData({
  405. msgList: res.data,
  406. notice: res.data[0]
  407. })
  408. if (this.data.msgList.length > 2) this.startDataCarousel();
  409. })
  410. },
  411. /* 开启消息轮播 */
  412. startDataCarousel() {
  413. clearInterval(DataCarousel);
  414. DataCarousel = setInterval(() => {
  415. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  416. this.setData({
  417. msgCount: count + 1,
  418. notice: this.data.msgList[count]
  419. })
  420. }, 5000)
  421. },
  422. /* 去消息详情 */
  423. toMsg(e) {
  424. const {
  425. item
  426. } = e.currentTarget.dataset;
  427. wx.navigateTo({
  428. url: '/pages/tabbar/message/details?id=' + item.messageid,
  429. })
  430. },
  431. /* banner */
  432. bannerClick(e) {
  433. const {
  434. item
  435. } = e.currentTarget.dataset,
  436. hyperlink = item.hyperlink.split(":");
  437. if (hyperlink[0] == 'path') wx.navigateTo({
  438. url: hyperlink[1]
  439. })
  440. },
  441. onShow() {
  442. this.getTabBar().init();
  443. if (this.data.msgList.length > 2) this.startDataCarousel();
  444. this.queryMessage(0); //更新最新消息
  445. },
  446. onHide() {
  447. clearInterval(DataCarousel);
  448. },
  449. onReady() {
  450. // this.setListHeight();
  451. },
  452. /* 设置页面高度 */
  453. setListHeight() {
  454. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  455. },
  456. onShareAppMessage() {}
  457. })