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.
76 lines
1.8 KiB
76 lines
1.8 KiB
Page({
|
|
data: {
|
|
productName: '',
|
|
specification: '',
|
|
price: 0,
|
|
quantity: 1,
|
|
totalPrice: 0,
|
|
loading: false,
|
|
error: ''
|
|
},
|
|
onLoad(options) {
|
|
console.log('接收到的参数:', options);
|
|
// 即使参数不完整,也要尝试获取并设置
|
|
const productName = options.productName ? decodeURIComponent(options.productName) : '';
|
|
const specification = options.specification ? decodeURIComponent(options.specification) : '';
|
|
let price = 0;
|
|
|
|
if (options.price) {
|
|
const decodedPrice = decodeURIComponent(options.price);
|
|
console.log('解码后的价格:', decodedPrice);
|
|
price = parseFloat(decodedPrice) || 0;
|
|
}
|
|
|
|
console.log('解析后的参数:', { productName, specification, price });
|
|
|
|
this.setData({
|
|
productName: productName,
|
|
specification: specification,
|
|
price: price,
|
|
totalPrice: 0 // 初始时总价为0,不显示
|
|
});
|
|
},
|
|
|
|
// 件数输入变化
|
|
onQuantityChange(e) {
|
|
const quantity = parseInt(e.detail.value) || 1;
|
|
this.setData({
|
|
quantity: quantity
|
|
// 只更新件数,不更新总价,等待点击计算按钮
|
|
});
|
|
},
|
|
|
|
// 减少数量
|
|
decreaseQuantity() {
|
|
if (this.data.quantity > 1) {
|
|
this.setData({
|
|
quantity: this.data.quantity - 1
|
|
});
|
|
}
|
|
},
|
|
|
|
// 增加数量
|
|
increaseQuantity() {
|
|
this.setData({
|
|
quantity: this.data.quantity + 1
|
|
});
|
|
},
|
|
|
|
// 计算价格
|
|
calculatePrice() {
|
|
const totalPrice = Math.round(this.data.price * this.data.quantity * 10) / 10;
|
|
this.setData({
|
|
totalPrice: totalPrice
|
|
});
|
|
wx.showToast({
|
|
title: '计算完成',
|
|
icon: 'success',
|
|
duration: 1000
|
|
});
|
|
},
|
|
|
|
// 返回上一页
|
|
goBack() {
|
|
wx.navigateBack();
|
|
}
|
|
});
|