|
|
|
@ -1,36 +1,49 @@
|
|
|
|
|
<script> |
|
|
|
|
export default { |
|
|
|
|
name: 'CurrencyCell', |
|
|
|
|
props: { |
|
|
|
|
column: Object, |
|
|
|
|
value: [String, Number], |
|
|
|
|
}, |
|
|
|
|
computed: { |
|
|
|
|
currency() { |
|
|
|
|
try { |
|
|
|
|
return isNaN(this.value) |
|
|
|
|
? this.value |
|
|
|
|
: new Intl.NumberFormat(this.currencyMeta.currency_locale || 'en-US', { |
|
|
|
|
style: 'currency', |
|
|
|
|
currency: this.currencyMeta.currency_code || 'USD', |
|
|
|
|
}).format(this.value) |
|
|
|
|
} catch (e) { |
|
|
|
|
return this.value |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
currencyMeta() { |
|
|
|
|
return { |
|
|
|
|
currency_locale: 'en-US', |
|
|
|
|
currency_code: 'USD', |
|
|
|
|
...(this.column && this.column.meta ? this.column.meta : {}), |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
<script setup lang="ts"> |
|
|
|
|
import { computed, inject } from '#imports' |
|
|
|
|
import { ColumnInj } from '~/context' |
|
|
|
|
|
|
|
|
|
const { modelValue: value } = defineProps<Props>() |
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['update:modelValue']) |
|
|
|
|
|
|
|
|
|
const column = inject(ColumnInj) |
|
|
|
|
|
|
|
|
|
const editEnabled = inject<boolean>('editEnabled') |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
modelValue: number |
|
|
|
|
} |
|
|
|
|
const root = ref<HTMLInputElement>() |
|
|
|
|
|
|
|
|
|
const localState = computed({ |
|
|
|
|
get: () => value, |
|
|
|
|
set: (val) => emit('update:modelValue', val), |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const currencyMeta = computed(() => { |
|
|
|
|
return { |
|
|
|
|
currency_locale: 'en-US', |
|
|
|
|
currency_code: 'USD', |
|
|
|
|
...(column && column.meta ? column.meta : {}), |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
const currency = computed(() => { |
|
|
|
|
try { |
|
|
|
|
return isNaN(value) |
|
|
|
|
? value |
|
|
|
|
: new Intl.NumberFormat(currencyMeta?.value?.currency_locale || 'en-US', { |
|
|
|
|
style: 'currency', |
|
|
|
|
currency: currencyMeta?.value?.currency_code || 'USD', |
|
|
|
|
}).format(value) |
|
|
|
|
} catch (e) { |
|
|
|
|
return value |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
|
<a v-if="value">{{ currency }}</a> |
|
|
|
|
<input v-if="editEnabled" ref="root" v-model="localState" /> |
|
|
|
|
<span v-else-if="value">{{ currency }}</span> |
|
|
|
|
<span v-else /> |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|