Browse Source

更新评估页面相关文件

pull/19/head
徐飞洋 1 month ago
parent
commit
f781deb18e
  1. 12
      pages/evaluate1/index.js
  2. 29
      pages/evaluate1/spec-detail.js
  3. 6
      pages/evaluate1/spec-detail.wxml

12
pages/evaluate1/index.js

@ -204,7 +204,7 @@ Page({
// 解析规格 // 解析规格
const specInfo = this.parseSpecification(spec); const specInfo = this.parseSpecification(spec);
let finalPrice = price; let finalPrice = parseFloat(price) || 0;
let finalPriceText = price; let finalPriceText = price;
// 根据规格类型和价格水平计算最终价格 // 根据规格类型和价格水平计算最终价格
@ -222,13 +222,17 @@ Page({
} }
} }
return { const specObj = {
name: spec, name: spec,
price: price, price: price,
priceText: price, priceText: price,
finalPrice: finalPrice, finalPrice: finalPrice,
finalPriceText: finalPriceText finalPriceText: finalPriceText
}; };
console.log('创建的规格对象:', specObj);
return specObj;
}); });
console.log('提取的规格和价格:', specifications); console.log('提取的规格和价格:', specifications);
@ -243,8 +247,10 @@ Page({
// 跳转到规格详情页面 // 跳转到规格详情页面
goToSpecDetail(e) { goToSpecDetail(e) {
const specItem = e.currentTarget.dataset.spec; const specItem = e.currentTarget.dataset.spec;
console.log('点击的规格项:', specItem);
console.log('传递的价格:', specItem.finalPriceText);
wx.navigateTo({ wx.navigateTo({
url: `/pages/evaluate1/spec-detail?productName=${encodeURIComponent(this.data.productName)}&specification=${encodeURIComponent(specItem.name)}&price=${encodeURIComponent(specItem.finalPrice)}` url: `/pages/evaluate1/spec-detail?productName=${encodeURIComponent(this.data.productName)}&specification=${encodeURIComponent(specItem.name)}&price=${encodeURIComponent(specItem.finalPriceText)}`
}); });
}, },

29
pages/evaluate1/spec-detail.js

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

6
pages/evaluate1/spec-detail.wxml

@ -11,7 +11,7 @@
</view> </view>
<view class="spec-item"> <view class="spec-item">
<text class="label">单价:</text> <text class="label">单价:</text>
<text class="value price">¥{{price.toFixed(2)}}</text> <text class="value price">¥{{price || 0}}</text>
</view> </view>
<view class="spec-info"> <view class="spec-info">
<text>您已选择此规格进行估价</text> <text>您已选择此规格进行估价</text>
@ -34,8 +34,8 @@
</view> </view>
<view class="result-section"> <view class="result-section">
<text class="result-label">总价:</text> <text class="result-label">预估:</text>
<text class="result-value">¥{{totalPrice.toFixed(2)}}</text> <text class="result-value">¥{{totalPrice > 0 ? totalPrice : ''}}</text>
</view> </view>
<view class="action"> <view class="action">

Loading…
Cancel
Save