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.
49 lines
1.0 KiB
49 lines
1.0 KiB
|
1 month ago
|
Page({
|
||
|
|
data: {
|
||
|
|
productName: '',
|
||
|
|
specification: '',
|
||
|
|
price: 0,
|
||
|
|
quantity: 1,
|
||
|
|
totalPrice: 0,
|
||
|
|
loading: false,
|
||
|
|
error: ''
|
||
|
|
},
|
||
|
|
onLoad(options) {
|
||
|
|
if (options.productName && options.specification && options.price) {
|
||
|
|
const price = parseFloat(options.price) || 0;
|
||
|
|
this.setData({
|
||
|
|
productName: decodeURIComponent(options.productName),
|
||
|
|
specification: decodeURIComponent(options.specification),
|
||
|
|
price: price,
|
||
|
|
totalPrice: price
|
||
|
|
});
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 件数输入变化
|
||
|
|
onQuantityChange(e) {
|
||
|
|
const quantity = parseInt(e.detail.value) || 1;
|
||
|
|
this.setData({
|
||
|
|
quantity: quantity,
|
||
|
|
totalPrice: this.data.price * quantity
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 计算价格
|
||
|
|
calculatePrice() {
|
||
|
|
const totalPrice = this.data.price * this.data.quantity;
|
||
|
|
this.setData({
|
||
|
|
totalPrice: totalPrice
|
||
|
|
});
|
||
|
|
wx.showToast({
|
||
|
|
title: '计算完成',
|
||
|
|
icon: 'success',
|
||
|
|
duration: 1000
|
||
|
|
});
|
||
|
|
},
|
||
|
|
|
||
|
|
// 返回上一页
|
||
|
|
goBack() {
|
||
|
|
wx.navigateBack();
|
||
|
|
}
|
||
|
|
});
|