From ee538bc2b5849b11e9ebe612424033451534e719 Mon Sep 17 00:00:00 2001 From: megavrilinvv Date: Fri, 30 Dec 2022 17:17:11 +0300 Subject: [PATCH 1/2] =?UTF-8?q?[WIP]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8,=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=20create=20and=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/schedule/TheSchedule.vue | 89 ++++++++++--------- .../schedule/components/ScheduleHeader.vue | 13 ++- .../{ScheduleBody.vue => ScheduleTable.vue} | 48 +++++++--- 3 files changed, 94 insertions(+), 56 deletions(-) rename src/pages/schedule/components/{ScheduleBody.vue => ScheduleTable.vue} (91%) diff --git a/src/pages/schedule/TheSchedule.vue b/src/pages/schedule/TheSchedule.vue index 7d7a8a3..bbe8dde 100644 --- a/src/pages/schedule/TheSchedule.vue +++ b/src/pages/schedule/TheSchedule.vue @@ -4,17 +4,19 @@ schedule-header( :start-month="startMonth", :times-shift="timesShift", + :change-show-time="changeShowTime", + :show-time="showTime" @switch-previous-month="switchPreviousMonth", @switch-next-month="switchNextMonth" ) - schedule-body( + schedule-table( :schedules-employee="fetchSchedulesEmployee", :schedule-list="scheduleList", :serialized="serialized", :buttons="buttons", :start-month="startMonth", :clear-employee="clearEmployee", - @new-schedule-employee="createNewScheduleEmployee", + :show-time="showTime", @schedule-employee="createScheduleEmployee", @schedules="distributeRequest" ) @@ -29,11 +31,12 @@ import * as moment from "moment"; import ScheduleHeader from "@/pages/schedule/components/ScheduleHeader.vue"; import ScheduleBar from "@/pages/schedule/components/ScheduleBar.vue"; -import ScheduleBody from "@/pages/schedule/components/ScheduleBody.vue"; +import ScheduleTable from "@/pages/schedule/components/ScheduleTable.vue"; import { fetchWrapper } from "@/shared/fetchWrapper.js"; + export default { name: "TheSchedule", - components: { ScheduleHeader, ScheduleBar, ScheduleBody }, + components: { ScheduleHeader, ScheduleBar, ScheduleTable }, data() { return { employeeList: [], @@ -69,6 +72,9 @@ export default { }, ], startMonth: moment().startOf("month"), + showTime: false, + currentEmployee: {}, + schedulesDate: {}, }; }, computed: { @@ -77,6 +83,9 @@ export default { }, }, methods: { + changeShowTime() { + this.showTime = !this.showTime; + }, fetchSchedules() { fetchWrapper .get("general/employee/") @@ -111,8 +120,8 @@ export default { schedules: [ { date: e.date, - end_time: e.end_time, - start_time: e.start_time, + end_time: e.end_time ? e.end_time.slice(0, -3) : "", + start_time: e.start_time ? e.start_time.slice(0, -3) : "", status: e.status, id: e.id, title: e.title, @@ -123,8 +132,8 @@ export default { } else { foundedElem.schedules.push({ date: e.date, - end_time: e.end_time, - start_time: e.start_time, + end_time: e.end_time ? e.end_time.slice(0, -3) : "", + start_time: e.start_time ? e.start_time.slice(0, -3) : "", status: e.status, id: e.id, title: e.title, @@ -138,67 +147,65 @@ export default { filterEmployee() { this.clearEmployee = []; this.clearEmployee = this.employeeList.filter((item) => - this.serialized.every((item2) => item2.id !== item.id) + this.serialized.every((el) => el.id !== item.id) ); }, - distributeRequest(inside, outside) { + distributeRequest(inside, outside, currentEmployee) { this.insideSchedules = inside; this.outsideSchedules = outside; + this.currentEmployee = currentEmployee; }, postCreateSchedules() { - 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); let data = { - employee: newSchedule.id, + employee: this.schedulesDate.id, active_flg: true, start_time: this.times.start_time, end_time: this.times.end_time, status: this.buttons.find((e) => e.active).work, }; - if (this.insideSchedules.length > 0) { + if (this.insideSchedules?.length > 0) { this.postUpdateSchedule(); - this.outsideSchedules.forEach((el) => { - fetchWrapper.post("accounts/schedules/create/", { - ...data, - start_date: el.start_date, - end_date: el.end_date, + if (this.outsideSchedules) + this.outsideSchedules.forEach((el) => { + fetchWrapper.post("accounts/schedules/create/", { + ...data, + start_date: el.start_date, + end_date: el.end_date, + }); }); - }); } else { - fetchWrapper.post("accounts/schedules/create/", { - ...data, - start_date: - newSchedule.schedules.start_date || newSchedule.schedule.start_date, - end_date: - newSchedule.schedules.end_date || newSchedule.schedule.end_date, - }); + fetchWrapper + .post("accounts/schedules/create/", { + ...data, + start_date: this.schedulesDate.start_date, + end_date: this.schedulesDate.end_date, + }) + .then(() => this.fetchSchedules()); } }, postUpdateSchedule() { let ids = ""; this.insideSchedules.forEach((e) => (ids += e.id + ",")); ids = ids.slice(0, -1); - fetchWrapper.post(`accounts/schedules/${ids}/update/`, { - employee: this.insideSchedules[0].employeeId, - active_flg: true, - start_time: this.insideSchedules[0].start_time, - end_time: this.insideSchedules[0].end_time, - status: this.buttons.find((e) => e.active).work, - }); + fetchWrapper + .post(`accounts/schedules/${ids}/update/`, { + employee: this.insideSchedules[0].employeeId, + active_flg: true, + start_time: this.times.start_time, + end_time: this.times.end_time, + status: this.buttons.find((e) => e.active).work, + }) + .then(() => this.fetchSchedules()); }, - createNewScheduleEmployee(e) { + createScheduleEmployee(e, id) { let schedules = { start_date: e.start, end_date: e.end, }; - this.clearEmployee.find((elem) => elem.id === e.id).schedules = schedules; - }, - createScheduleEmployee(e) { - let schedules = { + this.schedulesDate = { start_date: e.start, end_date: e.end, + id: id, }; this.serialized.find((elem) => elem.id === e.id).schedule = schedules; }, diff --git a/src/pages/schedule/components/ScheduleHeader.vue b/src/pages/schedule/components/ScheduleHeader.vue index 0282513..a182e8a 100644 --- a/src/pages/schedule/components/ScheduleHeader.vue +++ b/src/pages/schedule/components/ScheduleHeader.vue @@ -29,7 +29,13 @@ .text.flex.items-center .text.font-medium.text-base {{ dateString }} .opacity-50.font-bold.text-xxs.ml-2(v-if="isCurrentMonth") Текущий - base-button.font-semibold(:size="40", @click="openForm") Замена смен + .flex.gap-x-4 + base-button.font-semibold( + :size="40", + :style="{minWidth: '176px'}", + @click="changeShowTime" + ) {{textButton}} + base-button.font-semibold(:size="40", @click="openForm") Замена смен