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