Merge branch 'ASTRA-114' into 'master'

WIP Начала делать выбор года в календаре

See merge request andrusyakka/urban-couscous!430
This commit is contained in:
Daria Golova
2023-06-19 15:07:31 +00:00
6 changed files with 241 additions and 89 deletions

View File

@@ -0,0 +1,116 @@
<template lang="pug">
.calendar-wrapper.bg-white
component(
v-bind:is="currentForm",
v-model:internal-date="internalDate",
v-model:external-date="externalDate",
:range="range",
:range-count="rangeCount",
:next-form="nextForm",
:previous-form="previousForm"
)
.footer.flex.justify-end.items-center.px-5.py-3
q-btn(
color="dark"
flat,
no-caps,
label="Отменить",
size="14px",
padding="10px 12px",
@click="cancelChanges"
)
q-btn(
color="primary",
flat,
no-caps,
label="Сохранить",
size="14px",
padding="10px 12px",
@click="saveChanges"
)
</template>
<script>
import * as moment from "moment/moment";
import CalendarDates from "@/components/base/Calendar/CalendarDates.vue";
import CalendarMonths from "@/components/base/Calendar/CalendarMonths.vue";
export default {
name: "BaseCalendar",
components: { CalendarDates, CalendarMonths },
props: {
modelValue: Object,
range: Boolean,
rangeCount: Number,
save: {
type: Function,
default: () => {},
},
cancel: {
type: Function,
default: () => {},
},
},
data() {
return {
internalDate: moment(),
externalDate: null,
currentFormIndex: 0,
forms: ["CalendarDates", "CalendarMonths"],
};
},
computed: {
value: {
get() {
return this.modelValue;
},
set(value) {
this.$emit("update:modelValue", value);
},
},
currentForm() {
return this.forms[this.currentFormIndex];
},
},
methods: {
nextForm() {
this.currentFormIndex += 1;
},
previousForm() {
this.currentFormIndex -= 1;
},
cancelChanges() {
this.cancel();
},
saveChanges() {
this.value = this.externalDate?.from
? {
from: this.externalDate?.from?.clone(),
to: this.externalDate?.to?.clone(),
}
: this.externalDate.clone();
this.save();
},
},
mounted() {
if (this.value) {
if (this.range) {
this.internalDate = this.value?.from?.clone();
this.externalDate = {
from: this.value?.from?.clone(),
to: this.value?.to?.clone(),
};
} else {
this.internalDate = this.value?.clone();
this.externalDate = this.value?.clone();
}
}
},
};
</script>
<style scoped lang="sass">
.calendar-wrapper
width: 286px
.footer
border-top: 1px solid var(--border-light-grey-color)
</style>

View File

