index.js 6.4 KB

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