index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. isBrandMini: false,
  12. isCategoryMini: 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('.container')
  77. .boundingClientRect((rect) => {
  78. if (rect) {
  79. const shouldBarandBeMini = rect.top <= -480; // 在container上移到-480px时,品牌栏mini出现
  80. if (this.data.isBrandMini !== shouldBarandBeMini) {
  81. this.setData({
  82. isBrandMini: shouldBarandBeMini
  83. });
  84. }
  85. const shouldCategoryBeMini = rect.top <= -680; // 在container上移到-680px时,分类栏mini出现
  86. if (this.data.isCategoryMini !== shouldCategoryBeMini) {
  87. this.setData({
  88. isCategoryMini: shouldCategoryBeMini
  89. });
  90. }
  91. }
  92. })
  93. .exec();
  94. }
  95. })