index.js 5.2 KB

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