index.js 8.9 KB

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