liu
2026-10-26 4a55db3ee9932c641a0895deddb4ee3b0b47ad20
fix(erp): 新增采购申请实时计算税额
已修改4个文件
41 ■■■■■ 文件已修改
src/api/erp/purchase/request/index.ts 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/purchase/request/data.ts 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/purchase/request/modules/form.vue 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/erp/purchase/request/modules/item-form.vue 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/erp/purchase/request/index.ts
@@ -45,7 +45,10 @@
    productBarCode?: string; // 产品条码
    productPrice?: number; // 产品单价(参考价)
    count: number; // 数量
    totalPrice?: number; // 明细未税金额
    taxPercent?: number; // 税率
    taxPrice?: number; // 税额(单价 × 数量 × 税率 ÷ 100)
    qcCheckFlag?: boolean; // 是否质检
    demandTime?: string; // 需求日期
    remark?: string; // 备注
  }
src/views/erp/purchase/request/data.ts
@@ -97,6 +97,7 @@
      fieldName: 'totalTaxPrice',
      label: '税额',
      component: 'InputNumber',
      help: '计算规则:税额合计 = Σ(单价 × 数量 × 税率 ÷ 100)。单价按未税价计算,每条明细四舍五入保留2位。',
      componentProps: {
        placeholder: '根据明细税率自动计算',
        min: 0,
@@ -193,7 +194,7 @@
      formatter: 'formatAmount2',
    },
    {
      field: 'totalTaxPrice',
      field: 'taxPrice',
      title: '税额',
      formatter: 'formatAmount2',
      minWidth: 120,
src/views/erp/purchase/request/modules/form.vue
@@ -52,8 +52,13 @@
function handleUpdateItems(items: ErpPurchaseRequestApi.PurchaseRequestItem[]) {
  formData.value = modalApi.getData<ErpPurchaseRequestApi.PurchaseRequest>();
  formData.value.items = items;
  const totalTaxPrice = items.reduce(
    (sum, item) => sum + (item.taxPrice || 0),
    0,
  );
  formApi.setValues({
    items,
    totalTaxPrice,
  });
}
@@ -111,9 +116,10 @@
      formData.value = {
        requestTime: '',
        depositPrice: 0,
        totalTaxPrice: 0,
        items: [],
      };
      await formApi.setFieldValue('depositPrice', 0);
      await formApi.setValues({ depositPrice: 0, totalTaxPrice: 0 });
      return;
    }
    modalApi.lock();
src/views/erp/purchase/request/modules/item-form.vue
@@ -41,6 +41,10 @@
      },
      0,
    ),
    taxPrice: tableData.value.reduce(
      (sum, item) => sum + (item.taxPrice || 0),
      0,
    ),
  };
});
@@ -93,6 +97,7 @@
    count: 1,
    productPrice: undefined,
    taxPercent: undefined,
    taxPrice: 0,
    demandTime: undefined,
    remark: undefined,
    totalPrice: 0,
@@ -128,24 +133,31 @@
/** 处理行数据变更 */
function handleRowChange(row: any) {
  calculateRowAmount(row);
  const index = tableData.value.findIndex((item) => item.seq === row.seq);
  if (index === -1) {
    tableData.value.push(row);
  } else {
    tableData.value[index] = row;
  }
  // 计算预估金额
  if (row.productPrice && row.count) {
    row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
  }
  emit('update:items', [...tableData.value]);
}
/** 按未税价计算:税额 = 单价 × 数量 × 税率 ÷ 100 */
function calculateRowAmount(row: ErpPurchaseRequestApi.PurchaseRequestItem) {
  row.totalPrice = erpPriceMultiply(
    row.productPrice || 0,
    row.count || 0,
  ) ?? 0;
  row.taxPrice = erpPriceMultiply(
    row.totalPrice,
    (row.taxPercent || 0) / 100,
  ) ?? 0;
}
/** 初始化行数据 */
function initRow(row: ErpPurchaseRequestApi.PurchaseRequestItem) {
  if (row.productPrice && row.count) {
    row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0;
  }
  calculateRowAmount(row);
}
/** 表单校验 */
@@ -265,6 +277,7 @@
          <div class="flex space-x-4">
            <span>数量:{{ erpCountInputFormatter(summaries.count) }}</span>
            <span>预估金额:{{ erpPriceInputFormatter(summaries.totalPrice) }}</span>
            <span>税额:{{ erpPriceInputFormatter(summaries.taxPrice) }}</span>
          </div>
        </div>
      </div>