index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. let pageInit = null,
  2. _Http = getApp().globalData.http;
  3. Page({
  4. data: {
  5. PageCur: 'Home',
  6. collectCount: "", //购物车商品数量
  7. msgList: []
  8. },
  9. onLoad(options) {
  10. pageInit = {
  11. Home: false,
  12. Message: false,
  13. Market: false,
  14. Collect: false,
  15. UserCenter: false,
  16. };
  17. if (options.PageCur) this.setData({
  18. PageCur: options.PageCur
  19. })
  20. this.refreshData();
  21. this.getCollectCount();
  22. this.updateMsgCount();
  23. },
  24. /**
  25. * 更新站点信息
  26. * 主要用来渲染首页的banner和宫格
  27. */
  28. refreshData() {
  29. getApp().globalData.getCollectCount = this.getCollectCount.bind(this); //更新购物车件数
  30. getApp().globalData.socketCallback = this.updateMsgCount.bind(this); //更新信息数量
  31. getApp().globalData.changeBar = this.cutBar.bind(this); //切换首页页面
  32. let page = this.selectComponent("#Home");
  33. if (page && wx.getStorageSync('userauth').length != 0) {
  34. let authList = {},
  35. entrance = [{
  36. label: "E-订单",
  37. appid: "wxc1b6ae925ac1d06a",
  38. icon: "work-E-dingdan",
  39. list: getedd()
  40. }];
  41. //E订单
  42. function getedd() {
  43. let paths = [{
  44. name: "商城",
  45. PageCur: "Market",
  46. icon: "work-shangcheng"
  47. }, {
  48. name: "销售订单",
  49. path: "/packageA/orderForm/index",
  50. icon: "work-dingdan"
  51. }, {
  52. name: "订单明细",
  53. path: "/packageA/orderForm/rows",
  54. icon: "work-dingdan"
  55. }, {
  56. name: "账户",
  57. path: "/packageA/account/index",
  58. icon: "work-zhanghu"
  59. }, {
  60. name: "促销活动",
  61. path: "/packageA/activity/index",
  62. icon: "work-cuxiaohuodong"
  63. }, {
  64. name: "打款凭证",
  65. path: "/packageA/remitVoucher/index",
  66. icon: "work-dakuanpingzheng"
  67. }, {
  68. name: "返退单",
  69. path: "/packageA/returnOne/index",
  70. icon: "work-shujuchaxun"
  71. }, {
  72. name: "发货单",
  73. path: "/packageA/dispatchBill/index",
  74. icon: "icon-shouhuo"
  75. }, {
  76. name: "发货明细",
  77. path: "/packageA/dispatchBill/rows",
  78. icon: "icon-shouhuo"
  79. }];
  80. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货管理", "业绩查询"]),
  81. list = [];
  82. edd.forEach(v => {
  83. v.apps.forEach(s => {
  84. authList[s.name] = {
  85. options: s.meta.auth.map(a => a.option),
  86. optionnames: s.meta.auth.map(a => a.optionname),
  87. }
  88. if (authList[s.name].options.some(s => s == "read")) {
  89. let i = paths.findIndex(k => k.name == s.meta.title);
  90. if (i != -1) {
  91. paths[i].index = i;
  92. list.push(paths[i])
  93. }
  94. }
  95. })
  96. });
  97. return dye(list.sort((a, b) => a.index - b.index))
  98. };
  99. //染色
  100. function dye(list) {
  101. let colorList = [{
  102. color: "#3874F6",
  103. bColor: "#F0F3FF",
  104. }, {
  105. color: "#5AB73F",
  106. bColor: "#F4FAEF",
  107. }, {
  108. color: "#F29C37",
  109. bColor: "#FCF6EF",
  110. }, {
  111. color: "#EB4B5C",
  112. bColor: "#FDF1ED",
  113. }, {
  114. color: "#3874F6",
  115. bColor: "#F0F3FF",
  116. }, {
  117. color: "#F29C37",
  118. bColor: "#FCF6EF",
  119. }, {
  120. color: "#EB4B5C",
  121. bColor: "#FDF1ED",
  122. }, {
  123. color: "#3874F6",
  124. bColor: "#F0F3FF",
  125. }, {
  126. color: "#5AB73F",
  127. bColor: "#F4FAEF",
  128. }, {
  129. color: "#F29C37",
  130. bColor: "#FCF6EF",
  131. }, {
  132. color: "#5AB73F",
  133. bColor: "#F4FAEF",
  134. }, {
  135. color: "#3874F6",
  136. bColor: "#F0F3FF",
  137. }, {
  138. color: "#F29C37",
  139. bColor: "#FCF6EF",
  140. }, {
  141. color: "#EB4B5C",
  142. bColor: "#FDF1ED",
  143. }, {
  144. color: "#5AB73F",
  145. bColor: "#F4FAEF",
  146. }];
  147. return list.map((v, i) => {
  148. return {
  149. ...v,
  150. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  151. }
  152. })
  153. };
  154. wx.setStorageSync('auth', authList)
  155. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  156. page.setData({
  157. entrance,
  158. bannerList: banner ? banner.ads : []
  159. });
  160. pageInit.Home = true;
  161. page.selectComponent("#ListBox").setHeight(".head", page);
  162. } else {
  163. setTimeout(this.refreshData, 10);
  164. return;
  165. }
  166. },
  167. /**
  168. * 更新购物车数量
  169. */
  170. getCollectCount() {
  171. return _Http.basic({
  172. "id": 20220927093202,
  173. "content": {}
  174. }).then(res => {
  175. console.log("购物车数量", res)
  176. getApp().globalData.collectCount = res.data.num;
  177. pageInit.Collect = false;
  178. this.setData({
  179. collectCount: res.data.num
  180. })
  181. return res.data.num;
  182. });
  183. },
  184. /* 更新消息数量 */
  185. updateMsgCount() {
  186. pageInit.Message = false;
  187. _Http.basic({
  188. "classname": "system.message.Message",
  189. "method": "unReadMessageCount",
  190. "content": {
  191. nocache: true
  192. }
  193. }, false).then(res => {
  194. console.log('信息数量', res)
  195. if (res.msg != '成功') return;
  196. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  197. if (res.data.fcount == 0) fcount = "";
  198. this.setData({
  199. fcount
  200. })
  201. });
  202. _Http.basic({
  203. "classname": "system.message.Message",
  204. "method": "queryMessage",
  205. content: {
  206. nocache: true,
  207. pageNumber: 1,
  208. pageSize: 1,
  209. type: "",
  210. where: {}
  211. },
  212. }).then(res => {
  213. if (res.msg != '成功') return;
  214. this.selectComponent("#Home").setData({
  215. msgList: res.data
  216. })
  217. })
  218. },
  219. /**
  220. * 切换页面
  221. */
  222. NavChange(e) {
  223. this.cutBar({
  224. detail: e.currentTarget.dataset.cur
  225. });
  226. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  227. },
  228. /**
  229. * 切换bar
  230. */
  231. cutBar({
  232. detail
  233. }) {
  234. let page = this.selectComponent("#" + detail);
  235. if (!page) return;
  236. if (!pageInit[detail] && page.init()) pageInit[detail] = true;
  237. this.setData({
  238. PageCur: detail
  239. })
  240. },
  241. })