index.js 10.0 KB

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