|
|
// pages/secondhand/detail.js
|
|
|
Page({
|
|
|
data: {
|
|
|
goods: {
|
|
|
id: 1,
|
|
|
title: 'iPad Pro 2021 二手95新',
|
|
|
price: 4500,
|
|
|
condition: '95新',
|
|
|
description: '正品iPad Pro 2021款,11英寸,WiFi版,128G存储,银色。机器成色非常好,无磕碰无划痕,电池健康96%,原装充电器配件齐全。有需要的请联系我。',
|
|
|
images: [
|
|
|
'/images/ipad_1.jpg',
|
|
|
'/images/ipad_2.jpg',
|
|
|
'/images/ipad_3.jpg'
|
|
|
],
|
|
|
publishTime: '2023-05-20 14:30',
|
|
|
category: 'electronics',
|
|
|
seller: {
|
|
|
id: 'user456',
|
|
|
name: '张同学',
|
|
|
avatar: '/images/avatar.png',
|
|
|
verifyType: '大三学生'
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
|
|
|
onLoad: function(options) {
|
|
|
const goodsId = options.id;
|
|
|
// 根据goodsId从服务器获取商品详情
|
|
|
// 这里模拟获取数据
|
|
|
this.getGoodsDetail(goodsId);
|
|
|
},
|
|
|
|
|
|
getGoodsDetail: function(goodsId) {
|
|
|
// 模拟从服务器获取数据
|
|
|
// 实际场景中应该发起网络请求
|
|
|
console.log('获取商品详情,ID:', goodsId);
|
|
|
// 现在使用的是模拟数据,实际应该替换成从服务器获取的数据
|
|
|
},
|
|
|
|
|
|
previewImage: function(e) {
|
|
|
const index = e.currentTarget.dataset.index;
|
|
|
wx.previewImage({
|
|
|
current: this.data.goods.images[index],
|
|
|
urls: this.data.goods.images
|
|
|
});
|
|
|
},
|
|
|
|
|
|
contactSeller: function() {
|
|
|
wx.showModal({
|
|
|
title: '联系卖家',
|
|
|
content: '联系电话:138****5678\n微信:zhangsan123',
|
|
|
showCancel: false
|
|
|
});
|
|
|
},
|
|
|
|
|
|
buyNow: function() {
|
|
|
wx.showModal({
|
|
|
title: '确认购买',
|
|
|
content: `您确定要购买"${this.data.goods.title}"吗?价格:¥${this.data.goods.price}`,
|
|
|
success: (res) => {
|
|
|
if (res.confirm) {
|
|
|
// 确认购买,调用购买接口
|
|
|
this.confirmPurchase();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
confirmPurchase: function() {
|
|
|
// 模拟调用购买接口
|
|
|
wx.showLoading({
|
|
|
title: '处理中...',
|
|
|
});
|
|
|
|
|
|
// 模拟网络请求延迟
|
|
|
setTimeout(() => {
|
|
|
wx.hideLoading();
|
|
|
|
|
|
wx.showToast({
|
|
|
title: '购买成功',
|
|
|
icon: 'success',
|
|
|
duration: 2000,
|
|
|
success: () => {
|
|
|
// 延迟返回,让用户看到成功提示
|
|
|
setTimeout(() => {
|
|
|
wx.navigateBack();
|
|
|
}, 1500);
|
|
|
}
|
|
|
});
|
|
|
}, 1500);
|
|
|
},
|
|
|
|
|
|
onShareAppMessage: function() {
|
|
|
return {
|
|
|
title: this.data.goods.title,
|
|
|
path: `/pages/secondhand/detail?id=${this.data.goods.id}`,
|
|
|
imageUrl: this.data.goods.images[0]
|
|
|
};
|
|
|
}
|
|
|
})
|