Сделала BaseCalendar
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
component(
|
component(
|
||||||
v-bind:is="currentForm?.component",
|
v-bind:is="currentForm?.component",
|
||||||
v-model:internal-date="internalDate",
|
v-model:internal-date="internalDate",
|
||||||
v-model:external-date="value",
|
v-model:external-date="externalValue",
|
||||||
:range="range",
|
:range="range",
|
||||||
:start-year="startYear",
|
:start-year="startYear",
|
||||||
:end-year="endYear",
|
:end-year="endYear",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
label="Отменить",
|
label="Отменить",
|
||||||
size="14px",
|
size="14px",
|
||||||
padding="10px 12px",
|
padding="10px 12px",
|
||||||
@click="currentForm?.cancelFunction"
|
@click="cancelChanges"
|
||||||
)
|
)
|
||||||
q-btn(
|
q-btn(
|
||||||
color="primary",
|
color="primary",
|
||||||
@@ -56,10 +56,6 @@ export default {
|
|||||||
type: Function,
|
type: Function,
|
||||||
default: () => {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
// cancel: {
|
|
||||||
// type: Function,
|
|
||||||
// default: () => {},
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -69,23 +65,20 @@ export default {
|
|||||||
{
|
{
|
||||||
component: "CalendarDates",
|
component: "CalendarDates",
|
||||||
saveBtnLabel: "Сохранить",
|
saveBtnLabel: "Сохранить",
|
||||||
cancelFunction: this.cancelExternalChanges,
|
|
||||||
saveFunction: this.saveExternalChanges,
|
saveFunction: this.saveExternalChanges,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: "CalendarYears",
|
component: "CalendarYears",
|
||||||
saveBtnLabel: "Применить",
|
saveBtnLabel: "Применить",
|
||||||
cancelFunction: this.cancelInternalChanges,
|
|
||||||
saveFunction: this.applyInternalChanges,
|
saveFunction: this.applyInternalChanges,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: "CalendarMonths",
|
component: "CalendarMonths",
|
||||||
saveBtnLabel: "Применить",
|
saveBtnLabel: "Применить",
|
||||||
cancelFunction: this.cancelInternalChanges,
|
|
||||||
saveFunction: this.applyInternalChanges,
|
saveFunction: this.applyInternalChanges,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
previousValue: null,
|
externalValue: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -108,28 +101,29 @@ export default {
|
|||||||
changeForm(form) {
|
changeForm(form) {
|
||||||
this.currentForm = this.forms.find((elem) => elem.component === form);
|
this.currentForm = this.forms.find((elem) => elem.component === form);
|
||||||
},
|
},
|
||||||
cancelExternalChanges() {
|
changeDate() {
|
||||||
this.value = this.range
|
|
||||||
? {
|
|
||||||
from: this.previousValue?.from?.clone(),
|
|
||||||
to: this.previousValue?.to?.clone(),
|
|
||||||
}
|
|
||||||
: this.previousValue;
|
|
||||||
},
|
|
||||||
cancelInternalChanges() {
|
|
||||||
if (this.range) {
|
if (this.range) {
|
||||||
this.value = {
|
this.internalDate = this.value?.from?.clone();
|
||||||
from: this.previousValue?.from?.clone(),
|
this.externalValue = {
|
||||||
to: this.previousValue?.to?.clone(),
|
from: this.value?.from?.clone(),
|
||||||
|
to: this.value?.to?.clone(),
|
||||||
};
|
};
|
||||||
this.internalDate = this.previousValue?.from?.clone();
|
|
||||||
} else {
|
} else {
|
||||||
this.value = this.previousValue;
|
this.internalDate = this.value?.clone();
|
||||||
this.internalDate = this.previousValue;
|
this.externalValue = this.value?.clone();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
cancelChanges() {
|
||||||
|
this.changeDate();
|
||||||
this.changeForm("CalendarDates");
|
this.changeForm("CalendarDates");
|
||||||
},
|
},
|
||||||
saveExternalChanges() {
|
saveExternalChanges() {
|
||||||
|
if (this.range)
|
||||||
|
this.value = {
|
||||||
|
from: this.externalValue?.from?.clone(),
|
||||||
|
to: this.externalValue?.to?.clone(),
|
||||||
|
};
|
||||||
|
else this.value = this.externalValue?.clone();
|
||||||
this.save();
|
this.save();
|
||||||
},
|
},
|
||||||
applyInternalChanges() {
|
applyInternalChanges() {
|
||||||
@@ -144,18 +138,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.value) {
|
if (this.value) this.changeDate();
|
||||||
if (this.range) {
|
|
||||||
this.internalDate = this.value?.from?.clone();
|
|
||||||
this.previousValue = {
|
|
||||||
from: this.value?.from?.clone(),
|
|
||||||
to: this.value?.to?.clone(),
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
this.internalDate = this.value?.clone();
|
|
||||||
this.previousValue = this.value?.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.currentForm = this.forms[0];
|
this.currentForm = this.forms[0];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ export default {
|
|||||||
endYear: Number,
|
endYear: Number,
|
||||||
internalMonth: String,
|
internalMonth: String,
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
previousDate: null,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
internalValue: {
|
internalValue: {
|
||||||
get() {
|
get() {
|
||||||
@@ -69,9 +64,14 @@ export default {
|
|||||||
selectYear(year) {
|
selectYear(year) {
|
||||||
this.internalValue = this.internalValue.clone().year(year);
|
this.internalValue = this.internalValue.clone().year(year);
|
||||||
},
|
},
|
||||||
|
scrollToCurrentYear() {
|
||||||
|
document
|
||||||
|
.getElementById(parseInt(this.internalValue.format("YYYY"), 10))
|
||||||
|
.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.previousDate = this.internalValue.clone();
|
this.scrollToCurrentYear();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
range,
|
range,
|
||||||
:range-count="7",
|
:range-count="7",
|
||||||
:save="saveDatesChange",
|
:save="saveDatesChange",
|
||||||
|
:start-year="2000"
|
||||||
)
|
)
|
||||||
q-btn(
|
q-btn(
|
||||||
color="secondary",
|
color="secondary",
|
||||||
@@ -108,26 +109,16 @@ export default {
|
|||||||
previousWeek() {
|
previousWeek() {
|
||||||
this.dates.from = this.dates.from.clone().subtract(1, "week");
|
this.dates.from = this.dates.from.clone().subtract(1, "week");
|
||||||
this.dates.to = this.dates.to.clone().subtract(1, "week");
|
this.dates.to = this.dates.to.clone().subtract(1, "week");
|
||||||
this.changeSelectedDates(this.dates);
|
|
||||||
},
|
},
|
||||||
nextWeek() {
|
nextWeek() {
|
||||||
this.dates.from = this.dates.from.clone().add(1, "week");
|
this.dates.from = this.dates.from.clone().add(1, "week");
|
||||||
this.dates.to = this.dates.to.clone().add(1, "week");
|
this.dates.to = this.dates.to.clone().add(1, "week");
|
||||||
this.changeSelectedDates(this.dates);
|
|
||||||
},
|
},
|
||||||
...mapActions({
|
...mapActions({
|
||||||
changeSelectedDates: "changeSelectedDates",
|
changeSelectedDates: "changeSelectedDates",
|
||||||
}),
|
}),
|
||||||
saveDatesChange() {
|
saveDatesChange() {
|
||||||
this.calendarVisibility = false;
|
this.calendarVisibility = false;
|
||||||
if (
|
|
||||||
!this.dates?.from.isSame(this.selectedDates?.from) &&
|
|
||||||
!this.dates?.to.isSame(this.selectedDates?.to)
|
|
||||||
)
|
|
||||||
this.changeSelectedDates(this.dates);
|
|
||||||
},
|
|
||||||
cancelDatesChange() {
|
|
||||||
this.calendarVisibility = false;
|
|
||||||
},
|
},
|
||||||
initializeDates() {
|
initializeDates() {
|
||||||
this.dates = {
|
this.dates = {
|
||||||
@@ -137,19 +128,16 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// dates: {
|
dates: {
|
||||||
// deep: true,
|
deep: true,
|
||||||
// handler(val) {
|
handler(val) {
|
||||||
// if (
|
if (
|
||||||
// !this.val?.from.isSame(this.selectedDates?.from) &&
|
!this.val?.from.isSame(this.selectedDates?.from) &&
|
||||||
// !this.val?.to.isSame(this.selectedDates?.to)
|
!this.val?.to.isSame(this.selectedDates?.to)
|
||||||
// )
|
)
|
||||||
// this.changeSelectedDates(val);
|
this.changeSelectedDates(val);
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// calendarVisibility(val) {
|
|
||||||
// if (val === false) this.initializeDates();
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initializeDates();
|
this.initializeDates();
|
||||||
|
|||||||
Reference in New Issue
Block a user