Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add price per count #134

Merged
merged 2 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "[email protected]",
"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)}`;
};
Loading