113 lines
3.6 KiB
JavaScript
113 lines
3.6 KiB
JavaScript
Page({
|
|
data: {
|
|
// 轮播图图片列表
|
|
imageList: [
|
|
'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png',
|
|
'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png',
|
|
'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png',
|
|
'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png',
|
|
'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png',
|
|
'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner6.png',
|
|
// 更多图片路径...
|
|
],
|
|
|
|
// 商品分类
|
|
categories: ['全部', '教材','课程资源包'],
|
|
|
|
// 当前选中的分类索引
|
|
currentCategoryIndex: 0,
|
|
|
|
// 商品列表
|
|
productList: [
|
|
{
|
|
image: 'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner1.png',
|
|
name: '商品名称1',
|
|
price: 99.99,
|
|
category: '教材'
|
|
},
|
|
{
|
|
image: 'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png',
|
|
name: '商品名称2',
|
|
price: 199.99,
|
|
category: '教材'
|
|
},
|
|
{
|
|
image: 'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner3.png',
|
|
name: '商品名称3',
|
|
price: 199.99,
|
|
category: '课程资源包'
|
|
},
|
|
{
|
|
image: 'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner4.png',
|
|
name: '商品名称4',
|
|
price: 199.99,
|
|
category: '课程资源包'
|
|
},
|
|
{
|
|
image: 'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner5.png',
|
|
name: '商品名称5',
|
|
price: 199.99,
|
|
category: '课程资源包'
|
|
},
|
|
// 更多商品数据...
|
|
],
|
|
|
|
// 过滤后的商品列表
|
|
filteredProductList: []
|
|
},
|
|
|
|
onPullDownRefresh: function() {
|
|
// 执行下拉刷新操作,如重新加载数据
|
|
// 模拟数据加载
|
|
wx.showNavigationBarLoading(); // 在标题栏中显示加载
|
|
|
|
// 假设这里进行了数据刷新
|
|
setTimeout(() => {
|
|
// 数据刷新完毕,停止加载
|
|
wx.hideNavigationBarLoading();
|
|
wx.stopPullDownRefresh(); // 停止下拉动作
|
|
}, 1500);
|
|
},
|
|
|
|
onLoad: function(options) {
|
|
// 页面加载时执行的初始化操作
|
|
this.filterProductsByCategory(this.data.currentCategoryIndex);
|
|
},
|
|
|
|
// 切换分类
|
|
switchCategory: function(e) {
|
|
const index = e.currentTarget.dataset.index;
|
|
this.setData({
|
|
currentCategoryIndex: index
|
|
});
|
|
this.filterProductsByCategory(index);
|
|
},
|
|
|
|
// 根据分类过滤商品列表
|
|
filterProductsByCategory: function(categoryIndex) {
|
|
let filteredList = [];
|
|
if (categoryIndex === 0) {
|
|
// 全部分类
|
|
filteredList = this.data.productList;
|
|
} else {
|
|
const selectedCategory = this.data.categories[categoryIndex];
|
|
filteredList = this.data.productList.filter(item => item.category === selectedCategory);
|
|
}
|
|
this.setData({
|
|
filteredProductList: filteredList
|
|
});
|
|
},
|
|
|
|
// 其他页面事件处理函数...
|
|
to_car() {
|
|
wx.navigateTo({
|
|
url: '/pages/shop/buycar/buycar',
|
|
})
|
|
},
|
|
|
|
to_goods() {
|
|
wx.navigateTo({
|
|
url: '/pages/shop/goods/goods',
|
|
})
|
|
}
|
|
}); |