现象:
用户截图显示:
加载项目
↓
QuotationEditorComponent.loadProjectProducts()
↓ 从Parse查询Product表
productQuery.equalTo('project', this.project.toPointer())
↓ 获取产品列表
this.products = [product1, product2, ...]
↓
generateQuotationFromProducts()
↓ 遍历每个产品
for (const product of this.products) {
const quotation = product.get('quotation') || {};
const basePrice = quotation.price || calculateBasePrice(...); // ← 问题
↓
如果 quotation.price 为 0 或 undefined
↓ 调用calculateBasePrice计算
但可能返回0
↓
生成processes(基于basePrice=0)
↓
最终报价为¥0
}
Product表中的quotation字段问题:
Product.quotation.price 可能不存在Product.quotation.price 可能为 0Product.quotation 可能为空对象 {}calculateBasePrice可能返回0:
价格未正确保存到Product表:
修改文件:quotation-editor.component.ts
修改方法:generateQuotationFromProducts() (第539-592行)
// 🔥 关键修复:从Product.quotation.price读取价格,如果为0或undefined则重新计算
let basePrice = quotation.price || 0;
console.log(`📊 [报价生成] 产品"${productName}"价格检查:`, {
quotationPrice: quotation.price,
productId: product.id,
spaceType: space.spaceType,
priceLevel: this.projectInfo.priceLevel,
projectType: this.projectInfo.projectType
});
// 如果价格为0或undefined,重新计算
if (!basePrice || basePrice === 0) {
console.log(`⚠️ 产品"${productName}"价格为0,重新计算...`);
basePrice = this.calculateBasePrice({
priceLevel: this.projectInfo.priceLevel,
projectType: this.projectInfo.projectType,
renderType: this.projectInfo.renderType,
spaceType: space.spaceType || this.getDefaultSpaceType(),
styleLevel: space.styleLevel,
businessType: space.businessType,
architectureType: space.architectureType
});
console.log(`✅ 重新计算价格: ${basePrice}`);
// 🔥 立即保存到Product表,避免下次还是0
if (basePrice > 0) {
quotation.price = Math.round(basePrice);
quotation.basePrice = Math.round(basePrice);
product.set('quotation', quotation);
// 异步保存,不阻塞流程
product.save().then(() => {
console.log(`✅ 产品"${productName}"价格已更新到Product表: ${Math.round(basePrice)}`);
}).catch((err: any) => {
console.error(`❌ 保存产品"${productName}"价格失败:`, err);
});
}
}
检查价格是否为0:
product.get('quotation').price 读取重新计算价格:
calculateBasePrice() 方法保存到Product表:
quotation.price 和 quotation.basePrice详细日志输出:
修改方法:calculateBasePrice() (第424-471行)
console.log('💰 [计算基础价格] 输入参数:', {
priceLevel,
projectType,
renderType,
spaceType,
styleLevel,
businessType,
architectureType
});
const basePrice = getBasePrice(
priceLevel,
projectType as '家装' | '工装' | '建筑类',
renderType,
spaceType,
styleLevel,
businessType,
architectureType
);
console.log('💰 [计算基础价格] getBasePrice返回:', basePrice);
const finalPrice = Math.round(basePrice);
console.log('💰 [计算基础价格] 最终价格:', finalPrice);
return finalPrice;
输入参数验证:
计算过程追踪:
最终价格确认:
Product.quotation = {
priceLevel: '一级', // 价格级别
basePrice: 12800, // 基础价格
price: 12800, // 最终价格(重要!)
currency: 'CNY', // 货币
breakdown: { // 价格分解
modeling: 1280, // 建模10%
decoration: 5120, // 软装渲染40%
company: 6400 // 公司分配50%
},
status: 'draft', // 状态
validUntil: Date, // 有效期
processes: { // 工序分配(可选)
modeling: { enabled: true, amount: 1280, percentage: 10 },
softDecor: { enabled: true, amount: 2560, percentage: 20 },
rendering: { enabled: true, amount: 2560, percentage: 20 },
postProcess: { enabled: true, amount: 6400, percentage: 50 }
}
}
price - 最终价格,这是报价显示的主要字段basePrice - 基础价格,与price相同breakdown - 价格分解,可选processes - 工序分配,可选快捷键:F12 或 Ctrl+Shift+I
查看日志输出:
📊 [报价生成] 产品"厨房"价格检查: {
quotationPrice: 0,
productId: "xxx",
spaceType: "平层",
priceLevel: "一级",
projectType: "家装"
}
⚠️ 产品"厨房"价格为0,重新计算...
💰 [计算基础价格] 输入参数: {
priceLevel: "一级",
projectType: "家装",
renderType: "静态单张",
spaceType: "平层",
styleLevel: undefined,
businessType: undefined,
architectureType: undefined
}
💰 [计算基础价格] getBasePrice返回: 12800
💰 [计算基础价格] 最终价格: 12800
✅ 重新计算价格: 12800
✅ 产品"厨房"价格已更新到Product表: 12800
检查Parse Dashboard:
刷新页面:
原因:
解决方案:
现象:
❌ 保存产品"厨房"价格失败: Permission denied
解决方案:
现象:
💰 [计算基础价格] 输入参数: {
priceLevel: undefined,
projectType: undefined,
...
}
解决方案:
this.projectInfo 是否正确加载projectType 和 data.priceLevel加载项目
↓
loadProjectProducts() → 从Product表加载产品
↓
generateQuotationFromProducts()
↓
遍历产品,检查quotation.price
↓
如果price为0或undefined
↓ 重新计算
calculateBasePrice() → getBasePrice()
↓ 返回正确的价格(如12800)
basePrice = 12800
↓ 保存到Product表
product.set('quotation', { price: 12800, ... })
product.save()
↓ 生成报价明细
processes = generateDefaultProcesses(12800)
↓ 计算总价
calculateTotal() → this.quotation.total = 总和
↓ 发送事件
totalChange.emit(total)
↓ 父组件接收
StageOrderComponent.onTotalChange(total)
↓ 同步到项目
project.data.quotation.total = total
↓ 显示在页面
报价:¥12,800 ✅
修复完成时间:2024年11月15日 10:20 修复人员:Cascade AI Assistant