Files
PORTAL_COD2/front/src/components/cardLike.vue
T
2023-09-08 09:59:00 +03:00

194 lines
4.9 KiB
Vue

<template>
<v-card class="pt-2">
<v-card-title>
<span class="text-h5">Обратная связь</span>
</v-card-title>
<v-card-text class="px-2 py-0">
<v-container>
<v-row>
<v-col class="flex-grow-0 py-0 text-no-wrap align-self-center text-button">
Оцените сайт
</v-col>
<v-divider/>
</v-row>
<v-row
v-for="(x, key) in t_baseCriteria"
:key = key
>
<v-col class="flex-grow-0 pb-0">
<v-icon
size="large"
:color="x.color"
:icon="x.ico"
/>
</v-col>
<v-col class="pb-0" lg=3>
{{x.name}}
</v-col>
<v-col class="py-0">
<v-rating
v-model="x.rating"
hover
half-increments
size="small"
color="yellow-darken-3"
/>
</v-col>
<v-divider/>
</v-row >
<v-row class="mt-6">
<v-col class="pa-0 px-3">
<v-textarea
label="Ваши комментарии сделают портал лучше"
hide-details
variant="outlined"
rows="5"
row-height="15"
v-model="comment"
/>
</v-col>
</v-row>
</v-container>
</v-card-text>
<v-card-actions class="pt-0">
<small v-if="average < 5 || comment.length > 0" class="pl-5">
Вы оценили сайт на <span class="font-weight-black">{{average}}</span> {{myLabel()}}
</small>
<v-spacer/>
<v-btn
color="blue-darken-1"
variant="text"
text="Закрыть"
@click="menusCloses"
/>
<v-btn
v-if="tab_userComment.length=0"
color="blue-darken-1"
variant="text"
text="Отправить"
@click="feedAll"
/>
<v-btn
v-else
color="blue-darken-1"
variant="text"
text="Обновить"
@click="proba"
/>
</v-card-actions>
</v-card>
</template>
<script>
import { ref, onMounted, computed } from 'vue'
import { axiosApiInstance } from '@/utils/axios-api'
export default {
props: {
LikeDialog: {
type: Boolean,
default: false
}
},
setup(props, context) {
const comment = ref("")
const t_baseCriteria = ref([])
const tab_userComment = ref([])
const t_userComment = ref([])
onMounted(() => {
axiosApiInstance.get('api/feedback/baseCriteria/')
.then(data => {
t_baseCriteria.value = data.data.results
})
axiosApiInstance.get(`api/feedback/userComment/`)
.then(data => {
t_userComment.value = data.data.results
})
})
function feedAll() {
const feedObj = {}
feedObj.ratingstatus = ratingStatus.value.decFeed
feedObj.comment = comment.value
axiosApiInstance.post('api/feedback/formfeed/', feedObj)
comment.value=""
t_baseCriteria.value.map(e=>e.rating=5)
}
function feedUp() {
const feedObj = {}
feedObj.comment = comment.value
feedObj.ratingstatus = ratingStatus.value.decFeed
axiosApiInstance.put('api/feedback/formupdate/', feedObj)
}
const ratingStatus = computed(() => {
const decFeed = []
t_baseCriteria.value.map(e =>
{
const { id, rating } = {...e}
decFeed.push({id:id, rating:rating})
});
return { decFeed }
});
const average = computed(()=> {
const sum = t_baseCriteria.value.reduce((total, obj)=> total + obj.rating, 0)
const sumlen = sum/t_baseCriteria.value.length
const ukr = Number.isInteger(sumlen)?sumlen:sumlen.toFixed(1)
return ukr
})
function myLabel() {
let labels = ''
if (average.value > 0 && average.value <= 3)
labels = 'УПС-С! Мы обязательно все исправим'
else if (average.value > 2 && average.value <= 4)
labels = 'Спасибо за обратную связь, мы обратим на это внимание'
else if (average.value > 4 && average.value < 5)
labels = 'Класс, будем стараться до 5'
else
labels = "Спасибо за отзыв и высокую оценку ^__^"
return labels
}
function menusCloses() {
context.emit('menusClose')
}
function proba() {
const feedObj = {}
feedObj.comment = comment.value
axiosApiInstance.post(`api/feedback/userComment/`, feedObj)
// console.log(t_userComment.value, 't_userComment.value');
}
return {t_baseCriteria, tab_userComment, comment, average, feedAll, feedUp, menusCloses, myLabel, proba}
}
}
</script>
<style>
.custom_subtitle {
opacity: 1;
}
.v-selection-control__input {
width: 46%!important;
height: 46%!important;
border-radius: 0!important;
}
</style>