Skip to content

Commit

Permalink
add price per count (#134)
Browse files Browse the repository at this point in the history
Co-authored-by: AceDataCloud <office@acedata.cloud>
  • Loading branch information
Germey and AceDataCloud authored Aug 31, 2024
1 parent d8ad837 commit 562d32b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "add price per count",
"packageName": "@acedatacloud/nexior",
"email": "office@acedata.cloud",
"dependentChangeType": "patch"
}
12 changes: 12 additions & 0 deletions src/components/service/Estimation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<div v-for="(item, itemIndex) in api?.estimation" :key="itemIndex" class="items">
<p v-if="package?.amount && item?.cost" class="item">
≈ {{ item.name }} {{ Math.round(package.amount / item.cost) }} {{ $t('api.unit.count') }}
<span v-if="package.price > 0">
-
{{
getPriceString({ value: package.price / (package.amount / item.cost), fractionDigits: 3 }) +
' / ' +
$t(`api.unit.count`)
}}
</span>
<span v-if="item.remark"> ({{ item.remark }}) </span>
<span v-if="item?.comparisons?.length > 0"> - </span>
<span v-for="(comparison, comparisonIndex) in item?.comparisons" :key="comparisonIndex" class="comparison">
Expand All @@ -25,6 +33,7 @@
<script lang="ts">
import { IService, IPackage } from '@/operators';
import { defineComponent } from 'vue';
import { getPriceString } from '@/utils';
export default defineComponent({
name: 'ServiceEstimation',
Expand All @@ -38,6 +47,9 @@ export default defineComponent({
type: Object as () => IPackage | undefined,
required: true
}
},
methods: {
getPriceString
}
});
</script>
Expand Down
10 changes: 7 additions & 3 deletions src/utils/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)}`;
};

0 comments on commit 562d32b

Please sign in to comment.