From ae721f23273070cb9ede1ef1b136ab8e104f3131 Mon Sep 17 00:00:00 2001 From: megavrilinvv Date: Tue, 27 Dec 2022 18:42:00 +0300 Subject: [PATCH] =?UTF-8?q?[WIP]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0=20=D0=B4=D0=B0=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B0=D0=BF=D0=B4=D0=B5=D0=B9=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/schedule/TheSchedule.vue | 26 ++++++++--- .../schedule/components/ScheduleBody.vue | 46 +++++++++++++++++-- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/pages/schedule/TheSchedule.vue b/src/pages/schedule/TheSchedule.vue index b80f6a8..8a607f8 100644 --- a/src/pages/schedule/TheSchedule.vue +++ b/src/pages/schedule/TheSchedule.vue @@ -15,7 +15,8 @@ :buttons="buttons", :start-month="startMonth", :clear-employee="clearEmployee", - @new-date="createNewDate" + @new-schedule-employee="createNewScheduleEmployee", + @schedule-employee="createScheduleEmployee" ) schedule-bar( :data-schedule="dataSchedule", @@ -148,13 +149,19 @@ export default { ); }, postCreateSchedule() { - let currentEmployee = this.clearEmployee.find((e) => e.schedules); + let newSchedule = null; + if (this.clearEmployee.find((e) => e.schedules)) + newSchedule = this.clearEmployee.find((e) => e.schedules); + else newSchedule = this.serialized.find((e) => e.schedule); + fetchWrapper .post("accounts/schedules/create/", { - employee: currentEmployee.id, + employee: newSchedule.id, active_flg: true, - start_date: currentEmployee.schedules.start_date, - end_date: currentEmployee.schedules.end_date, + start_date: + newSchedule.schedules.start_date || newSchedule.schedule.start_date, + end_date: + newSchedule.schedules.end_date || newSchedule.schedule.end_date, start_time: this.times.start_time, end_time: this.times.end_time, status: this.buttons.find((e) => e.active).work, @@ -175,13 +182,20 @@ export default { }) .then(() => this.fetchSchedules()); }, - createNewDate(e) { + createNewScheduleEmployee(e) { let schedules = { start_date: e.start, end_date: e.end, }; this.clearEmployee.find((elem) => elem.id === e.id).schedules = schedules; }, + createScheduleEmployee(e) { + let schedules = { + start_date: e.start, + end_date: e.end, + }; + this.serialized.find((elem) => elem.id === e.id).schedule = schedules; + }, switchPreviousMonth() { this.startMonth = this.startMonth.clone().subtract(1, "M"); }, diff --git a/src/pages/schedule/components/ScheduleBody.vue b/src/pages/schedule/components/ScheduleBody.vue index eaad47a..bc39a4f 100644 --- a/src/pages/schedule/components/ScheduleBody.vue +++ b/src/pages/schedule/components/ScheduleBody.vue @@ -24,12 +24,12 @@ v-for="day in result", :key="day", :id="schedule.id + day", - @click="choiceCell(day, schedule.id)", + @click="choiceCell(day, schedule.id, schedule)", :class="selectTime(day, schedule.id)", :style="{backgroundColor: choiceDay(day, schedule.id) ? choiceColor(day) : ''}" ) .flex {{choiceDay(day, schedule.id) ? choiceWorks(day) : ''}} - .schedule-body.flex.w-full(v-if="clearEmployee", :style="{height: '44px'}") + .schedule-body.flex.w-full(v-if="clearEmployee", :style="{height: '44px'}", v-click-outside="saveEmployee") .edit.flex.items-center.justify-center.h-11.w-11(:style="{borderBottom: 'none'}") .flex.icon-edit(v-if="currentEmployee.label") //- base-button( @@ -136,7 +136,7 @@ export default { setActiveButton() { this.activeButton = this.buttons.find((e) => e.active); }, - choiceCell(time, id) { + choiceCell(time, id, schedule) { let formatTime = time.format("YYYY-MM-DD"); if ( this.dateInterval.start && @@ -152,9 +152,45 @@ export default { this.dateInterval.id = id; } else if (time.isAfter(this.dateInterval.start)) { this.dateInterval.end = formatTime; - if (this.currentEmployee.label) - this.$emit("new-date", this.dateInterval); + if (this.currentEmployee.label) { + this.$emit("new-schedule-employee", this.dateInterval); + } else this.$emit("schedule-employee", this.dateInterval); } else this.dateInterval.start = formatTime; + if ( + !this.currentEmployee.label && + this.dateInterval.start && + this.dateInterval.end + ) + this.rangeSchdedules(schedule); + }, + rangeSchdedules(schedule) { + let insideSchedules = schedule.schedules.filter( + (el) => + (el.date > this.dateInterval.start && + el.date < this.dateInterval.end) || + el.date === this.dateInterval.start || + el.date === this.dateInterval.end + ); + let keys = Object.keys(insideSchedules); + let outsideSchedules = []; + let firstDate = insideSchedules[keys[0]].date; + let lastDate = insideSchedules[keys.length - 1].date; + + if (this.dateInterval.start < firstDate) { + outsideSchedules.push({ + before: { + start_date: this.dateInterval.start, + end_date: moment(firstDate).subtract(1, "d").format("YYYY-MM-DD"), + }, + }); + } + if (this.dateInterval.end > lastDate) + outsideSchedules.push({ + after: { + start_date: moment(lastDate).add(1, "d").format("YYYY-MM-DD"), + end_date: this.dateInterval.end, + }, + }); }, selectTime(day, id) { let formatDay = day.format("YYYY-MM-DD");