index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // index.js
  2. const { API } = require('../../service/api.js');
  3. const App = getApp();
  4. Page({
  5. data: {
  6. bannerList: [],
  7. ipInfoList: [],
  8. prodClassList: [],
  9. showAddCartModal: false,
  10. currentProduct: null,
  11. isCategoryMini_1: false,
  12. isCategoryMini_2: false
  13. },
  14. // 显示商品属性模态框
  15. showAddCartModal(e) {
  16. const product = e.detail;
  17. this.setData({
  18. showAddCartModal: true,
  19. currentProduct:product
  20. });
  21. },
  22. // 关闭商品属性模态框
  23. handleCloseAddCartModal() {
  24. this.setData({ showAddCartModal: false });
  25. },
  26. // 进入今日热门页
  27. hotBut: function(){
  28. wx.navigateTo({
  29. url: '../Mall/hotCommodity/hotCommodity',
  30. })
  31. },
  32. // 进入新品上市页
  33. newBut: function(){
  34. wx.navigateTo({
  35. url: '../Mall/newCommodity/newCommodity',
  36. })
  37. },
  38. // 进入预售页
  39. presaleBut: function(){
  40. wx.navigateTo({
  41. url: '../Mall/presaleCommodity/presaleCommodity',
  42. })
  43. },
  44. onLoad: async function (options) {
  45. // 生命周期函数--监听页面加载
  46. console.log("onLoad");
  47. console.log('App.globalData', App.globalData);
  48. // const resBanner = await API.getBanners({});
  49. // console.log('resBanner', resBanner);
  50. // this.setData({
  51. // bannerList : resBanner.bannerList
  52. // });
  53. // const resBrand = await API.getIpInfos({});
  54. // console.log('resBrand', resBrand);
  55. // this.setData({
  56. // ipInfoList : resBrand.ipInfoList
  57. // });
  58. // const resCategory = await API.getProdClasses({});
  59. // console.log('resCategory', resCategory);
  60. // this.setData({
  61. // prodClassList : resCategory.prodClassList
  62. // });
  63. this.setData({
  64. prodClassList: [
  65. { classUrl: 'someprod.jpg', title: '火影忍者' },
  66. { classUrl: 'someprod.jpg', title: '初音' },
  67. { classUrl: 'someprod.jpg', title: '原神' },
  68. { classUrl: 'someprod.jpg', title: '柯南' },
  69. { classUrl: 'someprod.jpg', title: '非人哉' },
  70. { classUrl: 'someprod.jpg', title: '全部' },
  71. ]
  72. });
  73. },
  74. onPageScroll: function(e) {
  75. wx.createSelectorQuery()
  76. .select('.brand-bar-1')
  77. .boundingClientRect((rect) => {
  78. if (rect) {
  79. const shouldBeMini = rect.top <= 40; // 在brand-bar进入顶部时,category切换为mini模式
  80. if (this.data.isCategoryMini_1 !== shouldBeMini) {
  81. this.setData({
  82. isCategoryMini_1: shouldBeMini
  83. });
  84. }
  85. }
  86. })
  87. .exec();
  88. wx.createSelectorQuery()
  89. .select('.brand-bar-2')
  90. .boundingClientRect((rect) => {
  91. if (rect) {
  92. const shouldBeMini = rect.top <= 40; // 在brand-bar进入顶部时,category切换为mini模式
  93. if (this.data.isCategoryMini_2 !== shouldBeMini) {
  94. this.setData({
  95. isCategoryMini_2: shouldBeMini
  96. });
  97. }
  98. }
  99. })
  100. .exec();
  101. }
  102. })