goods_cate.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { getCategoryList} from '../../api/store.js';
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. navlist: [],
  9. productList: [],
  10. navActive: 0,
  11. parameter: {
  12. 'navbar': '1',
  13. 'return': '0',
  14. 'title':'产品分类'
  15. },
  16. navH:"",
  17. number:""
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (res) {
  23. this.getAllCategory();
  24. },
  25. infoScroll:function(){
  26. let that = this;
  27. let len = that.data.productList.length;
  28. that.setData({
  29. navH: app.globalData.navHeight,
  30. number: that.data.productList[len - 1].children.length
  31. })
  32. //设置商品列表高度
  33. wx.getSystemInfo({
  34. success: function (res) {
  35. that.setData({
  36. height: (res.windowHeight) * ( 750/res.windowWidth) - 98 - app.globalData.navHeight
  37. //res.windowHeight:获取整个窗口高度为px,*2为rpx;98为头部占据的高度;
  38. })
  39. },
  40. });
  41. var height = 0;
  42. var hightArr = [];
  43. for (var i = 0; i < len; i++) { //productList
  44. //获取元素所在位置
  45. var query = wx.createSelectorQuery().in(this);
  46. var idView = "#b" + i;
  47. query.select(idView).boundingClientRect();
  48. query.exec(function (res) {
  49. var top = res[0].top;
  50. hightArr.push(top);
  51. that.setData({
  52. hightArr: hightArr
  53. });
  54. });
  55. };
  56. },
  57. tap: function (e) {
  58. var id = e.currentTarget.dataset.id;
  59. var index = e.currentTarget.dataset.index;
  60. this.setData({
  61. toView: id,
  62. navActive: index
  63. });
  64. },
  65. getAllCategory:function(){
  66. var that = this;
  67. getCategoryList().then(res=>{
  68. that.setData({
  69. productList: res.data
  70. });
  71. that.infoScroll();
  72. })
  73. },
  74. scroll: function (e) {
  75. var scrollTop = e.detail.scrollTop;
  76. var scrollArr = this.data.hightArr;
  77. for (var i = 0; i < scrollArr.length; i++) {
  78. if (scrollTop >= 0 && scrollTop < scrollArr[1] - scrollArr[0]) {
  79. this.setData({
  80. navActive: 0,
  81. lastActive: 0
  82. })
  83. } else if (scrollTop >= scrollArr[i] - scrollArr[0] && scrollTop < scrollArr[i + 1] - scrollArr[0]) {
  84. this.setData({
  85. navActive: i
  86. })
  87. } else if (scrollTop >= scrollArr[scrollArr.length - 1] - scrollArr[0]) {
  88. this.setData({
  89. navActive: scrollArr.length - 1
  90. })
  91. }
  92. }
  93. },
  94. searchSubmitValue: function (e) {
  95. if (e.detail.value.length > 0)
  96. wx.navigateTo({ url: '/pages/goods_list/goods_list?searchValue=' + e.detail.value})
  97. else
  98. return app.Tips({ title:'请填写要搜索的产品信息'});
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. }
  125. })