index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. name: "业绩目标",
  176. path: "/packageA/target/index",
  177. icon: "work-yejimubiao"
  178. }];
  179. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货管理", "业绩查询"]),
  180. list = [];
  181. edd.forEach(v => {
  182. v.apps.forEach(s => {
  183. authList[s.name] = {
  184. options: s.meta.auth.map(a => a.option),
  185. optionnames: s.meta.auth.map(a => a.optionname),
  186. }
  187. if (authList[s.name].options.some(s => s == "read")) {
  188. let i = paths.findIndex(k => k.name == s.meta.title);
  189. if (i != -1) {
  190. paths[i].index = i;
  191. paths[i].isneedpay = s.isneedpay;
  192. list.push(paths[i])
  193. }
  194. }
  195. })
  196. });
  197. return dye(list.sort((a, b) => a.index - b.index))
  198. };
  199. //染色
  200. function dye(list) {
  201. let colorList = [{
  202. color: "#3874F6",
  203. bColor: "#F0F3FF",
  204. }, {
  205. color: "#5AB73F",
  206. bColor: "#F4FAEF",
  207. }, {
  208. color: "#F29C37",
  209. bColor: "#FCF6EF",
  210. }, {
  211. color: "#EB4B5C",
  212. bColor: "#FDF1ED",
  213. }, {
  214. color: "#3874F6",
  215. bColor: "#F0F3FF",
  216. }, {
  217. color: "#F29C37",
  218. bColor: "#FCF6EF",
  219. }, {
  220. color: "#EB4B5C",
  221. bColor: "#FDF1ED",
  222. }, {
  223. color: "#3874F6",
  224. bColor: "#F0F3FF",
  225. }, {
  226. color: "#5AB73F",
  227. bColor: "#F4FAEF",
  228. }, {
  229. color: "#F29C37",
  230. bColor: "#FCF6EF",
  231. }, {
  232. color: "#5AB73F",
  233. bColor: "#F4FAEF",
  234. }, {
  235. color: "#3874F6",
  236. bColor: "#F0F3FF",
  237. }, {
  238. color: "#F29C37",
  239. bColor: "#FCF6EF",
  240. }, {
  241. color: "#EB4B5C",
  242. bColor: "#FDF1ED",
  243. }, {
  244. color: "#5AB73F",
  245. bColor: "#F4FAEF",
  246. }];
  247. return list.map((v, i) => {
  248. return {
  249. ...v,
  250. ...colorList[i > colorList.length - 1 ? i - colorList.length : i]
  251. }
  252. })
  253. };
  254. wx.setStorageSync('auth', authList)
  255. let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
  256. page.setData({
  257. entrance,
  258. bannerList: banner ? banner.ads : []
  259. });
  260. pageInit.Home = true;
  261. page.selectComponent("#ListBox").setHeight(".head", page);
  262. console.log("entrance", entrance)
  263. return entrance.find(v => v.label == "E-订单").list
  264. } else {
  265. setTimeout(this.refreshData, 10);
  266. return;
  267. }
  268. },
  269. /* 获取通告列表 */
  270. /**
  271. * 更新购物车数量
  272. */
  273. getCollectCount() {
  274. return _Http.basic({
  275. "id": 20220927093202,
  276. "content": {}
  277. }).then(res => {
  278. console.log("购物车数量", res)
  279. getApp().globalData.collectCount = res.data.num;
  280. pageInit.Collect = false;
  281. this.setData({
  282. collectCount: res.data.num
  283. })
  284. return res.data.num;
  285. });
  286. },
  287. /* 更新消息数量 */
  288. updateMsgCount() {
  289. pageInit.Message = false;
  290. _Http.basic({
  291. "classname": "system.message.Message",
  292. "method": "unReadMessageCount",
  293. "content": {
  294. nocache: true
  295. }
  296. }, false).then(res => {
  297. console.log('信息数量', res)
  298. if (res.msg != '成功') return;
  299. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  300. if (res.data.fcount == 0) fcount = "";
  301. this.setData({
  302. fcount
  303. })
  304. });
  305. _Http.basic({
  306. "classname": "system.message.Message",
  307. "method": "queryMessage",
  308. content: {
  309. nocache: true,
  310. pageNumber: 1,
  311. pageSize: 1,
  312. type: "",
  313. where: {}
  314. },
  315. }).then(res => {
  316. if (res.msg != '成功') return;
  317. this.selectComponent("#Home").setData({
  318. msgList: res.data
  319. })
  320. })
  321. },
  322. /**
  323. * 切换页面
  324. */
  325. async NavChange(e) {
  326. let cur = e.currentTarget.dataset.cur;
  327. if (this.data.PageCur == cur) return;
  328. if (cur == 'Market' || cur == 'Collect') {
  329. let app = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案"])[0].apps
  330. let item = app.find(v => v.name == (cur == 'Market' ? "wmarket" : "wshoppingtrolley"))
  331. const res = await getApp().globalData.evidence(item);
  332. if (res) {
  333. this.cutBar({
  334. detail: e.currentTarget.dataset.cur
  335. });
  336. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  337. }
  338. } else {
  339. this.cutBar({
  340. detail: e.currentTarget.dataset.cur
  341. });
  342. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  343. }
  344. },
  345. /**
  346. * 切换bar
  347. */
  348. cutBar({
  349. detail
  350. }) {
  351. let page = this.selectComponent("#" + detail);
  352. if (!page) return;
  353. if (!pageInit[detail] && page.init()) pageInit[detail] = true;
  354. this.setData({
  355. PageCur: detail
  356. })
  357. },
  358. })