akaunting/resources/assets/js/components/AkauntingDate.vue

138 lines
3.1 KiB
Vue
Raw Normal View History

2019-11-16 10:21:14 +03:00
<template>
<base-input :label="title"
:name="name"
:class="[
{'readonly': readonly},
{'disabled': disabled},
formClasses
]"
:footer-error="formError"
:prependIcon="icon"
:readonly="readonly"
:disabled="disabled"
>
2019-11-16 10:21:14 +03:00
<flat-picker slot-scope="{focus, blur}"
2021-05-25 19:52:39 +03:00
:name="dataName"
@on-open="focus"
@on-close="blur"
2021-02-27 16:54:39 +03:00
:config="dateConfig"
class="form-control datepicker"
v-model="real_model"
@input="change"
:readonly="readonly"
:disabled="disabled">
2019-11-16 10:21:14 +03:00
</flat-picker>
</base-input>
</template>
<script>
import flatPicker from "vue-flatpickr-component";
import "flatpickr/dist/flatpickr.css";
export default {
name: 'akaunting-date',
components: {
flatPicker
},
props: {
title: {
type: String,
default: '',
description: "Modal header title"
},
2021-05-25 19:52:39 +03:00
dataName: {
type: String,
default: '',
description: "Modal header title"
},
2019-11-16 10:21:14 +03:00
placeholder: {
type: String,
default: '',
description: "Modal header title"
},
readonly: {
type: Boolean,
default: false,
description: "Input readonly status"
},
disabled: {
type: Boolean,
default: false,
description: "Input disabled status"
},
2019-11-16 10:21:14 +03:00
formClasses: null,
formError: null,
name: null,
2020-03-20 17:24:32 +03:00
value: {
default: null,
description: "Input value defalut"
},
model: {
default: null,
description: "Input model defalut"
},
2021-02-27 16:54:39 +03:00
dateConfig: {
type: Object,
default: function () {
return {
allowInput: true,
altFormat: "d M Y",
altInput: true,
dateFormat: "Y-m-d",
wrap: true,
};
},
description: "FlatPckr date configuration"
},
2019-11-16 10:21:14 +03:00
icon: {
type: String,
description: "Prepend icon (left)"
},
locale: {
type: String,
default: 'en',
2019-11-16 10:21:14 +03:00
}
},
data() {
return {
2021-05-25 19:52:39 +03:00
real_model: '',
}
},
created() {
if (this.locale !== 'en') {
const lang = require(`flatpickr/dist/l10n/${this.locale}.js`).default[this.locale];
2021-02-23 22:28:18 +03:00
2021-03-18 11:43:38 +03:00
this.dateConfig.locale = lang;
2019-11-16 10:21:14 +03:00
}
},
mounted() {
this.real_model = this.value;
if (this.model) {
this.real_model = this.model;
}
2019-11-16 10:21:14 +03:00
this.$emit('interface', this.real_model);
},
methods: {
change() {
this.$emit('interface', this.real_model);
this.$emit('change', this.real_model);
2019-11-16 10:21:14 +03:00
}
2021-05-25 19:52:39 +03:00
},
2021-05-25 22:19:49 +03:00
2021-05-25 19:52:39 +03:00
watch: {
2021-05-25 22:19:49 +03:00
value: function(val) {
2021-05-25 19:52:39 +03:00
this.real_model = val;
}
2019-11-16 10:21:14 +03:00
}
}
</script>