index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. let page = this.selectComponent("#Home");
  32. if (page && wx.getStorageSync('userauth').length != 0) {
  33. let authList = {},
  34. entrance = [{
  35. label: "E-订单",
  36. appid: "wxc1b6ae925ac1d06a",
  37. icon: "work-E-dingdan",
  38. list: getedd()
  39. }];
  40. //E订单
  41. function getedd() {
  42. let paths = [{
  43. name: "商城",
  44. PageCur: "Market",
  45. icon: "work-shangcheng"
  46. }, {
  47. name: "销售订单",
  48. path: "/packageA/orderForm/index",
  49. icon: "work-dingdan"
  50. }, {
  51. name: "账户",
  52. path: "/packageA/account/index",
  53. icon: "work-zhanghu"
  54. }, {
  55. name: "促销活动",
  56. path: "/packageA/activity/index",
  57. icon: "work-cuxiaohuodong"
  58. }, {
  59. name: "购物车",
  60. PageCur: "Collect",
  61. icon: "work-gouwuche"
  62. }, {
  63. name: "打款凭证",
  64. path: "/packageA/remitVoucher/index",
  65. icon: "work-dakuanpingzheng"
  66. }, {
  67. name: "退返申请",
  68. path: "/packageA/returnOne/index",
  69. icon: "work-shujuchaxun"
  70. }, {
  71. name: "发货单",
  72. path: "/packageA/dispatchBill/index",
  73. icon: "icon-shouhuo"
  74. }];
  75. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货与库存", "业绩查询"]),
  76. list = [];
  77. edd.forEach(v => {
  78. v.apps.forEach(s => {
  79. authList[s.name] = {
  80. options: s.meta.auth.map(a => a.option),
  81. optionnames: s.meta.auth.map(a => a.optionname),
  82. }
  83. if (authList[s.name].options.some(s => s == "read")) {
  84. let i = paths.findIndex(k => k.name == s.meta.title);
  85. if (i != -1) {
  86. paths[i].index = i;
  87. list.push(paths[i])
  88. }
  89. }
  90. })
  91. });
  92. return dye(list.sort((a, b) => a.index - b.index))
  93. };
  94. //染色
  95. function dye(list) {
  96. let colorList = [{
  97. color: "#3874F6",
  98. bColor: "#F0F3FF",
  99. }, {
  100. color: "#5AB73F",
  101. bColor: "#F4FAEF",
  102. }, {
  103. color: "#F29C37",
  104. bColor: "#FCF6EF",
  105. }, {
  106. color: "#EB4B5C",
  107. bColor: "#FDF1ED",
  108. }, {
  109. color: "#3874F6",
  110. bColor: "#F0F3FF",
  111. }, {
  112. color: "#F29C37",
  113. bColor: "#FCF6EF",
  114. }, {
  115. color: "#EB4B5C",
  116. bColor: "#FDF1ED",
  117. }, {
  118. color: "#3874F6",
  119. bColor: "#F0F3FF",
  120. }, {
  121. color: "#5AB73F",
  122. bColor: "#F4FAEF",
  123. }, {
  124. color: "#F29C37",
  125. bColor: "#FCF6EF",
  126. }, {
  127. color: "#5AB73F",
  128. bColor: "#F4FAEF",
  129. }, {
  130. color: "#3874F6",
  131. bColor: "#F0F3FF",
  132. }, {
  133. color: "#F29C37",
  134. bColor: "#FCF6EF",
  135. }, {
  136. color: "#EB4B5C",
  137. bColor: "#FDF1ED",
  138. }, {
  139. color: "#5AB73F",
  140. bColor: "#F4FAEF",
  141. }];
  142. return list.map((v, i) => {
  143. return {
  144. ...v,
  145. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  146. }
  147. })
  148. };
  149. wx.setStorageSync('auth', authList)
  150. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  151. page.setData({
  152. entrance,
  153. bannerList: banner ? banner.ads : []
  154. });
  155. pageInit.Home = true;
  156. page.selectComponent("#ListBox").setHeight(".head", page);
  157. } else {
  158. setTimeout(this.refreshData, 10);
  159. return;
  160. }
  161. },
  162. /**
  163. * 更新购物车数量
  164. */
  165. getCollectCount() {
  166. return _Http.basic({
  167. "id": 20220927093202,
  168. "content": {}
  169. }).then(res => {
  170. console.log("购物车数量", res)
  171. getApp().globalData.collectCount = res.data.num;
  172. pageInit.Collect = false;
  173. this.setData({
  174. collectCount: res.data.num
  175. })
  176. return res.data.num;
  177. });
  178. },
  179. /* 更新消息数量 */
  180. updateMsgCount() {
  181. console.log("调用")
  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. })