Files
PORTAL_COD2/front/src/components/news-list.vue
T
2023-10-02 13:15:17 +03:00

232 lines
4.8 KiB
Vue

<template>
<v-container class="py-1 newsVH px-0 bg-transparent overflow-auto">
<v-card
class="mx-auto mb-0 "
v-for="(x, i) in newss" :key= i
>
<v-img
:src="`${burl}${x.link}`"
height="164px"
cover
/>
<v-card-title>
{{x.title}}
</v-card-title>
<v-card-subtitle>
{{limitText(x.text)}}
</v-card-subtitle>
<v-card-actions>
<v-btn
color="teal-accent-4"
variant="text"
>
{{x.author.fio}}
</v-btn>
<v-spacer></v-spacer>
<v-btn
:icon="x.show ? 'mdi-chevron-up' : 'mdi-chevron-down'"
@click="x.show = !x.show"
></v-btn>
</v-card-actions>
<v-expand-transition>
<div v-show="x.show">
<v-divider/>
<v-card-text>
{{x.text}}
</v-card-text>
<v-divider/>
<v-card-actions >
<v-row >
<v-col>
<v-btn
variant="text"
icon="mdi-thumb-up-outline"
color="blue-darken-3"
@click="toggleIncrementLike"
/>
{{ incrementLikes }}
</v-col>
<v-col class=" ml-8">
<v-btn
variant="text"
icon="mdi-message-text-outline"
color="teal"
@click="commentadd"
/>
{{ message }}
<v-btn
:icon="x.show ? 'mdi-chevron-up' : 'mdi-chevron-down'"
@click="x.show = !x.show"
></v-btn>
</v-col>
<v-col class="text-center pr-0">
<v-btn
variant="text"
icon="mdi-thumb-down-outline"
color="red-lighten-2"
@click="toggleDecrementLike"
/>
{{ derementLikes }}
</v-col>
</v-row>
</v-card-actions>
<v-divider class="mb-2"/>
</div>
</v-expand-transition>
<v-expand-transition>
<div v-show="commentShow">
Тут комменты
</div>
</v-expand-transition>
</v-card>
<v-row justify="center">
<v-dialog
v-model="dialogCommentShow"
persistent
width="550"
>
<v-card>
<v-card-title class="text-h5">
Прокоментировать новость
</v-card-title>
<v-card-text>
<v-textarea
variant="solo"
hide-details
rows="5"
></v-textarea>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="blue-darken-1"
variant="text"
@click="dialogCommentShow = false"
>
Отмена
</v-btn>
<v-btn
color="blue-darken-1"
variant="text"
@click="dialogCommentShow = false"
>
Отправить
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-row>
</v-container>
</template>
<script>
import { ref,computed,watch } from 'vue'
import {useAccountStore} from '@/store/AccountStore'
import {getfromserver} from '@/utils/universal_functions'
import { baseURL } from '@/utils/axios-api'
const accountStore = useAccountStore()
export default {
setup(){
const newss=ref([])
const show=ref(false)
const incrementLikes = ref(0)
const derementLikes = ref(0)
const likedI = ref(false)
const likedD = ref(false)
const message = ref(0)
const commentShow = ref(false)
const dialogCommentShow = ref(false)
const toggleIncrementLike = () => {
if (likedI.value) {
incrementLikes.value--
}
else {
incrementLikes.value++
if(likedD.value){
derementLikes.value--
likedD.value = false
}
}
likedI.value=!likedI.value
}
const toggleDecrementLike = () => {
if (likedD.value) {
derementLikes.value--
}
else {
derementLikes.value++
if(likedI.value){
incrementLikes.value--
likedI.value = false
}
}
likedD.value=!likedD.value
}
const burl = baseURL.slice(0,-1)
const limitText=(text)=> {
return text.split(' ').slice(0, 10).join(' ')
}
getfromserver("api/navigation/news/", newss)
watch(()=>accountStore.cod2user ,(newValue,oldValue)=>{
if(newValue){
getfromserver("api/navigation/news/",newss)
}
}, {deep:true})
const commentadd = () => {
dialogCommentShow.value=!dialogCommentShow.value
// commentShow.value =!commentShow.value
}
return {
newss,
show,
burl,
limitText,
incrementLikes,
derementLikes,
message,
commentShow,
toggleIncrementLike,
toggleDecrementLike,
dialogCommentShow,
commentadd
}
}
}
</script>
<style>
.newsVH {
height: 93vh;
}
</style>