index.js 9.2 KB

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