index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // 进入sort页
  45. sortBut: function(){
  46. wx.navigateTo({
  47. url: '../Mall/sortCommodity/sortCommodity',
  48. })
  49. },
  50. onLoad: async function (options) {
  51. // 生命周期函数--监听页面加载
  52. console.log("onLoad");
  53. console.log('App.globalData', App.globalData);
  54. const resBanner = await API.getBanners({});
  55. console.log('resBanner', resBanner);
  56. this.setData({
  57. bannerList : resBanner.bannerList
  58. });
  59. const resBrand = await API.getIpInfos({});
  60. console.log('resBrand', resBrand);
  61. this.setData({
  62. ipInfoList : resBrand.ipInfoList
  63. });
  64. const resCategory = await API.getProdClasses({});
  65. console.log('resCategory', resCategory);
  66. this.setData({
  67. prodClassList : resCategory.prodClassList
  68. });
  69. },
  70. // onPageScroll: function(e) {
  71. // wx.createSelectorQuery()
  72. // .select('.container')
  73. // .boundingClientRect((rect) => {
  74. // if (rect) {
  75. // console.log("top" + rect.top);
  76. // const shouldBrandBeMini = rect.top <= -475; // 在container上移到-480px时,品牌栏mini出现
  77. // if (this.data.isBrandMini !== shouldBrandBeMini) {
  78. // this.setData({
  79. // isBrandMini: shouldBrandBeMini
  80. // });
  81. // }
  82. // const shouldCategoryBeMini = rect.top <= -600; // 在container上移到-680px时,分类栏mini出现
  83. // if (this.data.isCategoryMini !== shouldCategoryBeMini) {
  84. // this.setData({
  85. // isCategoryMini: shouldCategoryBeMini
  86. // });
  87. // }
  88. // }
  89. // })
  90. // .exec();
  91. // }
  92. })