index.js 17 KB

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