@@ -1,5 +1,5 @@
<template lang="pug"> <template lang="pug">
.calendar-wrapper.bg-white .w-full
.header.pl-3.pr-6.pt-14px.pb-10px.flex.items-center.justify-between .header.pl-3.pr-6.pt-14px.pb-10px.flex.items-center.justify-between
q-btn( q-btn(
size="14px" size="14px"
@@ -8,6 +8,7 @@
:label="internalMonth" :label="internalMonth"
no-caps, no-caps,
padding="10px 12px" padding="10px 12px"
@click="nextForm"
) )
.arrows.flex.items-center.justify-center.gap-x-6 .arrows.flex.items-center.justify-center.gap-x-6
q-btn( q-btn(
@@ -40,41 +41,18 @@
.flex.items-center.justify-center.rounded-full.w-full.h-full( .flex.items-center.justify-center.rounded-full.w-full.h-full(
:class="calculateCellClasses(date)", :class="calculateCellClasses(date)",
) {{ date.format("D") }} ) {{ date.format("D") }}
.footer.flex.justify-end.items-center.px-5.py-4
q-btn(
color="dark"
flat,
no-caps,
label="Отменить",
size="14px",
padding="6px 12px",
@click="cancel"
)
q-btn(
color="primary",
flat,
no-caps,
label="Сохранить",
size="14px",
padding="6px 12px",
@click="save"
)
</template> </template>
<script> <script>
import * as moment from "moment/moment";
import { mapState } from "vuex"; import { mapState } from "vuex";
export default { export default {
name: "BaseCalendar", name: "CalendarDates",
props: { props: {
modelValue: Object, internalDate: Object,
externalDate: Object,
range: Boolean, range: Boolean,
rangeCount: Number, rangeCount: Number,
save: { nextForm: {
type: Function,
default: () => {},
},
cancel: {
type: Function, type: Function,
default: () => {}, default: () => {},
}, },
@@ -82,31 +60,36 @@ export default {
data() { data() {
return { return {
week: ["ПН", "ВТ", "СР", "ЧТ", "ПТ", "СБ", "ВС"], week: ["ПН", "ВТ", "СР", "ЧТ", "ПТ", "СБ", "ВС"],
internalDate: moment(),
selectedDate: null,
datesRange: [],
}; };
}, },
computed: { computed: {
value: {
get() {
return this.modelValue;
},
set(value) {
this.$emit("update:modelValue", value);
},
},
...mapState({ ...mapState({
today: (state) => state.calendar.currentDate, today: (state) => state.calendar.currentDate,
}), }),
internalValue: {
get() {
return this.internalDate;
},
set(value) {
this.$emit("update:internalDate", value);
},
},
externalValue: {
get() {
return this.externalDate;
},
set(value) {
this.$emit("update:externalDate", value);
},
},
internalMonth() { internalMonth() {
let formattedMonth = this.internalDate.format("MMMM"); let formattedMonth = this.internalValue.format("MMMM");
return `${ return `${
formattedMonth[0].toUpperCase() + formattedMonth.slice(1) formattedMonth[0].toUpperCase() + formattedMonth.slice(1)
} ${this.internalDate.format("YYYY")}`; } ${this.internalValue.format("YYYY")}`;
}, },
internalStartDate() { internalStartDate() {
return this.internalDate return this.internalValue
.clone() .clone()
.startOf("month") .startOf("month")
.startOf("week") .startOf("week")
@@ -120,10 +103,10 @@ export default {
}, },
methods: { methods: {
previousMonth() { previousMonth() {
this.internalDate = this.internalDate.clone().subtract(1, "month"); this.internalValue = this.internalValue.clone().subtract(1, "month");
}, },
nextMonth() { nextMonth() {
this.internalDate = this.internalDate.clone().add(1, "month"); this.internalValue = this.internalValue.clone().add(1, "month");
}, },
calculateCellClasses(date) { calculateCellClasses(date) {
if (this.defineDateRange(date)) if (this.defineDateRange(date))
@@ -153,23 +136,28 @@ export default {
calculateRangeStyle(date) { calculateRangeStyle(date) {
if ( if (
this.range && this.range &&
this.value?.from && this.externalValue?.from &&
this.value?.to && this.externalValue?.to &&
!this.value?.from.isSame(this.value?.to?.format("YYYY-MM-DD")) !this.externalValue?.from.isSame(
this.externalValue?.to?.format("YYYY-MM-DD")
)
) { ) {
if (date.isSame(this.value?.from?.format("YYYY-MM-DD"))) if (date.isSame(this.externalValue?.from?.format("YYYY-MM-DD")))
return { return {
"border-top-left-radius": "9999px", "border-top-left-radius": "9999px",
"border-bottom-left-radius": "9999px", "border-bottom-left-radius": "9999px",
"background-color": "var(--btn-blue-color-5)", "background-color": "var(--btn-blue-color-5)",
}; };
if (date.isSame(this.value?.to?.format("YYYY-MM-DD"))) if (date.isSame(this.externalValue?.to?.format("YYYY-MM-DD")))
return { return {
"border-top-right-radius": "9999px", "border-top-right-radius": "9999px",
"border-bottom-right-radius": "9999px", "border-bottom-right-radius": "9999px",
"background-color": "var(--btn-blue-color-5)", "background-color": "var(--btn-blue-color-5)",
}; };
if (date.isAfter(this.value?.from) && date.isBefore(this.value?.to)) if (
date.isAfter(this.externalValue?.from) &&
date.isBefore(this.externalValue?.to)
)
return { return {
"background-color": "var(--btn-blue-color-5)", "background-color": "var(--btn-blue-color-5)",
}; };
@@ -177,50 +165,43 @@ export default {
}, },
selectDate(date) { selectDate(date) {
if (!this.range) { if (!this.range) {
this.value = date; this.externalValue = date;
return; return;
} }
if (this.rangeCount) { if (this.rangeCount) {
this.value.from = date; this.externalValue.from = date;
this.value.to = this.value.from.clone().add(this.rangeCount - 1, "day"); this.externalValue.to = this.externalValue.from
.clone()
.add(this.rangeCount - 1, "day");
return; return;
} }
if (this.value?.to) { if (this.externalValue?.to) {
this.value.from = date; this.externalValue.from = date;
this.value.to = null; this.externalValue.to = null;
return; return;
} }
if (date.isAfter(this.value?.from)) { if (date.isAfter(this.externalValue?.from)) {
this.value.to = date; this.externalValue.to = date;
return; return;
} }
this.value.to = this.value.from; this.externalValue.to = this.externalValue.from;
this.value.from = date; this.externalValue.from = date;
return; return;
}, },
defineDateRange(date) { defineDateRange(date) {
if (!this.range) { if (!this.range) {
return date.isSame(this.value?.format("YYYY-MM-DD")); return date.isSame(this.externalValue?.format("YYYY-MM-DD"));
} }
return ( return (
date.isSame(this.value?.from?.format("YYYY-MM-DD")) || date.isSame(this.externalValue?.from?.format("YYYY-MM-DD")) ||
date.isSame(this.value?.to?.format("YYYY-MM-DD")) date.isSame(this.externalValue?.to?.format("YYYY-MM-DD"))
); );
}, },
}, },
mounted() {
if (this.value) {
if (this.range) {
this.internalDate = this.value?.from?.clone();
} else this.internalDate = this.value?.clone();
}
},
}; };
</script> </script>
<style scoped lang="sass"> <style scoped lang="sass">
.calendar-wrapper
width: 286px
.header .header
border-bottom: 1px solid var(--border-light-grey-color) border-bottom: 1px solid var(--border-light-grey-color)
.week-item .week-item
@@ -250,10 +231,6 @@ export default {
grid-template-columns: repeat(7, 35px) grid-template-columns: repeat(7, 35px)
grid-template-rows: repeat(6, 35px) grid-template-rows: repeat(6, 35px)
row-gap: 4px row-gap: 4px
justify-content: center
align-items: center
.month:hover .month:hover
background-color: var(--bg-light-grey) background-color: var(--bg-light-grey)
.footer
border-top: 1px solid var(--border-light-grey-color)
</style> </style>

View File

@@ -0,0 +1,44 @@
<template lang="pug">
.w-full
.header.pl-3.pr-6.pt-14px.pb-10px.flex.items-center.justify-center
q-btn(
size="14px"
color="dark"
flat,
label="Июнь 2023"
no-caps,
padding="10px 12px"
)
.body.py-5.px-6
.item.flex.items-center.justify-center.cursor-pointer.py-3.rounded(v-for="num in 31") {{ num }}
</template>
<script>
export default {
name: "CalendarMonths",
props: {},
data() {
return {};
},
computed: {},
methods: {},
};
</script>
<style scoped lang="sass">
.header
border-bottom: 1px solid var(--border-light-grey-color)
.body
height: 298px
display: grid
grid-template-columns: repeat(3, 1fr)
row-gap: 4px
column-gap: 4px
overflow-y: auto
&::-webkit-scrollbar
width: 0
.item
background-color: var(--bg-light-grey)
&:hover
background-color: var(--border-light-grey-color)
</style>

View File

@@ -0,0 +1,17 @@
<template lang="pug">
</template>
<script>
export default {
name: "CalendarYears",
props: {},
data() {
return {};
},
computed: {},
methods: {},
};
</script>
<style scoped lang="sass"></style>

View File

@@ -69,7 +69,7 @@
<script> <script>
import BaseInput from "@/components/base/BaseInput"; import BaseInput from "@/components/base/BaseInput";
import BaseCalendar from "@/components/base/BaseCalendar"; import BaseCalendar from "@/components/base/Calendar/BaseCalendar.vue";
import { mapState, mapActions } from "vuex"; import { mapState, mapActions } from "vuex";
import { v_model } from "@/shared/mixins/v-model"; import { v_model } from "@/shared/mixins/v-model";
export default { export default {
@@ -119,23 +119,21 @@ export default {
}), }),
saveNewDate() { saveNewDate() {
this.calendarVisibility = false; this.calendarVisibility = false;
if (
!this.date?.from.isSame(this.selectedDates?.from) &&
!this.date?.to.isSame(this.selectedDates?.to)
)
this.changeSelectedDates(this.date);
}, },
cancelDateChanges() { cancelDateChanges() {
this.calendarVisibility = false; this.calendarVisibility = false;
}, },
}, },
watch: { watch: {
calendarVisibility(val) { date: {
if (val === false) deep: true,
this.date = { handler(val) {
from: this.selectedDates.from.clone(), if (
to: this.selectedDates.to.clone(), !this.val?.from.isSame(this.selectedDates?.from) &&
}; !this.val?.to.isSame(this.selectedDates?.to)
)
this.changeSelectedDates(val);
},
}, },
}, },
mounted() { mounted() {

View File

@@ -83,8 +83,8 @@ import FormCreateAttachments from "@/pages/clients/components/FormCreateAttachme
import BaseInput from "@/components/base/BaseInput.vue"; import BaseInput from "@/components/base/BaseInput.vue";
import BaseInputFullName from "@/components/base/BaseInputFullName.vue"; import BaseInputFullName from "@/components/base/BaseInputFullName.vue";
import { patientData } from "@/pages/newCalendar/utils/calendarConfig.js"; import { patientData } from "@/pages/newCalendar/utils/calendarConfig.js";
import BaseCalendar from "@/components/base/BaseCalendar.vue";
import HeaderRecordForm from "./HeaderRecordForm.vue"; import HeaderRecordForm from "./HeaderRecordForm.vue";
import BaseCalendar from "@/components/base/Calendar/BaseCalendar.vue";
export default { export default {
name: "RecordCreationForm", name: "RecordCreationForm",