[WIP] Добавил delete, возможность создания события на 1 день, поправил стили, отображение дней при изменении месяца

This commit is contained in:
megavrilinvv
2023-01-09 17:20:20 +03:00
parent e2cf5525ae
commit 2604d22471
3 changed files with 87 additions and 66 deletions

View File

@@ -26,42 +26,41 @@
v-for="day in result",
:key="day",
:id="schedule.id + day",
@click="choiceCell(day, schedule.id, schedule); clearData()",
@click="choiceCell(day, schedule.id, schedule); clearSelect(selectEmployee)",
:class="choiceState(day, schedule.id)",
:style="{backgroundColor: choiceDay(day, schedule.id) ? choiceColor(day, schedule) : ''}"
)
.flex(
:class="{'cell-work': choiceState(day, schedule.id).status, 'show-time': showTime}"
) {{choiceDay(day, schedule.id) ? choiceWorks(day, schedule) : ''}}
.schedule-select.flex.w-full.pr-2(v-if="clearEmployee")
.edit.flex.items-center.justify-center.h-11.w-11(v-if="currentEmployee.label")
.flex.icon-edit(v-if="currentEmployee.label")
.edit.flex.items-center.justify-center.h-11.w-11(v-if="selectEmployee.label")
.flex.icon-edit(v-if="selectEmployee.label")
//- base-button(
//- confirm,
//- rounded,
//- outlined,
//- :size="20",
//- @click="saveEmployee",
//- v-if="currentEmployee.label"
//- v-if="selectEmployee.label"
//- )
//- .icon-ok.text-xsm(class="pt-[3px]")
.text.flex.justify-center.items-center.cursor-pointer(:class="{'select-name': currentEmployee.label}")
.text.flex.justify-center.items-center.cursor-pointer(:class="{'select-name': selectEmployee.label}")
base-custom-select(
v-if="!currentEmployee.label",
v-if="!selectEmployee.label",
:items="ownersList",
v-model="currentEmployee",
v-model="selectEmployee",
placeholder="Добавить сотрудника",
:style="{border: 'none', justifyContent: 'center'}"
)
.flex.justify-center(v-else) {{currentEmployee.label}}
.flex.justify-center(v-else) {{selectEmployee.label}}
.cell.flex.flex-col.items-center.justify-center.w-11.h-11.cursor-pointer(
v-if="currentEmployee.label",
v-if="selectEmployee.label",
v-for="day in result",
:key="day",
:id="currentEmployee.id + day",
@click="choiceCell(day, currentEmployee.id)",
:class="choiceState(day, currentEmployee.id)"
:id="selectEmployee.id + day",
@click="choiceCell(day, selectEmployee.id)",
:class="choiceState(day, selectEmployee.id)"
)
</template>
@@ -81,16 +80,14 @@ export default {
startMonth: Object,
clearEmployee: Array,
showTime: Boolean,
clearSelect: Function,
selectEmployee: Object,
},
data() {
return {
days: "",
result: [],
employee: [],
currentEmployee: {
label: "",
id: null,
},
dateInterval: {
id: "",
start: "",
@@ -98,6 +95,7 @@ export default {
text: "",
},
activeButton: null,
choiceMonth: null,
};
},
computed: {
@@ -143,9 +141,9 @@ export default {
setActiveButton() {
this.activeButton = this.buttons.find((e) => e.active);
},
choiceCell(time, id, schedule) {
choiceCell(day, id, schedule) {
if (this.showTime) return;
let formatTime = time.format("YYYY-MM-DD");
let formatTime = day.format("YYYY-MM-DD");
let insideSchedules = schedule?.schedules.filter(
(el) =>
(el.date > this.dateInterval.start &&
@@ -154,11 +152,7 @@ export default {
el.date === this.dateInterval.end
);
if (
this.dateInterval.start &&
this.dateInterval.end &&
this.dateInterval.id !== id
) {
if (this.dateInterval.id !== id) {
this.dateInterval.start = "";
this.dateInterval.end = "";
this.dateInterval.id = "";
@@ -167,13 +161,14 @@ export default {
if (!this.dateInterval.start) {
this.dateInterval.start = formatTime;
this.dateInterval.id = id;
} else if (time.isAfter(this.dateInterval.start)) {
this.$emit("schedule-employee", this.dateInterval, id);
} else if (day.isAfter(this.dateInterval.start)) {
this.dateInterval.end = formatTime;
this.$emit("schedule-employee", this.dateInterval, id);
} else this.dateInterval.start = formatTime;
if (
!this.currentEmployee.label &&
!this.selectEmployee.label &&
this.dateInterval.start &&
this.dateInterval.end &&
insideSchedules
@@ -206,12 +201,7 @@ export default {
start_date: moment(lastDate).add(1, "d").format("YYYY-MM-DD"),
end_date: this.dateInterval.end,
});
this.$emit(
"schedules",
insideSchedules,
outsideSchedules,
this.currentEmployee
);
this.$emit("schedules", insideSchedules, outsideSchedules);
},
choiceState(day, id) {
let formatDay = day.format("YYYY-MM-DD");
@@ -232,16 +222,11 @@ export default {
return {
status: (resStart || resMiddle || resEnd) && !!this.activeButton,
"set-time": this.showTime,
"from-date": !!resStart && !this.activeButton,
"to-date": !!resEnd && !this.activeButton,
"middle-dates": !!resMiddle && !this.activeButton,
"set-date":
(!!resStart || !!resMiddle || !!resEnd) && !this.activeButton,
};
},
clearData() {
this.currentEmployee.label = "";
this.currentEmployee.id = null;
},
choiceWorks(day, employee) {
if (this.showTime) {
return this.choiceTime(employee, day);
@@ -259,9 +244,10 @@ export default {
return this.buttons.find((e) => e.work === res)?.color;
},
changeDays() {
this.days = moment().daysInMonth();
this.days = moment(this.choiceMonth, "YYYY-MM-DD").daysInMonth();
},
pushMonth() {
this.result = [];
this.result.push(this.startMonth);
for (let i = 2; i <= this.days; i++) {
this.result.push(this.startMonth.clone().add(i - 1, "d"));
@@ -285,7 +271,18 @@ export default {
: "1";
},
},
watch: {
startMonth: {
immediate: true,
handler(newMonth) {
if (newMonth) {
this.choiceMonth = newMonth.format("YYYY-MM-DD");
this.changeDays();
this.pushMonth();
}
},
},
},
mounted() {
this.changeDays();
this.pushMonth();
@@ -318,7 +315,6 @@ export default {
border-top-right-radius: 2px
.schedule-select
border-top: 1.5px solid var(--border-light-grey-color-1)
&:hover
background-color: var(--border-light-grey-color-1)
@@ -339,6 +335,7 @@ export default {
.select-name
width: 25%
border-right: 1.5px solid var(--border-light-grey-color-1)
border-bottom: 1.5px solid var(--border-light-grey-color-1)
.name-employee
width: 25%
@@ -369,12 +366,6 @@ export default {
.status::after
content: var(--text-status)
.from-date
background-color: limegreen !important
.to-date
background-color: red !important
.middle-dates
background-color: yellow !important
.set-date
background-color: var(--btn-blue-color-4) !important
</style>