index.js 9.7 KB

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