|
|
|
@ -9,29 +9,40 @@ Page({ |
|
|
|
error: '' |
|
|
|
}, |
|
|
|
onLoad(options) { |
|
|
|
if (options.productName && options.specification && options.price) { |
|
|
|
const price = parseFloat(options.price) || 0; |
|
|
|
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: decodeURIComponent(options.productName), |
|
|
|
specification: decodeURIComponent(options.specification), |
|
|
|
productName: productName, |
|
|
|
specification: specification, |
|
|
|
price: price, |
|
|
|
totalPrice: price |
|
|
|
totalPrice: 0 // 初始时总价为0,不显示
|
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 件数输入变化
|
|
|
|
onQuantityChange(e) { |
|
|
|
const quantity = parseInt(e.detail.value) || 1; |
|
|
|
this.setData({ |
|
|
|
quantity: quantity, |
|
|
|
totalPrice: this.data.price * quantity |
|
|
|
quantity: quantity |
|
|
|
// 只更新件数,不更新总价,等待点击计算按钮
|
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 计算价格
|
|
|
|
calculatePrice() { |
|
|
|
const totalPrice = this.data.price * this.data.quantity; |
|
|
|
const totalPrice = Math.round(this.data.price * this.data.quantity * 10) / 10; |
|
|
|
this.setData({ |
|
|
|
totalPrice: totalPrice |
|
|
|
}); |
|
|
|
|