index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. let pageInit = null,
  2. _Http = getApp().globalData.http,
  3. {
  4. vIndate
  5. } = require("../../utils/pay");
  6. Page({
  7. data: {
  8. PageCur: 'Home',
  9. collectCount: "", //购物车商品数量
  10. msgList: [],
  11. favoriteCount: 0, //收藏夹数量
  12. },
  13. onLoad(options) {
  14. pageInit = {
  15. Home: false,
  16. Message: false,
  17. Market: false,
  18. Collect: false,
  19. UserCenter: false,
  20. };
  21. if (options.PageCur) this.setData({
  22. PageCur: options.PageCur
  23. })
  24. this.refreshData();
  25. this.getCollectCount();
  26. this.getFavoriteCount();
  27. this.updateMsgCount();
  28. this.getAnnunciate();
  29. if (getApp().globalData.remindchangepassword_str) wx.showModal({
  30. title: "提示",
  31. content: getApp().globalData.remindchangepassword_str,
  32. confirmText: '前往修改',
  33. cancelText: "下次再说",
  34. success: ({
  35. confirm
  36. }) => {
  37. getApp().globalData.remindchangepassword_str = null;
  38. if (confirm) wx.navigateTo({
  39. url: '/pages/index/userCenter/changePassword/index',
  40. })
  41. },
  42. })
  43. getApp().globalData.http.refreshData = this.refreshData.bind(this);
  44. this.getVIndete();
  45. },
  46. getVIndete() {
  47. if (wx.getStorageSync('siteP').siteid) {
  48. vIndate();
  49. } else {
  50. setTimeout(() => {
  51. this.getVIndete();
  52. }, 100)
  53. }
  54. },
  55. getAnnunciate() {
  56. _Http.basic({
  57. "id": 20221111090904,
  58. "content": {
  59. "nocache": true,
  60. "pageSize": 1,
  61. "where": {
  62. "condition": ""
  63. }
  64. }
  65. }).then(res => {
  66. console.log("获取一条通告", res)
  67. if (res.msg == '成功' && res.data.length) this.selectComponent("#Home").setData({
  68. annunciate: res.data[0]
  69. })
  70. })
  71. },
  72. onShow() {
  73. // if (wx.getAccountInfoSync().miniProgram.envVersion !== 'release') this.refreshData();
  74. },
  75. /**
  76. * 更新站点信息
  77. * 主要用来渲染首页的banner和宫格
  78. */
  79. refreshData() {
  80. getApp().globalData.getCollectCount = this.getCollectCount.bind(this); //更新购物车件数
  81. getApp().globalData.getFavoriteCount = this.getFavoriteCount.bind(this); //更新收藏夹件数
  82. getApp().globalData.socketCallback = this.updateMsgCount.bind(this); //更新信息数量
  83. getApp().globalData.changeBar = this.cutBar.bind(this); //切换首页页面
  84. let page = this.selectComponent("#Home");
  85. if (page && wx.getStorageSync('userauth').length != 0) {
  86. let authList = {},
  87. entrance = [{
  88. label: "营销工具",
  89. icon: "work-yingxiaogongju",
  90. appid: "wx7505ddb0a1ec6146",
  91. list: gettool()
  92. }, {
  93. label: "E-订单",
  94. appid: "wx7505ddb0a1ec6146",
  95. icon: "work-E-dingdan",
  96. list: getedd()
  97. }];
  98. //营销工具
  99. function gettool() {
  100. const paths = [{
  101. name: "通告",
  102. path: "/marketing/annunciate/index",
  103. icon: "work-a-shouyejingangqutonggao",
  104. objectname: "sat_notice"
  105. }, {
  106. name: "营销物料",
  107. path: "/marketing/mediaLibrary/index",
  108. icon: "work-a-shouyejingangquyingxiaowuliao",
  109. objectname: "sys_attachment"
  110. }, {
  111. name: "推广素材",
  112. path: "/marketing/promotional/index",
  113. icon: "work-a-shouyejingangqutuiguangsucai",
  114. objectname: "sat_sharematerial"
  115. }, {
  116. name: "商学院",
  117. path: "/marketing/college/index",
  118. icon: "work-a-shangxueyuanxuexi",
  119. objectname: "sat_courseware"
  120. }, {
  121. name: "提报",
  122. path: "/marketing/submission/index",
  123. icon: "work-a-tibaoguanlitibao",
  124. objectname: "sat_submiteditmodel"
  125. }];
  126. let tool = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], paths.map(v => v.name)),
  127. list = [];
  128. tool.forEach(v => {
  129. let auth = v.apps[0].meta.auth;
  130. if (!auth.some(r => r.option == 'read')) return;
  131. authList[v.apps[0].name] = {
  132. options: auth.map(a => a.option),
  133. optionnames: auth.map(a => a.optionname)
  134. };
  135. let item = paths.find(s => s.name == v.systemmodulename);
  136. item && list.push(item)
  137. });
  138. return dye(list.sort((a, b) => a.index - b.index))
  139. };
  140. //E订单
  141. function getedd() {
  142. let paths = [{
  143. name: "商城",
  144. key: "wmarket",
  145. PageCur: "Market",
  146. icon: "work-shangcheng"
  147. }, {
  148. name: "订货单",
  149. key: "worderform",
  150. path: "/packageA/orderForm/index",
  151. icon: "work-dingdan"
  152. }, {
  153. name: "订单明细",
  154. key: "worderdetails",
  155. path: "/packageA/orderForm/rows",
  156. icon: "work-dingdan"
  157. }, {
  158. name: "账户",
  159. key: "waccount",
  160. path: "/packageA/account/index",
  161. icon: "work-zhanghu"
  162. }, {
  163. name: "促销活动",
  164. key: "wdiscounts",
  165. path: "/packageA/activity/index",
  166. icon: "work-cuxiaohuodong"
  167. }, {
  168. name: "打款凭证",
  169. key: "wpaymentdocument",
  170. path: "/packageA/remitVoucher/index",
  171. icon: "work-dakuanpingzheng"
  172. }, {
  173. name: "物流单",
  174. key: "wlogisticsbill",
  175. path: "/packageA/shipment/index",
  176. icon: "icon-shouhuo"
  177. }, {
  178. name: "返退申请单",
  179. key: "wreturn",
  180. path: "/packageA/returnOne/index",
  181. icon: "work-shujuchaxun"
  182. }, {
  183. name: "发货单",
  184. key: "wdispatch",
  185. path: "/packageA/dispatchBill/index",
  186. icon: "icon-shouhuo"
  187. }, {
  188. name: "发货明细",
  189. key: "wdeliverydetail",
  190. path: "/packageA/dispatchBill/rows",
  191. icon: "icon-shouhuo"
  192. }, {
  193. name: "工厂发退明细",
  194. key: "wsentandback",
  195. path: "/packageA/dispatchBill/sentandback",
  196. icon: "icon-shouhuo"
  197. }, {
  198. name: "业绩目标",
  199. key: "wtarget",
  200. path: "/packageA/target/index",
  201. icon: "work-yejimubiao"
  202. }, {
  203. name: "收藏夹",
  204. key: "wfavorites",
  205. path: "/packageA/favorites/index",
  206. icon: "work-webshoucang"
  207. }];
  208. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货管理", "业绩查询"]),
  209. list = [];
  210. edd.forEach(v => {
  211. v.apps.forEach(s => {
  212. authList[s.name] = {
  213. options: s.meta.auth.map(a => a.option),
  214. optionnames: s.meta.auth.map(a => a.optionname),
  215. forms: s.meta.forms
  216. }
  217. if (authList[s.name].options.some(s => s == "read")) {
  218. let i = paths.findIndex(k => k.key == s.name || k.name == s.meta.title);
  219. if (i != -1) {
  220. paths[i].name = s.meta.title;
  221. paths[i].index = i;
  222. paths[i].isneedpay = s.isneedpay;
  223. list.push(paths[i])
  224. }
  225. }
  226. })
  227. });
  228. return dye(list.sort((a, b) => a.index - b.index))
  229. };
  230. //染色
  231. function dye(list) {
  232. let colorList = [{
  233. color: "#3874F6",
  234. bColor: "#F0F3FF",
  235. }, {
  236. color: "#5AB73F",
  237. bColor: "#F4FAEF",
  238. }, {
  239. color: "#F29C37",
  240. bColor: "#FCF6EF",
  241. }, {
  242. color: "#EB4B5C",
  243. bColor: "#FDF1ED",
  244. }, {
  245. color: "#3874F6",
  246. bColor: "#F0F3FF",
  247. }, {
  248. color: "#F29C37",
  249. bColor: "#FCF6EF",
  250. }, {
  251. color: "#EB4B5C",
  252. bColor: "#FDF1ED",
  253. }, {
  254. color: "#3874F6",
  255. bColor: "#F0F3FF",
  256. }, {
  257. color: "#5AB73F",
  258. bColor: "#F4FAEF",
  259. }, {
  260. color: "#F29C37",
  261. bColor: "#FCF6EF",
  262. }, {
  263. color: "#5AB73F",
  264. bColor: "#F4FAEF",
  265. }, {
  266. color: "#3874F6",
  267. bColor: "#F0F3FF",
  268. }, {
  269. color: "#F29C37",
  270. bColor: "#FCF6EF",
  271. }, {
  272. color: "#EB4B5C",
  273. bColor: "#FDF1ED",
  274. }, {
  275. color: "#5AB73F",
  276. bColor: "#F4FAEF",
  277. }];
  278. return list.map((v, i) => {
  279. return {
  280. ...v,
  281. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  282. }
  283. })
  284. };
  285. wx.setStorageSync('auth', authList)
  286. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  287. page.setData({
  288. entrance,
  289. bannerList: banner ? banner.ads : []
  290. });
  291. pageInit.Home = true;
  292. page.selectComponent("#ListBox").setHeight(".head", page);
  293. console.log("entrance", entrance)
  294. return entrance.find(v => v.label == "E-订单").list
  295. } else {
  296. setTimeout(this.refreshData, 10);
  297. return;
  298. }
  299. },
  300. /* 获取通告列表 */
  301. /**
  302. * 更新购物车数量
  303. */
  304. getCollectCount() {
  305. return _Http.basic({
  306. "id": 20220927093202,
  307. "content": {}
  308. }).then(res => {
  309. console.log("购物车数量", res)
  310. getApp().globalData.collectCount = res.data.num;
  311. pageInit.Collect = false;
  312. this.setData({
  313. collectCount: res.data.num
  314. })
  315. return res.data.num;
  316. });
  317. },
  318. /* 更新收藏夹数量 */
  319. getFavoriteCount() {
  320. return _Http.basic({
  321. "id": 20231121145103,
  322. "content": {
  323. pageSize: 1,
  324. nocache: true
  325. }
  326. }).then(res => {
  327. console.log("收藏夹数量", res)
  328. getApp().globalData.favoriteCount = res.total;
  329. this.setData({
  330. favoriteCount: res.data.num
  331. })
  332. return res.total;
  333. });
  334. },
  335. /* 更新消息数量 */
  336. updateMsgCount() {
  337. pageInit.Message = false;
  338. _Http.basic({
  339. "classname": "system.message.Message",
  340. "method": "unReadMessageCount",
  341. "content": {
  342. nocache: true
  343. }
  344. }, false).then(res => {
  345. console.log('信息数量', res)
  346. if (res.msg != '成功') return;
  347. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  348. if (res.data.fcount == 0) fcount = "";
  349. this.setData({
  350. fcount
  351. })
  352. });
  353. _Http.basic({
  354. "classname": "system.message.Message",
  355. "method": "queryMessage",
  356. content: {
  357. nocache: true,
  358. pageNumber: 1,
  359. pageSize: 1,
  360. type: "",
  361. where: {}
  362. },
  363. }).then(res => {
  364. if (res.msg != '成功') return;
  365. this.selectComponent("#Home").setData({
  366. msgList: res.data
  367. })
  368. })
  369. },
  370. /**
  371. * 切换页面
  372. */
  373. async NavChange(e) {
  374. let cur = e.currentTarget.dataset.cur;
  375. if (this.data.PageCur == cur) return;
  376. if (cur == 'Market' || cur == 'Collect') {
  377. let app = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案"])[0].apps
  378. let item = app.find(v => v.name == (cur == 'Market' ? "wmarket" : "wshoppingtrolley"))
  379. const res = await getApp().globalData.evidence(item);
  380. if (res) {
  381. this.cutBar({
  382. detail: e.currentTarget.dataset.cur
  383. });
  384. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  385. }
  386. } else {
  387. this.cutBar({
  388. detail: e.currentTarget.dataset.cur
  389. });
  390. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  391. }
  392. },
  393. /**
  394. * 切换bar
  395. */
  396. cutBar({
  397. detail
  398. }) {
  399. let page = this.selectComponent("#" + detail);
  400. if (!page) return;
  401. if (!pageInit[detail] && page.init()) pageInit[detail] = true;
  402. this.setData({
  403. PageCur: detail
  404. })
  405. },
  406. })