yuan
5 天以前 2a8dc0db849bcafba80acda057bb554fc566dc53
fix: 优化采购和销售金额展示
已修改3个文件
356 ■■■■■ 文件已修改
src/utils/formatNumber.js 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/procurementLedger/index.vue 153 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/index.vue 184 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/formatNumber.js
@@ -73,3 +73,22 @@
  // 避免出现 "-0.00" 这类负零显示
  return parseFloat(text) === 0 ? text.replace(/^-/, "") : text;
};
/**
 * 最多保留 6 位小数:超过 6 位的按十进制四舍五入,再去掉末尾多余的 0
 * 用于采购/销售台账的金额、数量、单价等字段
 * 例:52333.580000 -> 52333.58 ;1.23456789 -> 1.234568 ;0.1 + 0.2 -> 0.3
 * @param {string|number} value 原始值
 * @returns {string} 格式化后的字符串
 */
export const formatDecimal6 = (value) => {
  if (value === undefined || value === null || value === "") {
    return "0";
  }
  const num = typeof value === "number" ? value : Number(value);
  // 非数字(如 "-"、"--")原样返回,避免把占位符显示成 0
  if (!Number.isFinite(num)) {
    return String(value);
  }
  return trimZeros(roundHalfUp(num, 6), 6);
};
src/views/procurementManagement/procurementLedger/index.vue
@@ -121,13 +121,17 @@
                </template>
              </el-table-column>
              <el-table-column label="数量"
                               prop="quantity" />
                               prop="quantity"
                               :formatter="formattedNumber" />
              <el-table-column label="可用数量"
                               prop="availableQuality" />
                               prop="availableQuality"
                               :formatter="formattedNumber" />
              <el-table-column label="退货数量"
                               prop="returnQuantity" />
                               prop="returnQuantity"
                               :formatter="formattedNumber" />
              <el-table-column label="税率(%)"
                               prop="taxRate" />
                               prop="taxRate"
                               :formatter="formattedNumber" />
              <el-table-column label="含税单价(元)"
                               prop="taxInclusiveUnitPrice"
                               :formatter="formattedNumber" />
@@ -418,11 +422,13 @@
                           width="70" />
          <el-table-column label="数量"
                           prop="quantity"
                           width="70" />
                           width="70"
                           :formatter="formattedNumber" />
          <el-table-column label="库存预警数量"
                           prop="warnNum"
                           width="120"
                           show-overflow-tooltip />
                           show-overflow-tooltip
                           :formatter="formattedNumber" />
          <el-table-column label="税率(%)"
                           prop="taxRate"
                           width="80" />
@@ -599,7 +605,6 @@
            <el-form-item label="含税单价(元):"
                          prop="taxInclusiveUnitPrice">
              <el-input-number v-model="productForm.taxInclusiveUnitPrice"
                               :precision="6"
                               :step="0.1"
                               :min="0"
                               clearable
@@ -612,7 +617,6 @@
                          prop="quantity">
              <el-input-number :step="0.1"
                               clearable
                               :precision="6"
                               :min="0"
                               style="width: 100%"
                               v-model="productForm.quantity"
@@ -626,7 +630,6 @@
            <el-form-item label="含税总价(元):"
                          prop="taxInclusiveTotalPrice">
              <el-input-number v-model="productForm.taxInclusiveTotalPrice"
                               :precision="6"
                               :step="0.1"
                               :min="0"
                               clearable
@@ -638,7 +641,6 @@
            <el-form-item label="不含税总价(元):"
                          prop="taxExclusiveTotalPrice">
              <el-input-number v-model="productForm.taxExclusiveTotalPrice"
                               :precision="6"
                               :step="0.1"
                               :min="0"
                               clearable
@@ -665,11 +667,11 @@
            <el-form-item label="库存预警数量:"
                          prop="warnNum">
              <el-input-number v-model="productForm.warnNum"
                               :precision="6"
                               :step="0.1"
                               :min="0"
                               clearable
                               style="width: 100%" />
                               style="width: 100%"
                               @change="normalizeProductNumber('warnNum')" />
            </el-form-item>
          </el-col>
        </el-row>
@@ -761,7 +763,7 @@
  import { modelList, productTreeList } from "@/api/basicData/product.js";
  import dayjs from "dayjs";
  import FileUpload from "@/components/AttachmentUpload/file/index.vue";
  import { roundHalfUp, trimZeros } from "@/utils/formatNumber.js";
  import { formatDecimal6 } from "@/utils/formatNumber.js";
  const userStore = useUserStore();
