index.js 12 KB

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