index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // index.js
  2. const { API } = require('../../service/api.js');
  3. const App = getApp();
  4. Page({
  5. data: {
  6. brandList: [
  7. {
  8. name: "全部IP",
  9. },
  10. {
  11. name: "火影忍者",
  12. },
  13. {
  14. name: "原神",
  15. },
  16. {
  17. name: "柯南",
  18. },
  19. {
  20. name: "非人哉",
  21. },
  22. {
  23. name: "海贼王",
  24. },
  25. {
  26. name: "初音",
  27. },
  28. {
  29. name: "千与千寻",
  30. },
  31. {
  32. name: "樱木花道",
  33. },
  34. {
  35. name: "原神",
  36. },
  37. ],
  38. categoryList: [
  39. {
  40. name: "立绘",
  41. },
  42. {
  43. name: "立绘",
  44. },
  45. {
  46. name: "立绘",
  47. },
  48. {
  49. name: "立绘",
  50. },
  51. {
  52. name: "立绘",
  53. },
  54. {
  55. name: "立绘",
  56. },
  57. {
  58. name: "立绘",
  59. },
  60. {
  61. name: "立绘",
  62. },
  63. ],
  64. showAddCartModal: false,
  65. currentProduct: null
  66. },
  67. // 显示商品属性模态框
  68. showAddCartModal(e) {
  69. const product = e.detail;
  70. this.setData({
  71. showAddCartModal: true,
  72. currentProduct:product
  73. });
  74. },
  75. // 关闭商品属性模态框
  76. handleCloseAddCartModal() {
  77. this.setData({ showAddCartModal: false });
  78. },
  79. // 添加购物车
  80. handleAddToCart(e) {
  81. const cartItem = e.detail.item;
  82. // 这里实现添加到购物车的逻辑
  83. console.log('添加到购物车:', cartItem);
  84. // 可以显示添加成功的提示
  85. wx.showToast({
  86. title: '已加入购物车',
  87. icon: 'success'
  88. });
  89. // 关闭弹框
  90. this.setData({ showAddCartModal: false });
  91. },
  92. methods: {
  93. onLoad: async function (options) {
  94. // 生命周期函数--监听页面加载
  95. console.log("onLoad");
  96. console.log('App.globalData', App.globalData);
  97. const res = await API.getBanners({});
  98. console.log('res', res);
  99. },
  100. },
  101. })