index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Copyright (C) 2018-2019
  3. * All rights reserved, Designed By www.joolun.com
  4. * 注意:
  5. * 本软件为www.joolun.com开发研制,项目使用请保留此说明
  6. */
  7. const app = getApp()
  8. Page({
  9. data: {
  10. config: app.globalData.config,
  11. TabCur: 0,
  12. MainCur: 0,
  13. VerticalNavTop: 0,
  14. goodsCategory: [],
  15. load: true
  16. },
  17. onLoad() {
  18. app.initPage()
  19. .then(res => {
  20. this.goodsCategoryGet()
  21. })
  22. },
  23. onShow() {
  24. //更新tabbar购物车数量
  25. wx.setTabBarBadge({
  26. index: 2,
  27. text: app.globalData.shoppingCartCount + ''
  28. })
  29. },
  30. goodsCategoryGet() {
  31. app.api.goodsCategoryGet()
  32. .then(res => {
  33. let goodsCategory = res.data
  34. this.setData({
  35. goodsCategory: goodsCategory
  36. })
  37. })
  38. },
  39. tabSelect(e) {
  40. this.setData({
  41. TabCur: e.currentTarget.dataset.id,
  42. MainCur: e.currentTarget.dataset.id,
  43. VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
  44. })
  45. },
  46. VerticalMain(e) {
  47. let that = this
  48. let list = this.data.goodsCategory
  49. let tabHeight = 0
  50. if (this.data.load) {
  51. for (let i = 0; i < list.length; i++) {
  52. let view = wx.createSelectorQuery().select("#main-" + i)
  53. view.fields({
  54. size: true
  55. }, data => {
  56. list[i].top = tabHeight
  57. tabHeight = tabHeight + data.height
  58. list[i].bottom = tabHeight
  59. }).exec()
  60. }
  61. that.setData({
  62. load: false,
  63. goodsCategory: list
  64. })
  65. }
  66. let scrollTop = e.detail.scrollTop + 20
  67. for (let i = 0; i < list.length; i++) {
  68. if (scrollTop > list[i].top && scrollTop < list[i].bottom) {
  69. that.setData({
  70. VerticalNavTop: (i - 1) * 50,
  71. TabCur: i
  72. })
  73. return false
  74. }
  75. }
  76. }
  77. })