feat(product):优化产品价格计算逻辑

- 新增 calcFlag 标志位控制价格计算时机
- 修改价格计算触发事件从 input 改为 change
- 调整 catalogueAllPrice 计算逻辑,增加折扣处理
- 注释掉 productTable2 的 catalogueAllPrice 计算逻辑
- 修复价格计算函数中的条件判断逻辑
dev_1.0.0
chenhao 2025-09-23 14:15:33 +08:00
parent 2862498b2f
commit c96a90d69a
1 changed files with 24 additions and 22 deletions

View File

@ -107,6 +107,7 @@
<!-- JS 函数引用或内联 -->
<script th:inline="javascript"> /*<![CDATA[*/
let canUpdateFlag=[[${canUpdate}]]
let calcFlag = false;
const updatePriceProductList=['8813A3YA','8813A3YB','8813A7U4','8813A7U2']
const quantityStep = ['3130A4TE']
const FOLD_ON_FOLD = 0.988;
@ -168,6 +169,7 @@
});
}
function setOrderPriceData(){
calcFlag = true;
let allPrice=0.00;
$(".all-price-column").find('.allPrice').each(function (index) {
allPrice+=parseFloat($(this).val())
@ -383,7 +385,7 @@
* 计算所有产品的目录总价之和并分配到updatePriceProductList产品的目录单价
*/
function calculateAndDistributeCataloguePrice() {
if (!canUpdateFlag){
if (!canUpdateFlag || !calcFlag) {
return;
}
// 1. 获取需要更新价格的产品行
@ -423,15 +425,15 @@
total += catalogueAllPrice;
}
});
// 计算终端产品表格productTable2
$('#productTable2 tbody tr').each(function () {
let productCode = $(this).find('.productBomCode').val();
// 排除固定产品
if (!EXCLUDED_PRODUCTS.includes(productCode)) {
let catalogueAllPrice = parseFloat($(this).find('.catalogueAllPrice').val()) || 0;
total += catalogueAllPrice;
}
});
// // 计算终端产品表格productTable2
// $('#productTable2 tbody tr').each(function () {
// let productCode = $(this).find('.productBomCode').val();
// // 排除固定产品
// if (!EXCLUDED_PRODUCTS.includes(productCode)) {
// let catalogueAllPrice = parseFloat($(this).find('.catalogueAllPrice').val()) || 0;
// total += catalogueAllPrice;
// }
// });
return total;
}
@ -584,21 +586,21 @@
}
setOrderPriceData()
})
$('.productTable .catalogue-price-format').on('input', function () {
$('.productTable .catalogue-price-format').on('change', function () {
let val = $(this).val()
$(this).parent().parent().find('.cataloguePrice').val(val)
let quantity = $(this).parent().parent().find('.quantity').val()
// let discount=$(this).parent().parent().find('.discount').val()
// if (discount && val){
// $(this).parent().parent().find('.price').val((val * discount).toFixed(2))
// let price = $(this).parent().parent().find('.price').val()
// $(this).parent().parent().find('.price-formmat').val(formatAmountNumber(price))
// if (quantity){
// $(this).parent().parent().find('.allPrice').val((quantity * val * discount).toFixed(2))
// let allPrice = $(this).parent().parent().find('.allPrice').val()
// $(this).parent().parent().find('.allPrice-formmat').val(formatAmountNumber(allPrice))
// }
// }
let discount=$(this).parent().parent().find('.discount').val()
if (discount && val){
$(this).parent().parent().find('.price').val((val * discount).toFixed(2))
let price = $(this).parent().parent().find('.price').val()
$(this).parent().parent().find('.price-formmat').val(formatAmountNumber(price))
if (quantity){
$(this).parent().parent().find('.allPrice').val((quantity * val * discount).toFixed(2))
let allPrice = $(this).parent().parent().find('.allPrice').val()
$(this).parent().parent().find('.allPrice-formmat').val(formatAmountNumber(allPrice))
}
}
if (quantity && val) {
$(this).parent().parent().find('.catalogueAllPrice').val((val * quantity).toFixed(2))
$(this).parent().parent().find('.catalogueAllPrice-formmat').val(formatAmountNumber((val * quantity).toFixed(2)))