@@ -1086,15 +1088,11 @@
  };
  const formattedNumber = (row, column, cellValue) => {
    return trimZeros(cellValue, 6);
    return formatDecimal6(cellValue);
  };
  // 金额显示格式化:按十进制四舍五入到 2 位小数(与数据库 ROUND 一致),再去掉末尾多余的 0
  const formatAmount = value => {
    return trimZeros(roundHalfUp(value, 2), 2);
  };
  // 金额列的表格格式化函数(单价列仍用 formattedNumber 保留 6 位小数)
  // 金额显示格式化:最多保留 6 位小数,超过 6 位的按十进制四舍五入
  const formattedAmount = (row, column, cellValue) => {
    return formatAmount(cellValue);
    return formatDecimal6(cellValue);
  };
  // 查询列表
  /** 搜索按钮操作 */
@@ -1214,10 +1212,10 @@
        "futureTicketsAmount",
      ],
      {
        taxInclusiveUnitPrice: { decimalPlaces: 6, trimZeros: true },
        // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致
        taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        taxInclusiveUnitPrice: { formatter: formatDecimal6 },
        // 金额列:合计后最多保留 6 位小数,超过 6 位按十进制四舍五入
        taxInclusiveTotalPrice: { formatter: formatDecimal6 },
        taxExclusiveTotalPrice: { formatter: formatDecimal6 },
        ticketsAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        futureTicketsAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        ticketsNum: { noDecimal: true }, // 不保留小数
@@ -1289,9 +1287,9 @@
      param,
      ["contractAmount", "netContractAmount"],
      {
        // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致
        contractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        netContractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        // 金额列:合计后最多保留 6 位小数,超过 6 位按十进制四舍五入
        contractAmount: { formatter: formatDecimal6 },
        netContractAmount: { formatter: formatDecimal6 },
      }
    );
  };
@@ -1305,10 +1303,10 @@
        "taxExclusiveTotalPrice",
      ],
      {
        taxInclusiveUnitPrice: { decimalPlaces: 6, trimZeros: true },
        // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致
        taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
        taxInclusiveUnitPrice: { formatter: formatDecimal6 },
        // 金额列:合计后最多保留 6 位小数,超过 6 位按十进制四舍五入
        taxInclusiveTotalPrice: { formatter: formatDecimal6 },
        taxExclusiveTotalPrice: { formatter: formatDecimal6 },
      }
    );
  };
