[WIP] Добавил отображение рабочего времени, фикс create and update

This commit is contained in:
megavrilinvv
2022-12-30 17:17:11 +03:00
parent 2b13957fe2
commit ee538bc2b5
3 changed files with 94 additions and 56 deletions

View File

@@ -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;
},