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.
store_node/miniprogram/pages/secondhand/detail.js

100 lines
2.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 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]
};
}
})