From 8eebc677808e5308693d97838c89b6dab28f8096 Mon Sep 17 00:00:00 2001 From: supergaojian <402853745@qq.com> Date: Tue, 4 Feb 2020 14:12:38 +0800 Subject: [PATCH] fix(amount): fix amount display negative number (#645) * fix(amount): fix amount display negative number fix #644 * fix(amount): change variable name fix #644 --- components/amount/demo/cases/demo1.vue | 6 ++++++ components/amount/index.vue | 11 +++++++++-- .../amount/test/__snapshots__/demo.spec.js.snap | 2 +- components/amount/test/cases/demo1.vue | 6 ++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/amount/demo/cases/demo1.vue b/components/amount/demo/cases/demo1.vue index d5d24cc55..98ac463d3 100644 --- a/components/amount/demo/cases/demo1.vue +++ b/components/amount/demo/cases/demo1.vue @@ -3,6 +3,12 @@ +
+ diff --git a/components/amount/index.vue b/components/amount/index.vue index 66ed17214..3340b4e26 100644 --- a/components/amount/index.vue +++ b/components/amount/index.vue @@ -24,10 +24,17 @@ export default { } const numberParts = value.split('.') - const integerValue = numberParts[0] + let integerValue = numberParts[0] const decimalValue = numberParts[1] || '' + + let sign = '' + if (integerValue.startsWith('-')) { + integerValue = integerValue.substring(1) + sign = '-' + } + const formateValue = formatValueByGapStep(3, integerValue, separator, 'right', 0, 1) - return decimalValue ? `${formateValue.value}.${decimalValue}` : `${formateValue.value}` + return decimalValue ? `${sign}${formateValue.value}.${decimalValue}` : `${sign}${formateValue.value}` }, doCapital(value) { return numberCapital(value) diff --git a/components/amount/test/__snapshots__/demo.spec.js.snap b/components/amount/test/__snapshots__/demo.spec.js.snap index f7c1bad5d..08662a805 100644 --- a/components/amount/test/__snapshots__/demo.spec.js.snap +++ b/components/amount/test/__snapshots__/demo.spec.js.snap @@ -10,6 +10,6 @@ exports[`Amount -Demo Basic 1`] = ` exports[`Amount -Demo Disabled unselected 1`] = `
壹仟贰佰叁拾肆元整 壹拾贰元叁角肆分 壹仟贰佰元整 壹仟贰佰零壹元整
`; -exports[`Amount -Demo Thousands Separator 1`] = `
1,234.00
`; +exports[`Amount -Demo Thousands Separator 1`] = `
1,234.00
-123,456.123
`; exports[`Amount -Demo Transition 1`] = `
0.00
`; diff --git a/components/amount/test/cases/demo1.vue b/components/amount/test/cases/demo1.vue index b2c2e7e24..8b48ba63a 100644 --- a/components/amount/test/cases/demo1.vue +++ b/components/amount/test/cases/demo1.vue @@ -3,6 +3,12 @@ +
+