index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. this.getAnnunciate();
  24. if (getApp().globalData.remindchangepassword_str) wx.showModal({
  25. title: "提示",
  26. content: getApp().globalData.remindchangepassword_str,
  27. confirmText: '前往修改',
  28. cancelText: "下次再说",
  29. success: ({
  30. confirm
  31. }) => {
  32. getApp().globalData.remindchangepassword_str = null;
  33. if (confirm) wx.navigateTo({
  34. url: '/pages/index/userCenter/changePassword/index',
  35. })
  36. },
  37. })
  38. },
  39. getAnnunciate() {
  40. _Http.basic({
  41. "id": 20221111090904,
  42. "content": {
  43. "nocache": true,
  44. "pageSize": 1,
  45. "where": {
  46. "condition": ""
  47. }
  48. }
  49. }).then(res => {
  50. console.log("获取一条通告", res)
  51. if (res.msg == '成功' && res.data.length) this.selectComponent("#Home").setData({
  52. annunciate: res.data[0]
  53. })
  54. })
  55. },
  56. onShow() {
  57. // if (wx.getAccountInfoSync().miniProgram.envVersion !== 'release') this.refreshData();
  58. },
  59. /**
  60. * 更新站点信息
  61. * 主要用来渲染首页的banner和宫格
  62. */
  63. refreshData() {
  64. getApp().globalData.getCollectCount = this.getCollectCount.bind(this); //更新购物车件数
  65. getApp().globalData.socketCallback = this.updateMsgCount.bind(this); //更新信息数量
  66. getApp().globalData.changeBar = this.cutBar.bind(this); //切换首页页面
  67. let page = this.selectComponent("#Home");
  68. if (page && wx.getStorageSync('userauth').length != 0) {
  69. let authList = {},
  70. entrance = [{
  71. label: "营销工具",
  72. icon: "work-yingxiaogongju",
  73. appid: "wx7505ddb0a1ec6146",
  74. list: gettool()
  75. }, {
  76. label: "E-订单",
  77. appid: "wx7505ddb0a1ec6146",
  78. icon: "work-E-dingdan",
  79. list: getedd()
  80. }];
  81. //营销工具
  82. function gettool() {
  83. const paths = [{
  84. name: "通告",
  85. path: "/marketing/annunciate/index",
  86. icon: "work-a-shouyejingangqutonggao",
  87. objectname: "sat_notice"
  88. }, {
  89. name: "营销物料",
  90. path: "/marketing/mediaLibrary/index",
  91. icon: "work-a-shouyejingangquyingxiaowuliao",
  92. objectname: "sys_attachment"
  93. }, {
  94. name: "推广素材",
  95. path: "/marketing/promotional/index",
  96. icon: "work-a-shouyejingangqutuiguangsucai",
  97. objectname: "sat_sharematerial"
  98. }, {
  99. name: "商学院",
  100. path: "/marketing/college/index",
  101. icon: "work-a-shangxueyuanxuexi",
  102. objectname: "sat_courseware"
  103. }, {
  104. name: "提报",
  105. path: "/marketing/submission/index",
  106. icon: "work-a-tibaoguanlitibao",
  107. objectname: "sat_submiteditmodel"
  108. }];
  109. let tool = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], paths.map(v => v.name)),
  110. list = [];
  111. tool.forEach(v => {
  112. let auth = v.apps[0].meta.auth;
  113. if (!auth.some(r => r.option == 'read')) return;
  114. authList[v.apps[0].name] = {
  115. options: auth.map(a => a.option),
  116. optionnames: auth.map(a => a.optionname)
  117. };
  118. let item = paths.find(s => s.name == v.systemmodulename);
  119. item && list.push(item)
  120. });
  121. return dye(list.sort((a, b) => a.index - b.index))
  122. };
  123. //E订单
  124. function getedd() {
  125. let paths = [{
  126. name: "商城",
  127. PageCur: "Market",
  128. icon: "work-shangcheng"
  129. }, {
  130. name: "订货单",
  131. path: "/packageA/orderForm/index",
  132. icon: "work-dingdan"
  133. }, {
  134. name: "订单明细",
  135. path: "/packageA/orderForm/rows",
  136. icon: "work-dingdan"
  137. }, {
  138. name: "账户",
  139. path: "/packageA/account/index",
  140. icon: "work-zhanghu"
  141. }, {
  142. name: "促销活动",
  143. path: "/packageA/activity/index",
  144. icon: "work-cuxiaohuodong"
  145. }, {
  146. name: "打款凭证",
  147. path: "/packageA/remitVoucher/index",
  148. icon: "work-dakuanpingzheng"
  149. }, {
  150. name: "物流单",
  151. path: "/packageA/shipment/index",
  152. icon: "icon-shouhuo"
  153. }, {
  154. name: "返退申请单",
  155. path: "/packageA/returnOne/index",
  156. icon: "work-shujuchaxun"
  157. }, {
  158. name: "发货单",
  159. path: "/packageA/dispatchBill/index",
  160. icon: "icon-shouhuo"
  161. }, {
  162. name: "发货明细",
  163. path: "/packageA/dispatchBill/rows",
  164. icon: "icon-shouhuo"
  165. }, {
  166. name: "工厂发退明细",
  167. path: "/packageA/dispatchBill/sentandback",
  168. icon: "icon-shouhuo"
  169. }];
  170. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货管理", "业绩查询"]),
  171. list = [];
  172. edd.forEach(v => {
  173. v.apps.forEach(s => {
  174. authList[s.name] = {
  175. options: s.meta.auth.map(a => a.option),
  176. optionnames: s.meta.auth.map(a => a.optionname),
  177. }
  178. if (authList[s.name].options.some(s => s == "read")) {
  179. let i = paths.findIndex(k => k.name == s.meta.title);
  180. if (i != -1) {
  181. paths[i].index = i;
  182. list.push(paths[i])
  183. }
  184. }
  185. })
  186. });
  187. return dye(list.sort((a, b) => a.index - b.index))
  188. };
  189. //染色
  190. function dye(list) {
  191. let colorList = [{
  192. color: "#3874F6",
  193. bColor: "#F0F3FF",
  194. }, {
  195. color: "#5AB73F",
  196. bColor: "#F4FAEF",
  197. }, {
  198. color: "#F29C37",
  199. bColor: "#FCF6EF",
  200. }, {
  201. color: "#EB4B5C",
  202. bColor: "#FDF1ED",
  203. }, {
  204. color: "#3874F6",
  205. bColor: "#F0F3FF",
  206. }, {
  207. color: "#F29C37",
  208. bColor: "#FCF6EF",
  209. }, {
  210. color: "#EB4B5C",
  211. bColor: "#FDF1ED",
  212. }, {
  213. color: "#3874F6",
  214. bColor: "#F0F3FF",
  215. }, {
  216. color: "#5AB73F",
  217. bColor: "#F4FAEF",
  218. }, {
  219. color: "#F29C37",
  220. bColor: "#FCF6EF",
  221. }, {
  222. color: "#5AB73F",
  223. bColor: "#F4FAEF",
  224. }, {
  225. color: "#3874F6",
  226. bColor: "#F0F3FF",
  227. }, {
  228. color: "#F29C37",
  229. bColor: "#FCF6EF",
  230. }, {
  231. color: "#EB4B5C",
  232. bColor: "#FDF1ED",
  233. }, {
  234. color: "#5AB73F",
  235. bColor: "#F4FAEF",
  236. }];
  237. return list.map((v, i) => {
  238. return {
  239. ...v,
  240. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  241. }
  242. })
  243. };
  244. wx.setStorageSync('auth', authList)
  245. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  246. page.setData({
  247. entrance,
  248. bannerList: banner ? banner.ads : []
  249. });
  250. pageInit.Home = true;
  251. page.selectComponent("#ListBox").setHeight(".head", page);
  252. } else {
  253. setTimeout(this.refreshData, 10);
  254. return;
  255. }
  256. },
  257. /* 获取通告列表 */
  258. /**
  259. * 更新购物车数量
  260. */
  261. getCollectCount() {
  262. return _Http.basic({
  263. "id": 20220927093202,
  264. "content": {}
  265. }).then(res => {
  266. console.log("购物车数量", res)
  267. getApp().globalData.collectCount = res.data.num;
  268. pageInit.Collect = false;
  269. this.setData({
  270. collectCount: res.data.num
  271. })
  272. return res.data.num;
  273. });
  274. },
  275. /* 更新消息数量 */
  276. updateMsgCount() {
  277. pageInit.Message = false;
  278. _Http.basic({
  279. "classname": "system.message.Message",
  280. "method": "unReadMessageCount",
  281. "content": {
  282. nocache: true
  283. }
  284. }, false).then(res => {
  285. console.log('信息数量', res)
  286. if (res.msg != '成功') return;
  287. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  288. if (res.data.fcount == 0) fcount = "";
  289. this.setData({
  290. fcount
  291. })
  292. });
  293. _Http.basic({
  294. "classname": "system.message.Message",
  295. "method": "queryMessage",
  296. content: {
  297. nocache: true,
  298. pageNumber: 1,
  299. pageSize: 1,
  300. type: "",
  301. where: {}
  302. },
  303. }).then(res => {
  304. if (res.msg != '成功') return;
  305. this.selectComponent("#Home").setData({
  306. msgList: res.data
  307. })
  308. })
  309. },
  310. /**
  311. * 切换页面
  312. */
  313. NavChange(e) {
  314. this.cutBar({
  315. detail: e.currentTarget.dataset.cur
  316. });
  317. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  318. },
  319. /**
  320. * 切换bar
  321. */
  322. cutBar({
  323. detail
  324. }) {
  325. let page = this.selectComponent("#" + detail);
  326. if (!page) return;
  327. if (!pageInit[detail] && page.init()) pageInit[detail] = true;
  328. this.setData({
  329. PageCur: detail
  330. })
  331. },
  332. })