gaoluyang
8 小时以前 170e43cd3509a33be7db74e5f3dbd7a71bd9ffd1
src/views/procurementManagement/procurementLedger/index.vue
@@ -103,7 +103,6 @@
        />
        <el-table-column
          label="供应商名称"
          width="240"
          prop="supplierName"
          show-overflow-tooltip
        />
@@ -116,7 +115,6 @@
        <el-table-column
          label="合同金额(元)"
          prop="contractAmount"
           width="200"
          show-overflow-tooltip
          :formatter="formattedNumber"
        />
@@ -1172,6 +1170,13 @@
  const day = String(today.getDate()).padStart(2, "0");
  return `${year}-${month}-${day}`;
}
// 税率可能为空:返回 number 或 null
const getTaxRateNumberOrNull = () => {
  const raw = productForm.value?.taxRate;
  if (raw === null || raw === undefined || raw === "") return null;
  const n = Number(raw);
  return Number.isFinite(n) ? n : null;
};
const mathNum = () => {
   // if (!productForm.value.taxRate) {
   //    proxy.$modal.msgWarning("请先选择税率");
@@ -1189,12 +1194,19 @@
      productForm.value.taxInclusiveUnitPrice,
      productForm.value.quantity
    );
    // 不含税总价计算
  // 不含税总价计算(税率可能为空)
  const taxRate = getTaxRateNumberOrNull();
  if (taxRate === null) {
    // 未填写税率时:按“含税/不含税一致”处理,避免出现 NaN
    productForm.value.taxExclusiveTotalPrice = productForm.value.taxInclusiveTotalPrice;
  } else {
    productForm.value.taxExclusiveTotalPrice =
      proxy.calculateTaxExclusiveTotalPrice(
        productForm.value.taxInclusiveTotalPrice,
        productForm.value.taxRate
        taxRate
      );
  }
  // if (productForm.value.taxRate) {
  //   // 不含税总价计算
  //   productForm.value.taxExclusiveTotalPrice =
@@ -1209,8 +1221,7 @@
   //    proxy.$modal.msgWarning("请先选择税率");
   //    return;
   // }
  const taxRate = productForm.value.taxRate?Number(productForm.value.taxRate):0;
  // if (!taxRate) return;
  const taxRate = getTaxRateNumberOrNull();
  if (field === 'taxInclusiveTotalPrice') {
    // 已知含税总价和数量,反算含税单价
    if (productForm.value.quantity) {
@@ -1222,13 +1233,21 @@
      productForm.value.quantity =
        (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice)).toFixed(2);
    }
    // 反算不含税总价
    productForm.value.taxExclusiveTotalPrice =
      (Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100)).toFixed(2);
    // 反算不含税总价(税率可能为空)
    if (taxRate === null) {
      productForm.value.taxExclusiveTotalPrice = productForm.value.taxInclusiveTotalPrice;
    } else {
      productForm.value.taxExclusiveTotalPrice =
        (Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100)).toFixed(2);
    }
  } else if (field === 'taxExclusiveTotalPrice') {
    // 反算含税总价
    productForm.value.taxInclusiveTotalPrice =
      (Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100)).toFixed(2);
    // 反算含税总价(税率可能为空)
    if (taxRate === null) {
      productForm.value.taxInclusiveTotalPrice = productForm.value.taxExclusiveTotalPrice;
    } else {
      productForm.value.taxInclusiveTotalPrice =
        (Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100)).toFixed(2);
    }
    // 已知数量,反算含税单价
    if (productForm.value.quantity) {
      productForm.value.taxInclusiveUnitPrice =