index.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. this.selectComponent('#Annunciate').getList();
  74. // if (wx.getAccountInfoSync().miniProgram.envVersion !== 'release') this.refreshData();
  75. },
  76. /**
  77. * 更新站点信息
  78. * 主要用来渲染首页的banner和宫格
  79. */
  80. refreshData() {
  81. getApp().globalData.getCollectCount = this.getCollectCount.bind(this); //更新购物车件数
  82. getApp().globalData.getFavoriteCount = this.getFavoriteCount.bind(this); //更新收藏夹件数
  83. getApp().globalData.socketCallback = this.updateMsgCount.bind(this); //更新信息数量
  84. getApp().globalData.changeBar = this.cutBar.bind(this); //切换首页页面
  85. let page = this.selectComponent("#Home");
  86. if (page && wx.getStorageSync('userauth').length != 0) {
  87. let authList = {},
  88. entrance = [{
  89. label: "E-订单",
  90. appid: "wx7505ddb0a1ec6146",
  91. icon: "work-E-dingdan",
  92. list: getedd()
  93. }];
  94. //E订单
  95. function getedd() {
  96. let paths = [{
  97. name: "商城",
  98. key: "wmarket",
  99. PageCur: "Market",
  100. icon: "work-shangcheng"
  101. }, {
  102. name: "订货单",
  103. key: "worderform",
  104. path: "/packageA/orderForm/index",
  105. icon: "work-dingdan"
  106. }, {
  107. name: "订单明细",
  108. key: "worderdetails",
  109. path: "/packageA/orderForm/rows",
  110. icon: "work-dingdan"
  111. }, {
  112. name: "账户",
  113. key: "waccount",
  114. path: "/packageA/account/index",
  115. icon: "work-zhanghu"
  116. }, {
  117. name: "促销活动",
  118. key: "wdiscounts",
  119. path: "/packageA/activity/index",
  120. icon: "work-cuxiaohuodong"
  121. }, {
  122. name: "打款凭证",
  123. key: "wpaymentdocument",
  124. path: "/packageA/remitVoucher/index",
  125. icon: "work-dakuanpingzheng"
  126. }, {
  127. name: "物流单",
  128. key: "wlogisticsbill",
  129. path: "/packageA/shipment/index",
  130. icon: "icon-shouhuo"
  131. }, {
  132. name: "返退申请单",
  133. key: "wreturn",
  134. path: "/packageA/returnOne/index",
  135. icon: "work-shujuchaxun"
  136. }, {
  137. name: "发货单",
  138. key: "wdispatch",
  139. path: "/packageA/dispatchBill/index",
  140. icon: "icon-shouhuo"
  141. }, {
  142. name: "发货明细",
  143. key: "wdeliverydetail",
  144. path: "/packageA/dispatchBill/rows",
  145. icon: "icon-shouhuo"
  146. }, {
  147. name: "工厂发退明细",
  148. key: "wsentandback",
  149. path: "/packageA/dispatchBill/sentandback",
  150. icon: "icon-shouhuo"
  151. }, {
  152. name: "业绩目标",
  153. key: "wtarget",
  154. path: "/packageA/target/index",
  155. icon: "work-yejimubiao"
  156. }, {
  157. name: "收藏夹",
  158. key: "wfavorites",
  159. path: "/packageA/favorites/index",
  160. icon: "work-webshoucang"
  161. }, {
  162. name: "通告",
  163. path: "/marketing/annunciate/index",
  164. icon: "work-a-shouyejingangqutonggao",
  165. objectname: "sat_notice"
  166. }];
  167. let edd = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案", "销售管理", "财务管理", "售后管理", "发货管理", "业绩查询", '消息中心']).concat(getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["通用"], ['消息中心'])),
  168. list = [];
  169. edd.forEach(v => {
  170. v.apps.forEach(s => {
  171. authList[s.name] = {
  172. options: s.meta.auth.map(a => a.option),
  173. optionnames: s.meta.auth.map(a => a.optionname),
  174. forms: s.meta.forms
  175. }
  176. if (authList[s.name].options.some(s => s == "read")) {
  177. let i = paths.findIndex(k => k.key == s.name || k.name == s.meta.title);
  178. if (i != -1) {
  179. paths[i].name = s.meta.title;
  180. paths[i].index = i;
  181. paths[i].isneedpay = s.isneedpay;
  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. console.log("entrance", entrance)
  253. return entrance.find(v => v.label == "E-订单").list
  254. } else {
  255. setTimeout(this.refreshData, 10);
  256. return;
  257. }
  258. },
  259. /* 获取通告列表 */
  260. /**
  261. * 更新购物车数量
  262. */
  263. getCollectCount() {
  264. return _Http.basic({
  265. "id": 20220927093202,
  266. "content": {}
  267. }).then(res => {
  268. console.log("购物车数量", res)
  269. getApp().globalData.collectCount = res.data.num;
  270. pageInit.Collect = false;
  271. this.setData({
  272. collectCount: res.data.num
  273. })
  274. return res.data.num;
  275. });
  276. },
  277. /* 更新收藏夹数量 */
  278. getFavoriteCount() {
  279. return _Http.basic({
  280. "id": 20231121145103,
  281. "content": {
  282. pageSize: 1,
  283. nocache: true
  284. }
  285. }).then(res => {
  286. console.log("收藏夹数量", res)
  287. getApp().globalData.favoriteCount = res.total;
  288. this.setData({
  289. favoriteCount: res.data.num
  290. })
  291. return res.total;
  292. });
  293. },
  294. /* 更新消息数量 */
  295. updateMsgCount() {
  296. pageInit.Message = false;
  297. _Http.basic({
  298. "classname": "system.message.Message",
  299. "method": "unReadMessageCount",
  300. "content": {
  301. nocache: true
  302. }
  303. }, false).then(res => {
  304. console.log('信息数量', res)
  305. if (res.msg != '成功') return;
  306. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  307. if (res.data.fcount == 0) fcount = "";
  308. this.setData({
  309. fcount
  310. })
  311. });
  312. _Http.basic({
  313. "classname": "system.message.Message",
  314. "method": "queryMessage",
  315. content: {
  316. nocache: true,
  317. pageNumber: 1,
  318. pageSize: 1,
  319. type: "",
  320. where: {}
  321. },
  322. }).then(res => {
  323. if (res.msg != '成功') return;
  324. this.selectComponent("#Home").setData({
  325. msgList: res.data
  326. })
  327. })
  328. },
  329. /**
  330. * 切换页面
  331. */
  332. async NavChange(e) {
  333. let cur = e.currentTarget.dataset.cur;
  334. if (cur == 'Home') this.selectComponent('#Annunciate').getList();
  335. if (this.data.PageCur == cur) return;
  336. if (cur == 'Market' || cur == 'Collect') {
  337. let app = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ["E-订单"], ["商品档案"])[0].apps
  338. let item = app.find(v => v.name == (cur == 'Market' ? "wmarket" : "wshoppingtrolley"))
  339. const res = await getApp().globalData.evidence(item);
  340. if (res) {
  341. this.cutBar({
  342. detail: e.currentTarget.dataset.cur
  343. });
  344. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  345. }
  346. } else {
  347. this.cutBar({
  348. detail: e.currentTarget.dataset.cur
  349. });
  350. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  351. }
  352. },
  353. /**
  354. * 切换bar
  355. */
  356. cutBar({
  357. detail
  358. }) {
  359. let page = this.selectComponent("#" + detail);
  360. if (!page) return;
  361. if (!pageInit[detail] && page.init()) pageInit[detail] = true;
  362. this.setData({
  363. PageCur: detail
  364. })
  365. },
  366. })