tuqin
6 天以前 949d344cd69a74d93141ffe74fecc05c0f4f5d8a
fix(crm): 修正商机「整单折扣」算法错误

问题:产品总金额 1000、整单折扣填 98 时,折扣后金额显示 20。
原逻辑先算出 1000×98% = 980(这已是折后价),又执行 1000-980 = 20,
把折后价当成折扣额减了第二次。

修正(form.vue / data.ts 两处保持一致):
- 折扣率语义统一为「填 98 表示按 98% 计价」,折后金额 = 总价 × 折扣率 / 100
- 折扣为空或 0 时按「不打折」处理,避免默认值 0 把金额算成 0

验证:1000 填 98 → 980;1000 填 100 → 1000;1000 不填 → 1000
已修改2个文件
29 ■■■■■ 文件已修改
src/views/crm/business/data.ts 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/crm/business/modules/form.vue 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/crm/business/data.ts
@@ -151,15 +151,15 @@
      dependencies: {
        triggerFields: ['totalProductPrice', 'discountPercent'],
        trigger(values, form) {
          const discountPrice =
            erpPriceMultiply(
              values.totalProductPrice,
              values.discountPercent / 100,
            ) ?? 0;
          form.setFieldValue(
            'totalPrice',
            values.totalProductPrice - discountPrice,
          );
          const totalProductPrice = values.totalProductPrice ?? 0;
          const discountPercent = values.discountPercent;
          // 与 form.vue 保持一致:98 表示 98 折;为空或 0 视为不打折
          const totalPrice =
            !discountPercent || discountPercent === 0
              ? totalProductPrice
              : (erpPriceMultiply(totalProductPrice, discountPercent / 100) ??
                0);
          form.setFieldValue('totalPrice', totalPrice);
        },
      },
    },
src/views/crm/business/modules/form.vue
@@ -38,11 +38,12 @@
        0,
      ) ?? 0;
    const discountPercent = formData.value.discountPercent;
    const discountPrice =
      discountPercent === null
        ? 0
        : erpPriceMultiply(totalProductPrice, discountPercent / 100);
    const totalPrice = totalProductPrice - (discountPrice ?? 0);
    // 折扣率语义:填 98 表示按 98% 计价(即 98 折)。
    // 为空或 0 时视作不打折,避免默认值 0 把金额算成 0。
    const totalPrice =
      !discountPercent || discountPercent === 0
        ? totalProductPrice
        : (erpPriceMultiply(totalProductPrice, discountPercent / 100) ?? 0);
    formData.value!.totalProductPrice = totalProductPrice;
    formData.value!.totalPrice = totalPrice;
    formApi.setValues(formData.value!);