index.js 5.3 KB

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