From 562d32b713e1ce0c60f234e468d870f8b8d9e91a Mon Sep 17 00:00:00 2001 From: Germey Date: Sat, 31 Aug 2024 15:21:50 +0800 Subject: [PATCH] add price per count (#134) Co-authored-by: AceDataCloud --- ...-nexior-5d8ce26a-e2db-48ad-973f-685e7828e3e3.json | 7 +++++++ src/components/service/Estimation.vue | 12 ++++++++++++ src/utils/price.ts | 10 +++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 change/@acedatacloud-nexior-5d8ce26a-e2db-48ad-973f-685e7828e3e3.json diff --git a/change/@acedatacloud-nexior-5d8ce26a-e2db-48ad-973f-685e7828e3e3.json b/change/@acedatacloud-nexior-5d8ce26a-e2db-48ad-973f-685e7828e3e3.json new file mode 100644 index 00000000..d5cc3750 --- /dev/null +++ b/change/@acedatacloud-nexior-5d8ce26a-e2db-48ad-973f-685e7828e3e3.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "add price per count", + "packageName": "@acedatacloud/nexior", + "email": "office@acedata.cloud", + "dependentChangeType": "patch" +} diff --git a/src/components/service/Estimation.vue b/src/components/service/Estimation.vue index e8a5cd09..1c21d85c 100644 --- a/src/components/service/Estimation.vue +++ b/src/components/service/Estimation.vue @@ -4,6 +4,14 @@

≈ {{ item.name }} {{ Math.round(package.amount / item.cost) }} {{ $t('api.unit.count') }} + + - + {{ + getPriceString({ value: package.price / (package.amount / item.cost), fractionDigits: 3 }) + + ' / ' + + $t(`api.unit.count`) + }} + ({{ item.remark }}) - @@ -25,6 +33,7 @@ diff --git a/src/utils/price.ts b/src/utils/price.ts index 97cbbd5e..d1da4b58 100644 --- a/src/utils/price.ts +++ b/src/utils/price.ts @@ -28,8 +28,12 @@ export const getPrice = (payload: { value: number; currency?: string }) => { }; }; -export const getPriceString = (payload: { value: number | undefined; defaultValue?: number | undefined }) => { - let { value, defaultValue } = payload; +export const getPriceString = (payload: { + value: number | undefined; + defaultValue?: number | undefined; + fractionDigits?: number | undefined; +}) => { + let { value, defaultValue, fractionDigits = 2 } = payload; if (value === undefined) { value = defaultValue; } @@ -39,5 +43,5 @@ export const getPriceString = (payload: { value: number | undefined; defaultValu const price = getPrice({ value }); - return `${price.label}${price.value?.toFixed(2)}`; + return `${price.label}${price.value?.toFixed(fractionDigits)}`; };