You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
Page({
|
|
data: {
|
|
productNames: [],
|
|
loading: false,
|
|
error: ''
|
|
},
|
|
onLoad(options) {
|
|
this.loadProductNames();
|
|
},
|
|
|
|
loadProductNames() {
|
|
this.setData({ loading: true, error: '' });
|
|
|
|
const api = require('../../utils/api');
|
|
api.getProducts().then(products => {
|
|
// 提取唯一的productName
|
|
const uniqueProductNames = [...new Set(products.map(product => product.productName).filter(Boolean))];
|
|
this.setData({
|
|
productNames: uniqueProductNames,
|
|
loading: false
|
|
});
|
|
}).catch(err => {
|
|
console.error('获取商品列表失败:', err);
|
|
this.setData({
|
|
error: '获取商品列表失败,请稍后重试',
|
|
loading: false
|
|
});
|
|
});
|
|
},
|
|
|
|
selectProduct(e) {
|
|
const productName = e.currentTarget.dataset.product;
|
|
console.log('选择商品:', productName);
|
|
// 将商品名称存储到本地存储,因为wx.switchTab不支持URL参数
|
|
wx.setStorageSync('selectedProductName', productName);
|
|
// 使用wx.switchTab导航到tabBar页面
|
|
wx.switchTab({
|
|
url: '/pages/evaluate1/index',
|
|
success: function(res) {
|
|
console.log('跳转成功:', res);
|
|
},
|
|
fail: function(err) {
|
|
console.error('跳转失败:', err);
|
|
}
|
|
});
|
|
}
|
|
});
|