262 lines
7.6 KiB
Vue
262 lines
7.6 KiB
Vue
<template>
|
||
<v-dialog v-model="dialog_create_calendar" min-width="636" max-width="800">
|
||
<dialog-create
|
||
:title="titleCard"
|
||
:newOrOld="newCalendar"
|
||
@closeDialog="dialog_create_calendar = false"
|
||
@delObject="delCalendar(propsCalendar.id)"
|
||
@postData="postCalendar"
|
||
>
|
||
<template v-slot:card_text>
|
||
<v-row no-gutters class="flex-column">
|
||
<v-col class="d-flex flex-column">
|
||
<v-row no-gutters class="align-center">
|
||
<v-col class="text-body-2 text-text_grey pb-5" lg="2">
|
||
Название
|
||
</v-col>
|
||
<v-col>
|
||
<v-textarea
|
||
density="compact"
|
||
label="Описание"
|
||
row-height="25"
|
||
rows="1"
|
||
variant="outlined"
|
||
v-model="propsCalendar.cl_name"
|
||
:rules="rules.cl_name"
|
||
></v-textarea></v-col
|
||
></v-row>
|
||
<v-row no-gutters class="align-center pb-3">
|
||
<v-col class="text-body-2 text-text_grey" lg="2"> Цвет </v-col>
|
||
<v-col v-for="(x, key) in color" :key="key">
|
||
<v-avatar
|
||
class="cursor-pointer"
|
||
@click="colorPik(x, key)"
|
||
size="x-small"
|
||
:color="x"
|
||
:variant="
|
||
propsCalendar.cl_color === null
|
||
? 'flat'
|
||
: propsCalendar.cl_color === x
|
||
? 'flat'
|
||
: 'tonal'
|
||
"
|
||
/> </v-col
|
||
></v-row>
|
||
|
||
<v-row no-gutters class="align-center pb-3">
|
||
<v-col class="text-body-2 text-text_grey" lg="2">
|
||
Участники
|
||
</v-col>
|
||
<v-col>
|
||
<calendar-create-select
|
||
:participant="propsCalendar.participant"
|
||
@returnIdParticant="returnIdParticant"
|
||
/> </v-col
|
||
></v-row>
|
||
</v-col>
|
||
<v-col class="d-flex flex-grow-0">
|
||
<v-textarea
|
||
density="compact"
|
||
label="Описание"
|
||
row-height="25"
|
||
rows="4"
|
||
variant="outlined"
|
||
shaped
|
||
no-resize
|
||
:rules="rules.cl_descr"
|
||
v-model="propsCalendar.cl_descr"
|
||
></v-textarea>
|
||
</v-col>
|
||
<v-row no-gutters class="align-center">
|
||
<v-col class="text-body-2 text-text_grey" lg="2"> Редакторы </v-col>
|
||
<v-col>
|
||
<calendar-create-select
|
||
:editor="true"
|
||
:participant="
|
||
propsCalendar.participant.filter((e) => e.editor == 1)
|
||
"
|
||
@returnIdParticant="returnIdParticant"
|
||
/>
|
||
</v-col>
|
||
<v-col lg="1" class="text-center">
|
||
<v-tooltip location="top">
|
||
<template v-slot:activator="{ props }">
|
||
<v-icon v-bind="props" icon="mdi-help-circle-outline" />
|
||
</template>
|
||
<div class="custom-tooltip">
|
||
Участники с доступом редактирования смогут изменять поля
|
||
календаря, а также редактировать и удалять события
|
||
</div>
|
||
</v-tooltip>
|
||
</v-col>
|
||
</v-row>
|
||
</v-row>
|
||
</template>
|
||
</dialog-create>
|
||
</v-dialog>
|
||
</template>
|
||
|
||
<script>
|
||
import { computed, ref, watch } from "vue";
|
||
import { axiosApiInstance } from "@/utils/axios-api";
|
||
import calendarCreateSelect from "@/components/calendar_of_events/calendar-create-select.vue";
|
||
import { useAlertStore } from "@/store/useAlertStore";
|
||
import { useAccountStore } from "@/store/AccountStore";
|
||
import DialogCreate from "./UI_calendar/dialogCreate.vue";
|
||
|
||
export default {
|
||
components: { calendarCreateSelect, DialogCreate },
|
||
|
||
props: {
|
||
opendialog: {
|
||
type: Boolean,
|
||
default: false,
|
||
},
|
||
|
||
calendar: {
|
||
type: Object,
|
||
default: {},
|
||
},
|
||
},
|
||
|
||
setup(props, { emit }) {
|
||
const postParticant = {};
|
||
const form_calendar = ref(null);
|
||
|
||
const accountStore = useAccountStore();
|
||
// Возможно можно сделать запись короче
|
||
const returnIdParticant = (idPart) => {
|
||
postParticant.value = { ...props.calendar, participant: idPart };
|
||
};
|
||
|
||
const dialog_create_calendar = computed({
|
||
get: () => props.opendialog,
|
||
set: (value) => emit("update:opendialog", value),
|
||
});
|
||
|
||
const propsCalendar = computed({
|
||
get: () => props.calendar,
|
||
set: (value) => emit("update:calendar", value),
|
||
});
|
||
|
||
const feedalert = useAlertStore().alert;
|
||
const rules = {
|
||
cl_name: [(val) => req(val)],
|
||
cl_descr: [(val) => req(val)],
|
||
};
|
||
|
||
const titleCard = ref("");
|
||
const newCalendar = ref(false);
|
||
|
||
const calendarNewOrOld = () => {
|
||
if (propsCalendar.value.hasOwnProperty("id")) {
|
||
titleCard.value = "Редактирование календаря";
|
||
} else {
|
||
titleCard.value = "Новый календарь";
|
||
newCalendar.value = true;
|
||
}
|
||
};
|
||
|
||
watch(
|
||
() => dialog_create_calendar,
|
||
(newValue, oldValue) => {
|
||
if (newValue) {
|
||
calendarNewOrOld();
|
||
}
|
||
},
|
||
{ deep: true }
|
||
);
|
||
|
||
const postCalendar = (val) => {
|
||
if (val.isValid) {
|
||
if (
|
||
postParticant.value.participant.some(
|
||
(e) => e.participant_calendar == accountStore.user.is_idEmployee
|
||
)
|
||
) {
|
||
axiosApiInstance
|
||
.post(`api/calendar_of_events/my_calendars/`, postParticant.value)
|
||
.then((result) => {
|
||
feedalert.alert = true;
|
||
feedalert.text = result.data.mess;
|
||
feedalert.ico = "mdi-check";
|
||
feedalert.color = "green-darken-4";
|
||
emit("getCalendar");
|
||
dialog_create_calendar.value = false;
|
||
});
|
||
} else {
|
||
feedalert.alert = true;
|
||
feedalert.text = "Вы не можете удалить себя из редакторов";
|
||
feedalert.color = "red-darken-2";
|
||
feedalert.ico = "mdi-alert-outline";
|
||
}
|
||
}
|
||
};
|
||
|
||
const color = [
|
||
"red",
|
||
"pink",
|
||
"deep-orange",
|
||
"amber",
|
||
"yellow",
|
||
"lime",
|
||
"light-green",
|
||
"green",
|
||
"light-blue",
|
||
"blue",
|
||
"indigo",
|
||
"deep-purple",
|
||
"purple",
|
||
"blue-grey",
|
||
"brown",
|
||
];
|
||
|
||
const colorPik = (col) => {
|
||
if (propsCalendar.value.cl_color === col) {
|
||
propsCalendar.value.cl_color = null;
|
||
} else {
|
||
propsCalendar.value.cl_color = col;
|
||
}
|
||
};
|
||
|
||
const delCalendar = (idcal) => {
|
||
axiosApiInstance
|
||
.delete(`api/calendar_of_events/my_calendars/?delid=${idcal}`)
|
||
.then((result) => {
|
||
feedalert.alert = true;
|
||
feedalert.text = result.data.mess;
|
||
feedalert.ico = "mdi-check";
|
||
feedalert.color = "orange-accent-1";
|
||
emit("getCalendar");
|
||
});
|
||
dialog_create_calendar.value = false;
|
||
};
|
||
|
||
const req = (val) => {
|
||
return !!val || "Поле обязательно";
|
||
};
|
||
|
||
return {
|
||
dialog_create_calendar,
|
||
|
||
postCalendar,
|
||
color,
|
||
colorPik,
|
||
returnIdParticant,
|
||
propsCalendar,
|
||
delCalendar,
|
||
rules,
|
||
form_calendar,
|
||
titleCard,
|
||
newCalendar,
|
||
};
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style>
|
||
.custom-tooltip {
|
||
max-width: 350px; /* Установка максимальной ширины для подсказки */
|
||
}
|
||
</style>
|