index.js 5.6 KB

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