index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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: "wx197f219a82a89d7b",
  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: "wx197f219a82a89d7b",
  44. list: gettool()
  45. }, {
  46. label: "CRM",
  47. appid: "wx197f219a82a89d7b",
  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/returnOne/index",
  241. icon: "work-shujuchaxun"
  242. }, {
  243. name: "居间费结算",
  244. path: "/packageA/betweenFee/index",
  245. icon: "work-jujianfeijiesuan"
  246. }, ];
  247. /* {
  248. name: "数据查询",
  249. path: "#",
  250. icon: "work-shujuchaxun"
  251. } */
  252. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货与库存", "业绩查询"]),
  253. list = [];
  254. edd.forEach(v => {
  255. v.apps.forEach(s => {
  256. authList[s.name] = {
  257. options: s.meta.auth.map(a => a.option),
  258. optionnames: s.meta.auth.map(a => a.optionname),
  259. }
  260. if (authList[s.name].options.some(s => s == "read")) {
  261. let i = paths.findIndex(k => k.name == s.meta.title);
  262. if (i != -1) {
  263. paths[i].index = i;
  264. list.push(paths[i])
  265. }
  266. }
  267. })
  268. });
  269. return dye(list.sort((a, b) => a.index - b.index))
  270. };
  271. //E服务
  272. function geteservice() {
  273. let paths = [{
  274. name: "工单",
  275. path: "/Eservice/workOrder/index",
  276. icon: "work-gongdan"
  277. }, {
  278. name: "申请单",
  279. path: "/Eservice/agent/serviceBillList/index",
  280. icon: "work-shenqingdan"
  281. }, {
  282. name: "申请单管理",
  283. path: "/Eservice/workerLeader/serviceBillList/index",
  284. icon: "work-shenqingdanguanli"
  285. }, {
  286. name: "业务员服务申请单",
  287. path: "/Eservice/saler/serviceBillList/index",
  288. icon: "work-yewuyuanfuwushenqingdan"
  289. }];
  290. let eservice = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-服务"], ["工单管理"]),
  291. list = [];
  292. eservice.forEach(v => {
  293. v.apps.forEach(s => {
  294. authList[s.name] = {
  295. options: s.meta.auth.map(a => a.option),
  296. optionnames: s.meta.auth.map(a => a.optionname),
  297. }
  298. if (authList[s.name].options.some(s => s == "read")) {
  299. let i = paths.findIndex(k => k.name == s.meta.title);
  300. if (i != -1) {
  301. paths[i].index = i;
  302. list.push(paths[i])
  303. }
  304. }
  305. })
  306. });
  307. return dye(list.sort((a, b) => a.index - b.index))
  308. }
  309. //染色
  310. function dye(list) {
  311. let colorList = [{
  312. color: "#3874F6",
  313. bColor: "#F0F3FF",
  314. }, {
  315. color: "#5AB73F",
  316. bColor: "#F4FAEF",
  317. }, {
  318. color: "#F29C37",
  319. bColor: "#FCF6EF",
  320. }, {
  321. color: "#EB4B5C",
  322. bColor: "#FDF1ED",
  323. }, {
  324. color: "#3874F6",
  325. bColor: "#F0F3FF",
  326. }, {
  327. color: "#F29C37",
  328. bColor: "#FCF6EF",
  329. }, {
  330. color: "#EB4B5C",
  331. bColor: "#FDF1ED",
  332. }, {
  333. color: "#3874F6",
  334. bColor: "#F0F3FF",
  335. }, {
  336. color: "#5AB73F",
  337. bColor: "#F4FAEF",
  338. }, {
  339. color: "#F29C37",
  340. bColor: "#FCF6EF",
  341. }, {
  342. color: "#5AB73F",
  343. bColor: "#F4FAEF",
  344. }, {
  345. color: "#3874F6",
  346. bColor: "#F0F3FF",
  347. }, {
  348. color: "#F29C37",
  349. bColor: "#FCF6EF",
  350. }, {
  351. color: "#EB4B5C",
  352. bColor: "#FDF1ED",
  353. }, {
  354. color: "#5AB73F",
  355. bColor: "#F4FAEF",
  356. }];
  357. return list.map((v, i) => {
  358. return {
  359. ...v,
  360. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  361. }
  362. })
  363. };
  364. wx.setStorageSync('auth', authList)
  365. this.setData({
  366. entrance,
  367. auth: JSON.stringify(authList),
  368. userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
  369. site: JSON.stringify(wx.getStorageSync('siteP'))
  370. })
  371. /* 获取首页banner */
  372. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  373. if (banner) this.setData({
  374. bannerList: banner.ads
  375. })
  376. } else {
  377. setTimeout(this.refreshData, 10);
  378. return;
  379. }
  380. },
  381. /* 获取最新信息 */
  382. queryMessage(i = 0) {
  383. _Http.basic({
  384. "classname": "system.message.Message",
  385. "method": "queryMessage",
  386. content: {
  387. nocache: true,
  388. pageNumber: 1,
  389. pageSize: 5,
  390. pageTotal: 1,
  391. type: "",
  392. where: {}
  393. },
  394. }, false).then(res => {
  395. if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
  396. title: res.msg,
  397. icon: "none"
  398. })
  399. this.setData({
  400. msgList: res.data,
  401. notice: res.data[0]
  402. })
  403. if (this.data.msgList.length > 2) this.startDataCarousel();
  404. })
  405. },
  406. /* 开启消息轮播 */
  407. startDataCarousel() {
  408. clearInterval(DataCarousel);
  409. DataCarousel = setInterval(() => {
  410. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  411. this.setData({
  412. msgCount: count + 1,
  413. notice: this.data.msgList[count]
  414. })
  415. }, 5000)
  416. },
  417. /* 去消息详情 */
  418. toMsg(e) {
  419. const {
  420. item
  421. } = e.currentTarget.dataset;
  422. wx.navigateTo({
  423. url: '/pages/tabbar/message/details?id=' + item.messageid,
  424. })
  425. },
  426. /* banner */
  427. bannerClick(e) {
  428. const {
  429. item
  430. } = e.currentTarget.dataset,
  431. hyperlink = item.hyperlink.split(":");
  432. if (hyperlink[0] == 'path') wx.navigateTo({
  433. url: hyperlink[1]
  434. })
  435. },
  436. onShow() {
  437. this.getTabBar().init();
  438. if (this.data.msgList.length > 2) this.startDataCarousel();
  439. this.queryMessage(0); //更新最新消息
  440. },
  441. onHide() {
  442. clearInterval(DataCarousel);
  443. },
  444. onReady() {
  445. // this.setListHeight();
  446. },
  447. /* 设置页面高度 */
  448. setListHeight() {
  449. this.selectComponent("#ListBox").setHeight(".grld-title", this);
  450. },
  451. onShareAppMessage() {}
  452. })