index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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/account/index",
  54. icon: "work-zhanghu"
  55. }, {
  56. name: "促销活动",
  57. path: "/packageA/activity/index",
  58. icon: "work-cuxiaohuodong"
  59. }, {
  60. name: "购物车",
  61. PageCur: "Collect",
  62. icon: "work-gouwuche"
  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. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货与库存", "业绩查询"]),
  77. list = [];
  78. edd.forEach(v => {
  79. v.apps.forEach(s => {
  80. authList[s.name] = {
  81. options: s.meta.auth.map(a => a.option),
  82. optionnames: s.meta.auth.map(a => a.optionname),
  83. }
  84. if (authList[s.name].options.some(s => s == "read")) {
  85. let i = paths.findIndex(k => k.name == s.meta.title);
  86. if (i != -1) {
  87. paths[i].index = i;
  88. list.push(paths[i])
  89. }
  90. }
  91. })
  92. });
  93. return dye(list.sort((a, b) => a.index - b.index))
  94. };
  95. //染色
  96. function dye(list) {
  97. let colorList = [{
  98. color: "#3874F6",
  99. bColor: "#F0F3FF",
  100. }, {
  101. color: "#5AB73F",
  102. bColor: "#F4FAEF",
  103. }, {
  104. color: "#F29C37",
  105. bColor: "#FCF6EF",
  106. }, {
  107. color: "#EB4B5C",
  108. bColor: "#FDF1ED",
  109. }, {
  110. color: "#3874F6",
  111. bColor: "#F0F3FF",
  112. }, {
  113. color: "#F29C37",
  114. bColor: "#FCF6EF",
  115. }, {
  116. color: "#EB4B5C",
  117. bColor: "#FDF1ED",
  118. }, {
  119. color: "#3874F6",
  120. bColor: "#F0F3FF",
  121. }, {
  122. color: "#5AB73F",
  123. bColor: "#F4FAEF",
  124. }, {
  125. color: "#F29C37",
  126. bColor: "#FCF6EF",
  127. }, {
  128. color: "#5AB73F",
  129. bColor: "#F4FAEF",
  130. }, {
  131. color: "#3874F6",
  132. bColor: "#F0F3FF",
  133. }, {
  134. color: "#F29C37",
  135. bColor: "#FCF6EF",
  136. }, {
  137. color: "#EB4B5C",
  138. bColor: "#FDF1ED",
  139. }, {
  140. color: "#5AB73F",
  141. bColor: "#F4FAEF",
  142. }];
  143. return list.map((v, i) => {
  144. return {
  145. ...v,
  146. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  147. }
  148. })
  149. };
  150. wx.setStorageSync('auth', authList)
  151. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  152. page.setData({
  153. entrance,
  154. bannerList: banner ? banner.ads : []
  155. });
  156. pageInit.Home = true;
  157. page.selectComponent("#ListBox").setHeight(".head", page);
  158. } else {
  159. setTimeout(this.refreshData, 10);
  160. return;
  161. }
  162. },
  163. /**
  164. * 更新购物车数量
  165. */
  166. getCollectCount() {
  167. return _Http.basic({
  168. "id": 20220927093202,
  169. "content": {}
  170. }).then(res => {
  171. console.log("购物车数量", res)
  172. getApp().globalData.collectCount = res.data.num;
  173. pageInit.Collect = false;
  174. this.setData({
  175. collectCount: res.data.num
  176. })
  177. return res.data.num;
  178. });
  179. },
  180. /* 更新消息数量 */
  181. updateMsgCount() {
  182. pageInit.Message = false;
  183. _Http.basic({
  184. "classname": "system.message.Message",
  185. "method": "unReadMessageCount",
  186. "content": {
  187. nocache: true
  188. }
  189. }, false).then(res => {
  190. console.log('信息数量', res)
  191. if (res.msg != '成功') return;
  192. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  193. if (res.data.fcount == 0) fcount = "";
  194. this.setData({
  195. fcount
  196. })
  197. });
  198. _Http.basic({
  199. "classname": "system.message.Message",
  200. "method": "queryMessage",
  201. content: {
  202. nocache: true,
  203. pageNumber: 1,
  204. pageSize: 1,
  205. type: "",
  206. where: {}
  207. },
  208. }).then(res => {
  209. if (res.msg != '成功') return;
  210. this.selectComponent("#Home").setData({
  211. msgList: res.data
  212. })
  213. })
  214. },
  215. /**
  216. * 切换页面
  217. */
  218. NavChange(e) {
  219. this.cutBar({
  220. detail: e.currentTarget.dataset.cur
  221. });
  222. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  223. },
  224. /**
  225. * 切换bar
  226. */
  227. cutBar({
  228. detail
  229. }) {
  230. let page = this.selectComponent("#" + detail);
  231. if (!page) return;
  232. if (!pageInit[detail] && page.init()) pageInit[detail] = true;
  233. this.setData({
  234. PageCur: detail
  235. })
  236. },
  237. })