@@ -1517,6 +1515,20 @@
      // 复制行数据
      productForm.value = { ...row };
      // 后端数量/金额字段按 6 位小数返回(如 10.000000),转成普通数值,
      // 避免输入框回显多余的 0
      [
        "quantity",
        "taxInclusiveUnitPrice",
        "taxInclusiveTotalPrice",
        "taxExclusiveTotalPrice",
        "warnNum",
      ].forEach(key => {
        const val = productForm.value[key];
        if (val === null || val === undefined || val === "") return;
        productForm.value[key] = toDisplayNumber(val);
      });
      // 如果是从模板加载的数据,可能没有 productId 和 productModelId
      // 需要根据 productCategory 和 specificationModel 来查找对应的 ID
      if (!productForm.value.productId && productForm.value.productCategory) {
@@ -1645,6 +1657,8 @@
  const submitProduct = () => {
    proxy.$refs["productFormRef"].validate(valid => {
      if (valid) {
        // 提交前统一把数值收敛到最多 6 位小数(超出四舍五入)
        normalizeProductNumbers();
        if (operationType.value === "edit") {
          submitProductEdit();
        } else {
@@ -1803,7 +1817,33 @@
    return `${year}-${month}-${day}`;
  }
  // 计算结果转成数字:最多保留 6 位小数(超过 6 位的四舍五入),并去掉末尾无意义的 0,
  // 避免回填到 el-input-number 时出现 100.000000 这类展示
  const toDisplayNumber = value => {
    const num = Number(formatDecimal6(value));
    return Number.isFinite(num) ? num : 0;
  };
  // 产品弹窗单个数值字段归一化:输入超过 6 位小数时四舍五入到 6 位
  const normalizeProductNumber = key => {
    const val = productForm.value[key];
    if (val === null || val === undefined || val === "") return;
    productForm.value[key] = toDisplayNumber(val);
  };
  // 产品弹窗参与联动计算的数值字段统一归一化
  const normalizeProductNumbers = () => {
    [
      "quantity",
      "taxInclusiveUnitPrice",
      "taxInclusiveTotalPrice",
      "taxExclusiveTotalPrice",
      "warnNum",
    ].forEach(normalizeProductNumber);
  };
  const mathNum = () => {
    normalizeProductNumbers();
    if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
@@ -1815,23 +1855,26 @@
      return;
    }
    // 含税总价计算
    productForm.value.taxInclusiveTotalPrice =
    productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
      proxy.calculateTaxIncludeTotalPrice(
        productForm.value.taxInclusiveUnitPrice,
        productForm.value.quantity,
        6
      )
      );
    if (productForm.value.taxRate) {
      // 不含税总价计算
      productForm.value.taxExclusiveTotalPrice =
      productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
        proxy.calculateTaxExclusiveTotalPrice(
          productForm.value.taxInclusiveTotalPrice,
          productForm.value.taxRate,
          6
        )
        );
    }
  };
  const reverseMathNum = field => {
    normalizeProductNumbers();
    if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
@@ -1846,7 +1889,7 @@
    ) {
      const value = Number(productForm.value[field]);
      if (value < 0) {
        productForm.value[field] = "0";
        productForm.value[field] = 0;
        proxy.$modal.msgWarning("值不能小于0");
        return;
      }
@@ -1855,65 +1898,63 @@
    if (field === "taxInclusiveTotalPrice") {
      // 已知含税总价和数量,反算含税单价
      if (productForm.value.quantity) {
        productForm.value.taxInclusiveUnitPrice = (
        productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
          Number(productForm.value.taxInclusiveTotalPrice) /
          Number(productForm.value.quantity)
        ).toFixed(6);
        );
        // 确保结果不为负数
        if (Number(productForm.value.taxInclusiveUnitPrice) < 0) {
          productForm.value.taxInclusiveUnitPrice = "0";
          productForm.value.taxInclusiveUnitPrice = 0;
        }
      }
      // 已知含税总价和含税单价,反算数量
      else if (productForm.value.taxInclusiveUnitPrice) {
        productForm.value.quantity = (
        productForm.value.quantity = toDisplayNumber(
          Number(productForm.value.taxInclusiveTotalPrice) /
          Number(productForm.value.taxInclusiveUnitPrice)
        ).toFixed(6);
        );
        // 确保结果不为负数
        if (Number(productForm.value.quantity) < 0) {
          productForm.value.quantity = "0";
          productForm.value.quantity = 0;
        }
      }
      // 反算不含税总价
      productForm.value.taxExclusiveTotalPrice = (
        Number(productForm.value.taxInclusiveTotalPrice) /
        (1 + taxRate / 100)
      ).toFixed(6);
      productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
        Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100)
      );
      // 确保结果不为负数
      if (Number(productForm.value.taxExclusiveTotalPrice) < 0) {
        productForm.value.taxExclusiveTotalPrice = "0";
        productForm.value.taxExclusiveTotalPrice = 0;
      }
    } else if (field === "taxExclusiveTotalPrice") {
      // 反算含税总价
      productForm.value.taxInclusiveTotalPrice = (
        Number(productForm.value.taxExclusiveTotalPrice) *
        (1 + taxRate / 100)
      ).toFixed(6);
      productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
        Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100)
      );
      // 确保结果不为负数
      if (Number(productForm.value.taxInclusiveTotalPrice) < 0) {
        productForm.value.taxInclusiveTotalPrice = "0";
        productForm.value.taxInclusiveTotalPrice = 0;
      }
      // 已知数量,反算含税单价
      if (productForm.value.quantity) {
        productForm.value.taxInclusiveUnitPrice = (
        productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
          Number(productForm.value.taxInclusiveTotalPrice) /
          Number(productForm.value.quantity)
        ).toFixed(6);
        );
        // 确保结果不为负数
        if (Number(productForm.value.taxInclusiveUnitPrice) < 0) {
          productForm.value.taxInclusiveUnitPrice = "0";
          productForm.value.taxInclusiveUnitPrice = 0;
        }
      }
      // 已知含税单价,反算数量
      else if (productForm.value.taxInclusiveUnitPrice) {
        productForm.value.quantity = (
        productForm.value.quantity = toDisplayNumber(
          Number(productForm.value.taxInclusiveTotalPrice) /
          Number(productForm.value.taxInclusiveUnitPrice)
        ).toFixed(6);
        );
        // 确保结果不为负数
        if (Number(productForm.value.quantity) < 0) {
          productForm.value.quantity = "0";
          productForm.value.quantity = 0;
        }
      }
    }
