add price per count (#134)

Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
GermeyandAceDataCloud authored and GitHub committed 2024-08-31 15:21:50 +08:00
1 parent d8ad837d8a
commit 562d32b713
3 files changed
+26 -3

No files matched your search

+12
View File
@@ -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">
@@ -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',
@@ -38,6 +47,9 @@ export default defineComponent({
type: Object as () => IPackage | undefined,
required: true
}
},
methods: {
getPriceString
}
});
</script>
+7 -3
View File
@@ -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)}`;
};