From 5cff13e7871d26a80f430d890f18070c0d1b6665 Mon Sep 17 00:00:00 2001 From: zhangrenyuan <18990852002@163.com> Date: Thu, 16 Apr 2026 16:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E7=BB=A9=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../financialAccount/performanceAttribution.vue | 46 ++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/views/moneyManage/financialAccount/performanceAttribution.vue b/src/views/moneyManage/financialAccount/performanceAttribution.vue index 82bf1f0..9fe918a 100644 --- a/src/views/moneyManage/financialAccount/performanceAttribution.vue +++ b/src/views/moneyManage/financialAccount/performanceAttribution.vue @@ -3,6 +3,7 @@ import { ref, reactive, onMounted, toRefs, nextTick, computed, watch, onBeforeUn import { ElMessage, ElMessageBox } from 'element-plus' import request from '@/util/http.js' import dayjs from 'dayjs' +import Decimal from 'decimal.js' import { useI18n } from 'vue-i18n' import { refundOnline, performanceSelect, exportPerformance, adjustment } from '@/api/cash/financialAccount.js' import { getUserInfo } from '@/api/common/common.js' @@ -368,6 +369,32 @@ const matrixMarkets = computed(() => [ const adjustData = ref([]) +const isEmptyAdjustValue = (value) => { + return value === '' || value === undefined || value === null || value === '-' +} + +const toSafeDecimal = (value) => { + if (isEmptyAdjustValue(value)) { + return new Decimal(0) + } + + const normalized = formatNumber(value) + if (!normalized || normalized === '-' || normalized === '.' || normalized === '-.') { + return new Decimal(0) + } + + try { + return new Decimal(normalized) + } catch (error) { + return new Decimal(0) + } +} + +const formatDecimalValue = (value) => { + const decimalValue = Decimal.isDecimal(value) ? value : toSafeDecimal(value) + return decimalValue.toFixed().replace(/\.0+$/, '').replace(/(\.\d*?[1-9])0+$/, '$1') +} + const initAdjustData = () => { adjustData.value = matrixMarkets.value.map(rowMarket => { const row = { inMarket: rowMarket.label + t('common.customer') } @@ -390,12 +417,11 @@ const computedAdjustData = computed(() => { const sumRow = { inMarket: t('cash.cashFlow.total'), isSum: true } matrixMarkets.value.forEach(colMarket => { - let colSum = 0 + let colSum = new Decimal(0) adjustData.value.forEach(row => { - const val = parseFloat(row[colMarket.key]) - if (!isNaN(val)) colSum += val + colSum = colSum.plus(toSafeDecimal(row[colMarket.key])) }) - sumRow[colMarket.key] = colSum + sumRow[colMarket.key] = formatDecimalValue(colSum) }) data.push(sumRow) @@ -403,12 +429,11 @@ const computedAdjustData = computed(() => { }) const getRowTotal = (row) => { - let sum = 0 + let sum = new Decimal(0) matrixMarkets.value.forEach(colMarket => { - const val = parseFloat(row[colMarket.key]) - if (!isNaN(val)) sum += val + sum = sum.plus(toSafeDecimal(row[colMarket.key])) }) - return sum + return formatDecimalValue(sum) } const formatNumber = (val) => { @@ -434,15 +459,14 @@ const submitAdjustment = async () => { // 如果单元格为空或者非数字,默认为 0 const matrix = adjustData.value.map(row => { return matrixMarkets.value.map(colMarket => { - const val = parseFloat(row[colMarket.key]) - return isNaN(val) ? 0 : val + return toSafeDecimal(row[colMarket.key]).toNumber() }) }) // 构造最终提交的数据结构 const payload = { matrix: matrix, - weight: parseFloat(adjustCoefficient.value), // 系数 + weight: toSafeDecimal(adjustCoefficient.value).toNumber(), // 系数 time: adjustTime.value, submitterId: adminData.value.id || 1000063, // 从全局 adminData 获取 submitterMarket: adminData.value.marketName || '总部' // 如果为空默认传总部