src/views/salesManagement/salesLedger/index.vue
@@ -117,7 +117,7 @@
              </el-table-column>
              <el-table-column label="审批中数量" width="120" align="center">
                <template #default="scope">
                  <span>{{ scope.row.pendingApprovalQuantity || 0 }}</span>
                  <span>{{ formatDecimal6(scope.row.pendingApprovalQuantity) }}</span>
                </template>
              </el-table-column>
              <el-table-column
@@ -150,9 +150,17 @@
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="数量" prop="quantity" />
              <el-table-column label="待发货数量" prop="noQuantity" />
              <el-table-column label="税率(%)" prop="taxRate" />
              <el-table-column
                label="数量"
                prop="quantity"
                :formatter="formattedNumber"
              />
              <el-table-column label="待发货数量"
                               prop="noQuantity"
                               :formatter="formattedNumber" />
              <el-table-column label="税率(%)"
                               prop="taxRate"
                               :formatter="formattedNumber" />
              <el-table-column
                label="含税单价(元)"
                prop="taxInclusiveUnitPrice"
@@ -161,12 +169,12 @@
              <el-table-column
                label="含税总价(元)"
                prop="taxInclusiveTotalPrice"
                :formatter="formattedAmount"
                :formatter="formattedRawAmount"
              />
              <el-table-column
                label="不含税总价(元)"
                prop="taxExclusiveTotalPrice"
                :formatter="formattedAmount"
                :formatter="formattedRawAmount"
              />
              <!--操作-->
              <el-table-column Width="60px" label="操作" align="center">
@@ -219,7 +227,7 @@
          prop="contractAmount"
          width="220"
          show-overflow-tooltip
          :formatter="formattedAmount"
          :formatter="formattedRawAmount"
        />
        <el-table-column
          label="录入人"
@@ -513,7 +521,11 @@
          <el-table-column label="产品大类" prop="productCategory" />
          <el-table-column label="规格型号" prop="specificationModel" />
          <el-table-column label="单位" prop="unit" />
          <el-table-column label="数量" prop="quantity" />
          <el-table-column
            label="数量"
            prop="quantity"
            :formatter="formattedNumber"
          />
          <el-table-column label="税率(%)" prop="taxRate" />
          <el-table-column
            label="含税单价(元)"
@@ -523,12 +535,12 @@
          <el-table-column
            label="含税总价(元)"
            prop="taxInclusiveTotalPrice"
            :formatter="formattedAmount"
            :formatter="formattedRawAmount"
          />
          <el-table-column
            label="不含税总价(元)"
            prop="taxExclusiveTotalPrice"
            :formatter="formattedAmount"
            :formatter="formattedRawAmount"
          />
          <el-table-column label="是否生产" prop="isProduction" width="150">
            <template #default="scope">
@@ -766,7 +778,6 @@
                :min="0"
                v-model="productForm.taxInclusiveUnitPrice"
                style="width: 100%"
                :precision="6"
                placeholder="请输入"
                clearable
                @change="calculateFromUnitPrice"
@@ -781,7 +792,6 @@
                v-model="productForm.quantity"
                placeholder="请输入"
                clearable
                :precision="6"
                @change="calculateFromQuantity"
                style="width: 100%"
              />
@@ -959,10 +969,10 @@
                      <td>{{ product.productCategory || "" }}</td>
                      <td>{{ product.specificationModel || "" }}</td>
                      <td>{{ product.unit || "" }}</td>
                      <td>{{ trimZeros(product.taxInclusiveUnitPrice, 6) }}</td>
                      <td>{{ trimZeros(product.quantity, 6) }}</td>
                      <td>{{ formatDecimal6(product.taxInclusiveUnitPrice) }}</td>
                      <td>{{ formatDecimal6(product.quantity) }}</td>
                      <td>
                        {{ formatAmount(product.taxInclusiveTotalPrice) }}
                        {{ formatDecimal6(product.taxInclusiveTotalPrice) }}
                      </td>
                    </tr>
                    <tr v-if="!item.products || item.products.length === 0">
