2021-04-10 19:45:11 +02:00
|
|
|
<template>
|
2022-12-01 23:46:02 +01:00
|
|
|
<label class="field-wrap field-wrap-sm" :for="id" :class="sizes[size].wrap">
|
2021-08-22 16:15:16 +02:00
|
|
|
<span v-if="label" class="field-label">
|
|
|
|
{{ label }}
|
|
|
|
<span v-show="required" class="text-red-800"> *</span>
|
|
|
|
</span>
|
2022-12-01 23:46:02 +01:00
|
|
|
<div class="real-field-wrap size-sm" :class="sizes[size].field">
|
2022-08-11 23:19:52 +02:00
|
|
|
<input
|
|
|
|
@keypress="$emit('keypress', $event)"
|
|
|
|
:name="name"
|
|
|
|
:type="type"
|
|
|
|
:value="transformedValue"
|
|
|
|
@input="onInput"
|
|
|
|
@change="onChange"
|
|
|
|
:disabled="disabled"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
/>
|
2021-08-22 16:15:16 +02:00
|
|
|
<div v-if="hint" class="info-wrap">
|
|
|
|
<div v-tooltip="hint">
|
2023-07-06 13:56:19 +02:00
|
|
|
<ui-sprite src="info-button" class="info-button"></ui-sprite>
|
2021-04-10 19:45:11 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import wNumb from 'wnumb';
|
|
|
|
|
|
|
|
var numb = {
|
|
|
|
natural: wNumb({
|
|
|
|
mark: ',',
|
|
|
|
thousand: '.',
|
|
|
|
decimals: 0,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 100;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 100;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
}),
|
|
|
|
naturalRaw: wNumb({
|
|
|
|
mark: '',
|
|
|
|
thousand: '',
|
|
|
|
decimals: 0,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 100;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 100;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
}),
|
2021-08-22 16:15:16 +02:00
|
|
|
naturalDetailRaw: wNumb({
|
|
|
|
mark: '',
|
|
|
|
thousand: '',
|
|
|
|
decimals: 0,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 10000;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 10000;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
}),
|
2021-04-10 19:45:11 +02:00
|
|
|
area: wNumb({
|
|
|
|
mark: ',',
|
|
|
|
thousand: '.',
|
|
|
|
decimals: 2,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 100;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 100;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
}),
|
2021-08-22 16:15:16 +02:00
|
|
|
areaDetail: wNumb({
|
|
|
|
mark: ',',
|
|
|
|
thousand: '.',
|
|
|
|
decimals: 4,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 10000;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 10000;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
}),
|
2021-04-10 19:45:11 +02:00
|
|
|
twoDecimalRaw: wNumb({
|
|
|
|
mark: ',',
|
|
|
|
thousand: '',
|
|
|
|
decimals: 2,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 100;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 100;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
}),
|
|
|
|
fourDecimalRaw: wNumb({
|
|
|
|
mark: ',',
|
|
|
|
thousand: '',
|
|
|
|
decimals: 4,
|
|
|
|
decoder(a) {
|
|
|
|
return a * 10000;
|
|
|
|
},
|
|
|
|
encoder(a) {
|
|
|
|
return a / 10000;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
|
|
|
}),
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var transformers = {
|
|
|
|
none: {
|
|
|
|
display: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return v;
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v;
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
edit: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return v;
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v;
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
natural: {
|
|
|
|
display: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return isNaN(parseInt(v)) ? '' : numb.natural.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v === '' ? null : numb.natural.from(v);
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
edit: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return isNaN(parseInt(v)) ? '' : numb.naturalRaw.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v === '' ? null : numb.naturalRaw.from(v);
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
area: {
|
|
|
|
display: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return v === null ? '' : numb.area.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v === '' ? null : numb.area.from(v);
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
to(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if (Math.round(v / 100) * 100 === v) {
|
|
|
|
return numb.naturalRaw.to(v);
|
|
|
|
}
|
2021-04-10 19:45:11 +02:00
|
|
|
return numb.twoDecimalRaw.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (v.indexOf(',') === -1) {
|
|
|
|
return numb.naturalRaw.from(v);
|
|
|
|
}
|
2021-04-10 19:45:11 +02:00
|
|
|
|
|
|
|
return numb.twoDecimalRaw.from(v);
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
currency: {
|
|
|
|
display: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return v === null ? '' : numb.area.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v === '' ? null : numb.area.from(v);
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
to(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if (Math.round(v / 100) * 100 === v) {
|
|
|
|
return numb.naturalRaw.to(v);
|
|
|
|
}
|
2021-04-10 19:45:11 +02:00
|
|
|
return numb.twoDecimalRaw.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (v.indexOf(',') === -1) {
|
|
|
|
return numb.naturalRaw.from(v);
|
|
|
|
}
|
2021-04-10 19:45:11 +02:00
|
|
|
|
|
|
|
return numb.twoDecimalRaw.from(v);
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
},
|
|
|
|
currencyDetail: {
|
|
|
|
display: {
|
2022-08-11 23:19:52 +02:00
|
|
|
to(v) {
|
|
|
|
return v === null ? '' : numb.areaDetail.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
|
|
|
return v === '' ? null : numb.areaDetail.from(v);
|
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
to(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if (Math.round(v / 10000) * 10000 === v) {
|
|
|
|
return numb.naturalDetailRaw.to(v);
|
|
|
|
}
|
2021-08-22 16:15:16 +02:00
|
|
|
return numb.fourDecimalRaw.to(v);
|
|
|
|
},
|
|
|
|
from(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (v.indexOf(',') === -1) {
|
|
|
|
return numb.naturalDetailRaw.from(v);
|
|
|
|
}
|
2021-08-22 16:15:16 +02:00
|
|
|
|
|
|
|
return numb.fourDecimalRaw.from(v);
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
2022-08-11 23:19:52 +02:00
|
|
|
data: function () {
|
2021-04-10 19:45:11 +02:00
|
|
|
return {
|
2022-08-11 23:19:52 +02:00
|
|
|
focus: false,
|
2022-12-01 23:46:02 +01:00
|
|
|
sizes: {
|
|
|
|
sm: {
|
|
|
|
wrap: 'field-wrap-sm',
|
|
|
|
field: 'size-sm',
|
|
|
|
},
|
|
|
|
base: {
|
|
|
|
wrap: 'field-wrap-base',
|
|
|
|
field: 'size-base',
|
|
|
|
},
|
|
|
|
lg: {
|
|
|
|
wrap: 'field-wrap-lg',
|
|
|
|
field: 'size-lg',
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
placeholder: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
2021-04-10 19:45:11 +02:00
|
|
|
return '';
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
default: {},
|
|
|
|
mode: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
|
|
|
return 'none';
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
2022-08-11 23:19:52 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
inset: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
2021-04-10 19:45:11 +02:00
|
|
|
return null;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
size: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
2021-08-22 16:15:16 +02:00
|
|
|
return 'base';
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
id: {
|
2022-08-11 23:19:52 +02:00
|
|
|
required: true,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
hint: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: null,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2023-07-06 13:56:19 +02:00
|
|
|
modelValue: {},
|
2021-04-10 19:45:11 +02:00
|
|
|
mask: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: undefined,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
label: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
type: {
|
|
|
|
required: false,
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
|
|
|
return 'text';
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
default: false,
|
2022-08-11 23:19:52 +02:00
|
|
|
type: Boolean,
|
2021-08-22 16:15:16 +02:00
|
|
|
},
|
|
|
|
name: {},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onFocus() {
|
|
|
|
this.focus = true;
|
|
|
|
},
|
|
|
|
onBlur() {
|
|
|
|
this.focus = false;
|
|
|
|
},
|
|
|
|
onChange(v) {
|
|
|
|
if (this.mode !== 'none') {
|
|
|
|
this.transformedValue = v.target.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onInput(v) {
|
|
|
|
if (this.mode === 'none') {
|
|
|
|
this.transformedValue = v.target.value;
|
|
|
|
}
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
transformedValue: {
|
|
|
|
get() {
|
2023-07-06 13:56:19 +02:00
|
|
|
return transformers[this.mode][this.focus ? 'edit' : 'display'].to(this.modelValue);
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
set(v) {
|
2023-07-06 13:56:19 +02:00
|
|
|
this.$emit('update:modelValue', transformers[this.mode][this.focus ? 'edit' : 'display'].from(v));
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
insetClass() {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (this.inset === '') {
|
|
|
|
return 'bg-inset';
|
|
|
|
}
|
|
|
|
if (this.inset === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-04-10 19:45:11 +02:00
|
|
|
|
|
|
|
return `bg-${this.inset}`;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
created() {
|
2023-07-06 13:56:19 +02:00
|
|
|
if (typeof this.modelValue === 'undefined') {
|
2021-04-10 19:45:11 +02:00
|
|
|
this.$emit('input', this.default === undefined ? '' : this.default);
|
|
|
|
}
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scope>
|
|
|
|
.bg-inset {
|
2023-05-08 15:11:16 +02:00
|
|
|
background: linear-gradient(to bottom, hsl(247.5, 66.7%, 97.6%) 0%, hsl(247.5, 66.7%, 97.6%) 41%, hsl(0deg 0% 100%) 41%, hsl(180deg 0% 100%) 100%);
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
|
|
|
</style>
|