index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. let _Http = getApp().globalData.http,
  2. DataCarousel = null;
  3. Page({
  4. data: {
  5. appid: wx.getStorageSync('appid'),
  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. objectname: "sat_notice"
  97. }, {
  98. name: "营销物料",
  99. path: "/pages/mediaLibrary/index",
  100. icon: "work-a-shouyejingangquyingxiaowuliao",
  101. objectname: "sys_attachment"
  102. }, {
  103. name: "推广素材",
  104. path: "/pages/promotional/index",
  105. icon: "work-a-shouyejingangqutuiguangsucai",
  106. objectname: "sat_sharematerial"
  107. }, {
  108. name: "商学院",
  109. path: "/pages/college/index",
  110. icon: "work-a-shangxueyuanxuexi",
  111. objectname: "sat_courseware"
  112. }, {
  113. name: "提报",
  114. path: "/pages/submission/index",
  115. icon: "work-a-tibaoguanlitibao",
  116. objectname: "sat_submiteditmodel"
  117. }];
  118. let tool = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], paths.map(v => v.name)),
  119. list = [];
  120. tool.forEach(v => {
  121. let auth = v.apps[0].meta.auth;
  122. if (!auth.some(r => r.option == 'read')) return;
  123. authList[v.apps[0].name] = {
  124. options: auth.map(a => a.option),
  125. optionnames: auth.map(a => a.optionname)
  126. };
  127. let item = paths.find(s => s.name == v.systemmodulename);
  128. item && list.push(item)
  129. });
  130. return dye(list)
  131. };
  132. //CRM
  133. function getcrm() {
  134. const paths = [{
  135. name: "市场活动",
  136. path: "/packageA/activity/index",
  137. icon: "work-shichanghuodong",
  138. objectname: "sat_campaign"
  139. }, {
  140. name: "公海线索",
  141. path: "/packageA/publicClue/index",
  142. icon: "work-xiaochengxu_xiaoshoumubiao",
  143. objectname: "sat_orderclue"
  144. }, {
  145. name: "销售线索",
  146. path: "/packageA/saleClue/index",
  147. icon: "work-xiaoshouxiansuo",
  148. objectname: "sat_orderclue"
  149. }, {
  150. name: "公海客户",
  151. path: "/packageA/publicCustomer/index",
  152. icon: "work-gonghaikehu",
  153. objectname: "sa_customers"
  154. }, {
  155. name: "我的客户",
  156. path: "/packageA/setclient/index",
  157. icon: "work-kehu",
  158. objectname: "sa_customers"
  159. }, {
  160. name: "项目商机",
  161. path: "/packageA/project/index",
  162. icon: "work-xiangmushangji",
  163. objectname: "sa_project"
  164. }, {
  165. name: "报价单",
  166. path: "/packageA/offers/index",
  167. icon: "work-xiangmubaojia",
  168. objectname: "sa_quotedprice"
  169. }, {
  170. name: "竞争对手",
  171. path: "/packageA/opponent/index",
  172. icon: "work-jingzhengduishou",
  173. objectname: "sa_competitor"
  174. }, {
  175. name: "合同",
  176. path: "/packageA/contract/index",
  177. icon: "work-hetong",
  178. objectname: "sa_contract"
  179. }, {
  180. name: "销售目标",
  181. path: "/packageA/target/index",
  182. icon: "work-xiaochengxu_xiaoshoumubiao",
  183. objectname: "sa_salestarget"
  184. }, {
  185. name: "销售预测",
  186. path: "/packageA/salesForecasting/index",
  187. icon: "work-xiaochengxu_xiaoshouyuce",
  188. objectname: "sa_salesforecastbill"
  189. }];
  190. let crm = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['CRM'], ['销售预测', '销售线索', '销售目标', '合同管理', '客户管理', '项目管理']),
  191. list = [];
  192. crm.forEach(v => {
  193. v.apps.forEach(s => {
  194. authList[s.name] = {
  195. options: s.meta.auth.map(a => a.option),
  196. optionnames: s.meta.auth.map(a => a.optionname),
  197. }
  198. if (authList[s.name].options.some(s => s == "read")) {
  199. let i = paths.findIndex(k => k.name == s.meta.title);
  200. if (i != -1) {
  201. paths[i].index = i;
  202. list.push(paths[i])
  203. }
  204. }
  205. })
  206. });
  207. return dye(list.sort((a, b) => a.index - b.index))
  208. };
  209. //E订单
  210. function getedd() {
  211. let paths = [{
  212. name: "商城",
  213. path: "/packageA/market/index",
  214. icon: "work-shangcheng",
  215. objectname: "sa_itemgroup"
  216. }, {
  217. name: "销售订单",
  218. path: "/packageA/orderForm/index",
  219. icon: "work-dingdan",
  220. objectname: "sa_order"
  221. }, {
  222. name: "收货",
  223. path: "/packageA/shipment/index",
  224. icon: "work-shouhuo",
  225. objectname: "sa_logistics"
  226. }, {
  227. name: "业绩目标",
  228. path: "/packageA/target/index",
  229. icon: "work-yejimubiao"
  230. }, {
  231. name: "账户",
  232. path: "/packageA/account/index",
  233. icon: "work-zhanghu",
  234. objectname: "sa_accountbalance"
  235. }, {
  236. name: "促销活动",
  237. path: "/packageA/activity/index",
  238. icon: "work-cuxiaohuodong",
  239. objectname: "sa_promotion"
  240. }, {
  241. name: "工具查询",
  242. path: "/packageA/tool/index",
  243. icon: "work-gongjuchaxun"
  244. }, {
  245. name: "购物车",
  246. path: "/packageA/shopping/index",
  247. icon: "work-gouwuche"
  248. }, {
  249. name: "开票",
  250. path: "/packageA/invoice/index",
  251. icon: "work-kaipiao",
  252. objectname: "sa_invoiceapplyid"
  253. }, {
  254. name: "打款凭证",
  255. path: "/packageA/remitVoucher/index",
  256. icon: "work-dakuanpingzheng"
  257. }, {
  258. name: "工具借用",
  259. path: "/packageA/borrow/index",
  260. icon: "work-shujuchaxun",
  261. objectname: "sa_order"
  262. }, {
  263. name: "工具归还",
  264. path: "/packageA/toolBill/index",
  265. icon: "work-shujuchaxun",
  266. objectname: "sa_order"
  267. }, {
  268. name: "退返申请",
  269. path: "/packageA/returnOne/index",
  270. icon: "work-shujuchaxun",
  271. objectname: "sa_aftersalesmag"
  272. }, {
  273. name: "居间费结算",
  274. path: "/packageA/betweenFee/index",
  275. icon: "work-jujianfeijiesuan"
  276. }, ];
  277. /* {
  278. name: "数据查询",
  279. path: "#",
  280. icon: "work-shujuchaxun"
  281. } */
  282. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货与库存", "业绩查询"]),
  283. list = [];
  284. edd.forEach(v => {
  285. v.apps.forEach(s => {
  286. authList[s.name] = {
  287. options: s.meta.auth.map(a => a.option),
  288. optionnames: s.meta.auth.map(a => a.optionname),
  289. }
  290. if (authList[s.name].options.some(s => s == "read")) {
  291. let i = paths.findIndex(k => k.name == s.meta.title);
  292. if (i != -1) {
  293. paths[i].index = i;
  294. list.push(paths[i])
  295. }
  296. }
  297. })
  298. });
  299. return dye(list.sort((a, b) => a.index - b.index))
  300. };
  301. //E服务
  302. function geteservice() {
  303. let paths = [{
  304. name: "工单",
  305. path: "/Eservice/workOrder/index",
  306. icon: "work-gongdan",
  307. objectname: "sa_workorder"
  308. }, {
  309. name: "申请单",
  310. path: "/Eservice/agent/serviceBillList/index",
  311. icon: "work-shenqingdan",
  312. // objectname: "sa_serviceorder"
  313. }, {
  314. name: "申请单管理",
  315. path: "/Eservice/workerLeader/serviceBillList/index",
  316. icon: "work-shenqingdanguanli",
  317. // objectname: "sa_serviceorder"
  318. }, {
  319. name: "业务员服务申请单",
  320. path: "/Eservice/saler/serviceBillList/index",
  321. icon: "work-yewuyuanfuwushenqingdan",
  322. // objectname: "sa_serviceorder"
  323. }];
  324. let eservice = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-服务"], ["工单管理"]),
  325. list = [];
  326. eservice.forEach(v => {
  327. v.apps.forEach(s => {
  328. authList[s.name] = {
  329. options: s.meta.auth.map(a => a.option),
  330. optionnames: s.meta.auth.map(a => a.optionname),
  331. }
  332. if (authList[s.name].options.some(s => s == "read")) {
  333. let i = paths.findIndex(k => k.name == s.meta.title);
  334. if (i != -1) {
  335. paths[i].index = i;
  336. list.push(paths[i])
  337. }
  338. }
  339. })
  340. });
  341. return dye(list.sort((a, b) => a.index - b.index))
  342. }
  343. //染色
  344. function dye(list) {
  345. let colorList = [{
  346. color: "#3874F6",
  347. bColor: "#F0F3FF",
  348. }, {
  349. color: "#5AB73F",
  350. bColor: "#F4FAEF",
  351. }, {
  352. color: "#F29C37",
  353. bColor: "#FCF6EF",
  354. }, {
  355. color: "#EB4B5C",
  356. bColor: "#FDF1ED",
  357. }, {
  358. color: "#3874F6",
  359. bColor: "#F0F3FF",
  360. }, {
  361. color: "#F29C37",
  362. bColor: "#FCF6EF",
  363. }, {
  364. color: "#EB4B5C",
  365. bColor: "#FDF1ED",
  366. }, {
  367. color: "#3874F6",
  368. bColor: "#F0F3FF",
  369. }, {
  370. color: "#5AB73F",
  371. bColor: "#F4FAEF",
  372. }, {
  373. color: "#F29C37",
  374. bColor: "#FCF6EF",
  375. }, {
  376. color: "#5AB73F",
  377. bColor: "#F4FAEF",
  378. }, {
  379. color: "#3874F6",
  380. bColor: "#F0F3FF",
  381. }, {
  382. color: "#F29C37",
  383. bColor: "#FCF6EF",
  384. }, {
  385. color: "#EB4B5C",
  386. bColor: "#FDF1ED",
  387. }, {
  388. color: "#5AB73F",
  389. bColor: "#F4FAEF",
  390. }];
  391. return list.map((v, i) => {
  392. return {
  393. ...v,
  394. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  395. }
  396. })
  397. };
  398. wx.setStorageSync('auth', authList)
  399. this.setData({
  400. entrance,
  401. auth: JSON.stringify(authList),
  402. userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
  403. site: JSON.stringify(wx.getStorageSync('siteP'))
  404. })
  405. /* 获取首页banner */
  406. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  407. if (banner) this.setData({
  408. bannerList: banner.ads
  409. })
  410. //用于消息跳转对照权限以及路径
  411. wx.setStorageSync('authComparison', entrance.map(v => {
  412. v = v.list.map(s => {
  413. s.appid = v.appid;
  414. return s
  415. })
  416. return v
  417. }).flat())
  418. } else {
  419. setTimeout(this.refreshData, 10);
  420. return;
  421. }
  422. },
  423. /* 获取最新信息 */
  424. queryMessage(i = 0) {
  425. _Http.basic({
  426. "classname": "system.message.Message",
  427. "method": "queryMessage",
  428. content: {
  429. nocache: true,
  430. pageNumber: 1,
  431. pageSize: 5,
  432. pageTotal: 1,
  433. type: "",
  434. where: {}
  435. },
  436. }, false).then(res => {
  437. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  438. title: res.msg,
  439. icon: "none"
  440. })
  441. this.setData({
  442. msgList: res.data,
  443. notice: res.data[0]
  444. })
  445. if (this.data.msgList.length > 2) this.startDataCarousel();
  446. })
  447. },
  448. /* 开启消息轮播 */
  449. startDataCarousel() {
  450. clearInterval(DataCarousel);
  451. DataCarousel = setInterval(() => {
  452. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  453. this.setData({
  454. msgCount: count + 1,
  455. notice: this.data.msgList[count]
  456. })
  457. }, 5000)
  458. },
  459. /* 去消息详情 */
  460. toMsg(e) {
  461. const {
  462. item
  463. } = e.currentTarget.dataset;
  464. wx.navigateTo({
  465. url: '/pages/tabbar/message/details?id=' + item.messageid,
  466. })
  467. },
  468. /* banner */
  469. bannerClick(e) {
  470. const {
  471. item
  472. } = e.currentTarget.dataset,
  473. hyperlink = item.hyperlink.split(":");
  474. if (hyperlink[0] == 'path') wx.navigateTo({
  475. url: hyperlink[1]
  476. })
  477. },
  478. onShow() {
  479. this.getTabBar().init();
  480. if (this.data.msgList.length > 2) this.startDataCarousel();
  481. this.queryMessage(0); //更新最新消息
  482. },
  483. onHide() {
  484. clearInterval(DataCarousel);
  485. },
  486. onReady() {
  487. // this.setListHeight();
  488. },
  489. /* 设置页面高度 */
  490. setListHeight() {
  491. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  492. },
  493. onShareAppMessage() {}
  494. })