index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: false
  12. },
  13. // 显示商品属性模态框
  14. showAddCartModal(e) {
  15. const product = e.detail;
  16. this.setData({
  17. showAddCartModal: true,
  18. currentProduct:product
  19. });
  20. },
  21. // 关闭商品属性模态框
  22. handleCloseAddCartModal() {
  23. this.setData({ showAddCartModal: false });
  24. },
  25. // 进入今日热门页
  26. hotBut: function(){
  27. wx.navigateTo({
  28. url: '../Mall/hotCommodity/hotCommodity',
  29. })
  30. },
  31. // 进入新品上市页
  32. newBut: function(){
  33. wx.navigateTo({
  34. url: '../Mall/newCommodity/newCommodity',
  35. })
  36. },
  37. // 进入预售页
  38. presaleBut: function(){
  39. wx.navigateTo({
  40. url: '../Mall/presaleCommodity/presaleCommodity',
  41. })
  42. },
  43. onLoad: async function (options) {
  44. // 生命周期函数--监听页面加载
  45. console.log("onLoad");
  46. console.log('App.globalData', App.globalData);
  47. // const resBanner = await API.getBanners({});
  48. // console.log('resBanner', resBanner);
  49. // this.setData({
  50. // bannerList : resBanner.bannerList
  51. // });
  52. // const resBrand = await API.getIpInfos({});
  53. // console.log('resBrand', resBrand);
  54. // this.setData({
  55. // ipInfoList : resBrand.ipInfoList
  56. // });
  57. // const resCategory = await API.getProdClasses({});
  58. // console.log('resCategory', resCategory);
  59. // this.setData({
  60. // prodClassList : resCategory.prodClassList
  61. // });
  62. this.setData({
  63. prodClassList: [
  64. { classUrl: 'someprod.jpg', title: '火影忍者' },
  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. ]
  71. });
  72. },
  73. onPageScroll: function(e) {
  74. wx.createSelectorQuery()
  75. .select('.brand-bar')
  76. .boundingClientRect((rect) => {
  77. if (rect) {
  78. const shouldBeMini = rect.top <= 40; // 在brand-bar进入顶部时,category切换为mini模式
  79. if (this.data.isCategoryMini !== shouldBeMini) {
  80. this.setData({
  81. isCategoryMini: shouldBeMini
  82. });
  83. }
  84. }
  85. })
  86. .exec();
  87. }
  88. })