index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. },
  12. // 显示商品属性模态框
  13. showAddCartModal(e) {
  14. const product = e.detail;
  15. this.setData({
  16. showAddCartModal: true,
  17. currentProduct:product
  18. });
  19. },
  20. // 关闭商品属性模态框
  21. handleCloseAddCartModal() {
  22. this.setData({ showAddCartModal: false });
  23. },
  24. // 进入今日热门页
  25. hotBut: function(){
  26. wx.navigateTo({
  27. url: '../Mall/hotCommodity/hotCommodity',
  28. })
  29. },
  30. // 进入新品上市页
  31. newBut: function(){
  32. wx.navigateTo({
  33. url: '../Mall/newCommodity/newCommodity',
  34. })
  35. },
  36. // 进入预售页
  37. presaleBut: function(){
  38. wx.navigateTo({
  39. url: '../Mall/presaleCommodity/presaleCommodity',
  40. })
  41. },
  42. onLoad: async function (options) {
  43. // 生命周期函数--监听页面加载
  44. console.log("onLoad");
  45. console.log('App.globalData', App.globalData);
  46. const resBanner = await API.getBanners({});
  47. console.log('resBanner', resBanner);
  48. this.setData({
  49. bannerList : resBanner.bannerList
  50. });
  51. const resBrand = await API.getIpInfos({});
  52. console.log('resBrand', resBrand);
  53. this.setData({
  54. ipInfoList : resBrand.ipInfoList
  55. });
  56. const resCategory = await API.getProdClasses({});
  57. console.log('resCategory', resCategory);
  58. this.setData({
  59. prodClassList : resCategory.prodClassList
  60. });
  61. },
  62. })