index.js 17 KB

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