63 lines
1.8 KiB
Vue
63 lines
1.8 KiB
Vue
<template>
|
|
<div>
|
|
<v-text-field
|
|
ref="textField"
|
|
:value="currencyValue"
|
|
@change="updateValue"
|
|
v-currency="{
|
|
currency: currencyName,
|
|
locale: languageName
|
|
}"
|
|
:readonly="readonly"
|
|
:disabled="disabled"
|
|
:label="label"
|
|
:rules="rules"
|
|
:error-messages="errorMessages"
|
|
:append-outer-icon="appendOuterIcon"
|
|
@click:append-outer="$emit('gz-append-outer')"
|
|
></v-text-field>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
/* Xeslint-disable //@click:append-outer="appendOuter"*/
|
|
//https://dm4t2.github.io/vue-currency-input/guide/#introduction :value="formattedValue"
|
|
//https://codesandbox.io/s/vue-template-kd7d1?fontsize=14&module=%2Fsrc%2FApp.vue
|
|
//https://github.com/dm4t2/vue-currency-input
|
|
//https://github.com/dm4t2/vue-currency-input/releases
|
|
import { setValue, parseCurrency } from "vue-currency-input";
|
|
export default {
|
|
data() {
|
|
return {
|
|
currencyName: window.$gz.locale.getCurrencyName(),
|
|
languageName: window.$gz.locale.getResolvedLanguage()
|
|
};
|
|
},
|
|
props: {
|
|
label: { type: String, default: null },
|
|
rules: { type: Array, default: undefined },
|
|
value: { type: Number, default: null },
|
|
readonly: { type: Boolean, default: false },
|
|
disabled: { type: Boolean, default: false },
|
|
errorMessages: { type: Array, default: null },
|
|
appendOuterIcon: { type: String, default: null }
|
|
},
|
|
computed: {
|
|
currencyValue() {
|
|
return this.value;
|
|
}
|
|
},
|
|
methods: {
|
|
updateValue() {
|
|
let val = this.$refs.textField.$refs.input.value;
|
|
let parsedValue = parseCurrency(val, {
|
|
currency: this.currencyName,
|
|
locale: this.languageName
|
|
});
|
|
if (parsedValue != this.value) {
|
|
this.$emit("input", parsedValue);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
</script>
|