diff --git a/src/components/ui/VnCurrency.vue b/src/components/ui/VnCurrency.vue index b4b7622b0..b3ea821fd 100644 --- a/src/components/ui/VnCurrency.vue +++ b/src/components/ui/VnCurrency.vue @@ -14,8 +14,8 @@ const $props = defineProps({ default: undefined, }, foreignField: { - type: String, - default: 'foreignPrice', + type: [String, undefined], + default: undefined, }, localField: { type: String, @@ -27,22 +27,36 @@ const $props = defineProps({ description: 'find currency code in array data model', }, }); + +const foreignFieldComputed = ref(); const arrayData = $props.arrayDataModel && useArrayData($props.arrayDataModel); -const foreignValue = computed(() => $props.model?.[$props.foreignField]); +const foreignValue = ref(); const localValue = computed(() => $props.model?.[$props.localField]); const currency = computed( - () => $props.currencyCode ?? arrayData.store.data?.currency?.code -); -const toCurrencyLabel = computed(() => - toCurrency(foreignValue.value ?? localValue.value, currency.value) + () => $props.currencyCode ?? arrayData.store.data?.currency?.code, ); +const toCurrencyLabel = ref(); const currencyCodeModel = ref(); -// onMounted(() => { -// if ($props.arrayDataModel) { -// currencyCodeModel.value = arrayData.store.data?.currency?.code; -// } -// }); +onMounted(() => { + // if ($props.arrayDataModel) { + // currencyCodeModel.value = arrayData.store.data?.currency?.code; + // } + foreignFieldComputed.value = + $props.foreignField ?? + 'foreign' + + $props.localField.charAt(0).toUpperCase() + + $props.localField.slice(1); + foreignValue.value = $props.model[foreignFieldComputed.value]; + getLabel(); +}); + +function getLabel() { + toCurrencyLabel.value = toCurrency( + foreignValue.value ?? localValue.value, + currency.value, + ); +}