gaoluyang
10 小时以前 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"
        />
@@ -273,14 +271,6 @@
                placeholder="请选择"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否开票" prop="isInvoice">
              <el-select v-model="form.isInvoice" placeholder="请选择" clearable>
                <el-option label="是" :value="1" />
                <el-option label="否" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
@@ -718,7 +708,6 @@
    supplierId: "",
    paymentMethod: "",
      executionDate: "",
    isInvoice: "",
  },
  rules: {
    purchaseContractNumber: [
@@ -728,7 +717,6 @@
    supplierId: [{ required: true, message: "请输入", trigger: "blur" }],
      entryDate: [{ required: true, message: "请选择", trigger: "change" }],
      executionDate: [{ required: true, message: "请选择", trigger: "change" }],
    isInvoice: [{ required: true, message: "请选择", trigger: "change" }],
  },
});
const {  form, rules } = toRefs(data);
@@ -1182,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("请先选择税率");
@@ -1199,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 =
@@ -1219,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) {
@@ -1232,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 =