@@ -1051,7 +1061,7 @@
          <el-col :span="24">
            <el-form-item label="待发货数量:">
              <el-input
                :model-value="currentDeliveryRow?.noQuantity"
                :model-value="formatDecimal6(currentDeliveryRow?.noQuantity)"
                disabled
              />
            </el-form-item>
@@ -1123,7 +1133,7 @@
                  align="center"
                >
                  <template #default="scope">
                    {{ getDeliveryBatchQuantity(scope.row) }}
                    {{ formatDecimal6(getDeliveryBatchQuantity(scope.row)) }}
                  </template>
                </el-table-column>
                <el-table-column
@@ -1190,7 +1200,7 @@
import FileUpload from "@/components/AttachmentUpload/file/index.vue";
import ImageUpload from "@/components/AttachmentUpload/image/index.vue";
import { getCurrentDate } from "@/utils/index.js";
import { roundHalfUp, trimZeros } from "@/utils/formatNumber.js";
import { formatDecimal6, roundHalfUp } from "@/utils/formatNumber.js";
import { listCustomer } from "@/api/basicData/customer.js";
const FileList = defineAsyncComponent(() =>
@@ -1534,15 +1544,35 @@
  });
};
const formattedNumber = (row, column, cellValue) => {
  return trimZeros(cellValue, 6);
  return formatDecimal6(cellValue);
};
// 金额显示格式化:按十进制四舍五入到 2 位小数(与数据库 ROUND 一致),再去掉末尾多余的 0
// 报价金额显示:按十进制四舍五入到 2 位小数(与数据库 ROUND 一致),再去掉末尾多余的 0
const formatAmount = (value) => {
  return trimZeros(roundHalfUp(value, 2), 2);
  return formatDecimal6(roundHalfUp(value, 2));
};
// 金额列的表格格式化函数(单价列仍用 formattedNumber 保留 6 位小数)
const formattedAmount = (row, column, cellValue) => {
  return formatAmount(cellValue);
// 金额列显示:最多保留 6 位小数,超过 6 位的按十进制四舍五入
const formattedRawAmount = (row, column, cellValue) => {
  return formatDecimal6(cellValue);
};
// 把金额计算结果转成「输入几位就几位」的数字(最多 6 位小数,超出四舍五入)
const toDisplayNumber = (value) => {
  const num = Number(formatDecimal6(value));
  return Number.isFinite(num) ? num : 0;
};
// 产品弹窗单个数值字段归一化:输入超过 6 位小数时四舍五入到 6 位
const normalizeProductNumber = (key) => {
  const val = productForm.value[key];
  if (val === null || val === undefined || val === "") return;
  productForm.value[key] = toDisplayNumber(val);
};
// 产品弹窗参与联动计算的数值字段统一归一化
const normalizeProductNumbers = () => {
  [
    "quantity",
    "taxInclusiveUnitPrice",
    "taxInclusiveTotalPrice",
    "taxExclusiveTotalPrice",
  ].forEach(normalizeProductNumber);
};
const findLedgerRecordByRow = (row) => {
  if (!row) return null;
@@ -1702,10 +1732,10 @@
    param,
    ["contractAmount", "taxInclusiveTotalPrice", "taxExclusiveTotalPrice"],
    {
      // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致
      contractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
      taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
      taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
      // 金额列合计后最多保留 6 位小数,超过 6 位按十进制四舍五入
      contractAmount: { formatter: formatDecimal6 },
      taxInclusiveTotalPrice: { formatter: formatDecimal6 },
      taxExclusiveTotalPrice: { formatter: formatDecimal6 },
    }
  );
};
@@ -1719,10 +1749,10 @@
      "taxExclusiveTotalPrice",
    ],
    {
      taxInclusiveUnitPrice: { decimalPlaces: 6, trimZeros: true },
      // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致
      taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
      taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
      taxInclusiveUnitPrice: { formatter: formatDecimal6 },
      // 金额列合计后最多保留 6 位小数,超过 6 位按十进制四舍五入
      taxInclusiveTotalPrice: { formatter: formatDecimal6 },
      taxExclusiveTotalPrice: { formatter: formatDecimal6 },
    }
  );
};
@@ -1875,11 +1905,9 @@
    const quantity = Number(p.quantity ?? 0) || 0;
    const unitPrice = Number(p.unitPrice ?? 0) || 0;
    const taxRate = "13"; // 默认 13%,便于直接提交(如需可在产品中自行修改)
    const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6);
    const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(
      taxInclusiveTotalPrice,
      taxRate,
      6
    const taxInclusiveTotalPrice = toDisplayNumber(unitPrice * quantity);
    const taxExclusiveTotalPrice = toDisplayNumber(
      proxy.calculateTaxExclusiveTotalPrice(taxInclusiveTotalPrice, taxRate, 6)
    );
    return {
      // 台账字段
@@ -1888,7 +1916,7 @@
      unit: p.unit || "",
      quantity: quantity,
      taxRate: taxRate,
      taxInclusiveUnitPrice: unitPrice.toFixed(6),
      taxInclusiveUnitPrice: toDisplayNumber(unitPrice),
      taxInclusiveTotalPrice: taxInclusiveTotalPrice,
      taxExclusiveTotalPrice: taxExclusiveTotalPrice,
      invoiceType: "增普票",
@@ -1953,6 +1981,17 @@
  proxy.resetForm("productFormRef");
  if (type === "edit") {
    productForm.value = { ...row };
    // 回填时把金额/数量统一成数字,避免 "5000.000000" 这类补零字符串直接进输入框
    [
      "quantity",
      "taxInclusiveUnitPrice",
      "taxInclusiveTotalPrice",
      "taxExclusiveTotalPrice",
    ].forEach((key) => {
      const val = productForm.value[key];
      if (val === null || val === undefined || val === "") return;
      productForm.value[key] = toDisplayNumber(val);
    });
    productIndex.value = index;
    // 编辑时根据产品大类名称反查 tree 节点 id,并加载规格型号列表
    try {
@@ -1988,6 +2027,8 @@
const submitProduct = () => {
  proxy.$refs["productFormRef"].validate((valid) => {
    if (valid) {
      // 提交前统一把数值收敛到最多 6 位小数(超出四舍五入)
      normalizeProductNumbers();
      if (operationType.value === "edit") {
        submitProductEdit();
      } else {
@@ -2454,16 +2495,19 @@
                                                                                                      ""
                                                                                                    }</td>
                                                                                                    <td>${
                                                                                                      product.taxInclusiveUnitPrice ||
                                                                                                      "0"
                                                                                                      formatDecimal6(
                                                                                                        product.taxInclusiveUnitPrice
                                                                                                      )
                                                                                                    }</td>
                                                                                                    <td>${
                                                                                                      product.quantity ||
                                                                                                      "0"
                                                                                                      formatDecimal6(
                                                                                                        product.quantity
                                                                                                      )
                                                                                                    }</td>
                                                                                                    <td>${
                                                                                                      product.taxInclusiveTotalPrice ||
                                                                                                      "0"
                                                                                                      formatDecimal6(
                                                                                                        product.taxInclusiveTotalPrice
                                                                                                      )
                                                                                                    }</td>
                                                                                                  </tr>
                                                                                                `
@@ -2566,7 +2610,7 @@
  const total = products.reduce((sum, product) => {
    return sum + (parseFloat(product.quantity) || 0);
  }, 0);
  return trimZeros(total, 6);
  return formatDecimal6(total);
};
// 计算产品总金额
@@ -2575,7 +2619,7 @@
  const total = products.reduce((sum, product) => {
    return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
  }, 0);
  return formatAmount(total);
  return formatDecimal6(total);
};
// 用于打印的计算函数
@@ -2584,7 +2628,7 @@
  const total = products.reduce((sum, product) => {
    return sum + (parseFloat(product.quantity) || 0);
  }, 0);
  return trimZeros(total, 6);
  return formatDecimal6(total);
};
const getTotalAmountForPrint = (products) => {
@@ -2592,11 +2636,12 @@
  const total = products.reduce((sum, product) => {
    return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
  }, 0);
  return formatAmount(total);
  return formatDecimal6(total);
};
const mathNum = () => {
  console.log("productForm.value", productForm.value);
  normalizeProductNumbers();
  if (!productForm.value.taxInclusiveUnitPrice) {
    return;
  }
@@ -2604,25 +2649,28 @@
    return;
  }
  // 含税总价计算
  productForm.value.taxInclusiveTotalPrice =
  productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
    proxy.calculateTaxIncludeTotalPrice(
      productForm.value.taxInclusiveUnitPrice,
      productForm.value.quantity,
      6
    )
    );
  if (productForm.value.taxRate) {
    // 不含税总价计算
    productForm.value.taxExclusiveTotalPrice =
    productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
      proxy.calculateTaxExclusiveTotalPrice(
        productForm.value.taxInclusiveTotalPrice,
        productForm.value.taxRate,
        6
      )
      );
  }
};
// 根据含税总价计算含税单价和数量
const calculateFromTotalPrice = () => {
  normalizeProductNumbers();
  if (isCalculating.value) return;
  const totalPrice = parseFloat(productForm.value.taxInclusiveTotalPrice);
@@ -2635,15 +2683,18 @@
  isCalculating.value = true;
  // 计算含税单价 = 含税总价 / 数量
  productForm.value.taxInclusiveUnitPrice = (totalPrice / quantity).toFixed(6);
  productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
    totalPrice / quantity
  );
  // 如果有税率,计算不含税总价
  if (productForm.value.taxRate) {
    productForm.value.taxExclusiveTotalPrice =
    productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
      proxy.calculateTaxExclusiveTotalPrice(
        totalPrice,
        productForm.value.taxRate,
        6
      )
      );
  }
@@ -2652,6 +2703,7 @@
// 根据不含税总价计算含税单价和数量
const calculateFromExclusiveTotalPrice = () => {
  normalizeProductNumbers();
  if (!productForm.value.taxRate) {
    proxy.$modal.msgWarning("请先选择税率");
    return;
@@ -2673,18 +2725,19 @@
  // 先计算含税总价 = 不含税总价 / (1 - 税率/100)
  const taxRateDecimal = taxRate / 100;
  const inclusiveTotalPrice = exclusiveTotalPrice / (1 - taxRateDecimal);
  productForm.value.taxInclusiveTotalPrice = inclusiveTotalPrice.toFixed(6);
  productForm.value.taxInclusiveTotalPrice = toDisplayNumber(inclusiveTotalPrice);
  // 计算含税单价 = 含税总价 / 数量
  productForm.value.taxInclusiveUnitPrice = (
  productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
    inclusiveTotalPrice / quantity
  ).toFixed(6);
  );
  isCalculating.value = false;
};
// 根据数量变化计算总价
const calculateFromQuantity = () => {
  normalizeProductNumbers();
  if (!productForm.value.taxRate) {
    proxy.$modal.msgWarning("请先选择税率");
    return;
@@ -2701,15 +2754,18 @@
  isCalculating.value = true;
  // 计算含税总价
  productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6);
  productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
    unitPrice * quantity
  );
  // 如果有税率,计算不含税总价
  if (productForm.value.taxRate) {
    productForm.value.taxExclusiveTotalPrice =
    productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
      proxy.calculateTaxExclusiveTotalPrice(
        productForm.value.taxInclusiveTotalPrice,
        productForm.value.taxRate,
        6
      )
      );
  }
@@ -2718,6 +2774,7 @@
// 根据含税单价变化计算总价
const calculateFromUnitPrice = () => {
  normalizeProductNumbers();
  if (!productForm.value.taxRate) {
    proxy.$modal.msgWarning("请先选择税率");
    return;
@@ -2734,15 +2791,18 @@
  isCalculating.value = true;
  // 计算含税总价
  productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6);
  productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
    unitPrice * quantity
  );
  // 如果有税率,计算不含税总价
  if (productForm.value.taxRate) {
    productForm.value.taxExclusiveTotalPrice =
    productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
      proxy.calculateTaxExclusiveTotalPrice(
        productForm.value.taxInclusiveTotalPrice,
        productForm.value.taxRate,
        6
      )
      );
  }
@@ -2751,6 +2811,7 @@
// 根据税率变化计算不含税总价
const calculateFromTaxRate = () => {
  normalizeProductNumbers();
  if (!productForm.value.taxRate) {
    proxy.$modal.msgWarning("请先选择税率");
    return;
@@ -2769,8 +2830,9 @@
  isCalculating.value = true;
  // 计算不含税总价
  productForm.value.taxExclusiveTotalPrice =
    proxy.calculateTaxExclusiveTotalPrice(inclusiveTotalPrice, taxRate, 6);
  productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
    proxy.calculateTaxExclusiveTotalPrice(inclusiveTotalPrice, taxRate, 6)
  );
  isCalculating.value = false;
};