<template>
<div>
// Тут интупы с v-modal
// ....
// Компонент который загружает картинки при выборе и отправляет в
// родительский компонент массив с именами картинок. А при обновлении
// карточки передается этот же массив в компонент для отображения имени
// картинки загруженной
<upload-image @images="getImages" :images="images"></upload-image>
// Кнопка сабмит
// btn
</div>
</template>
<script>
export default {
props: {
change: {
type: String,
required: true
},
data: {
type: Object,
default() {
return {}
}
}
},
data() {
return {
id: '',
title: '',
value: null,
options: this.tags,
checkbox: false,
refLink: '',
videoLink: '',
shortText: '',
summ: '',
srock: '',
stavka: '',
doc: '',
age: '',
identif: '',
job: '',
pereplata: '',
prodlenie: '',
ki: '',
conditionOne: '',
conditionTwo: '',
conditionTree: '',
conditionFour: '',
conditionFive: '',
conditionSix: '',
prevOne: '',
prevTwo: '',
prevThree: '',
tabOne: '',
tabTwo: '',
tabThree: '',
tabFour: '',
tabFive: '',
tabSix: '',
htmlText: '',
blockFive: ['','','',''],
images: []
}
},
async fetch() {
this.options = await this.$store.dispatch('tag/getAllTagsAdmin')
},
mounted() {
if(this.data) {
this.id = this.data._id,
this.images = this.data.images,
this.title = this.data.title
}
},
methods: {
async onSubmit() {
let tags = this.value.map(item => item)
try {
const formData = {
id: this.id,
tags: tags,
title: this.title,
premium: this.checkbox,
htmlText: this.htmlText,
images: this.images,
refLink: this.refLink,
videoLink: this.videoLink,
shortText: this.shortText,
summ: this.summ,
srock: this.srock,
stavka: this.stavka,
doc: this.doc,
age: this.age,
identif: this.identif,
job: this.job,
pereplata: this.pereplata,
prodlenie: this.prodlenie,
ki: this.ki,
conditionOne: this.conditionOne,
conditionTwo: this.conditionTwo,
conditionTree: this.conditionTree,
conditionFour: this.conditionFour,
conditionFive: this.conditionFive,
conditionSix: this.conditionSix,
prevOne: this.prevOne,
prevTwo: this.prevTwo,
prevThree: this.prevThree,
tabOne: this.tabOne,
tabTwo: this.tabTwo,
tabThree: this.tabThree,
tabFour: this.tabFour,
tabFive: this.tabFive,
tabSix: this.tabSix,
blockFive: this.blockFive
}
await this.$store.dispatch(`card/${this.change}`, formData)
alert(`Карточка ${this.change}`)
} catch(e) {
alert('Произошла ошибка')
}
},
getImages(data){
this.images = data
}
}
}
</script>
data() {
return {
title: '',
value: null,
options: this.tags,
checkbox: false,
refLink: '',
videoLink: '',
shortText: '',
summ: '',
srock: '',
stavka: '',
doc: '',
age: '',
identif: '',
job: '',
pereplata: '',
prodlenie: '',
ki: '',
conditionOne: '',
conditionTwo: '',
conditionTree: '',
conditionFour: '',
conditionFive: '',
conditionSix: '',
prevOne: '',
prevTwo: '',
prevThree: '',
tabOne: '',
tabTwo: '',
tabThree: '',
tabFour: '',
tabFive: '',
tabSix: '',
htmlText: '',
blockFive: ['','','',''],
images: []
}
},
const Tag = require('../models/tag.model')
const Card = require('../models/card.model')
const Post = require('../models/post.model')
module.exports.getData = async (req, res) => {
try {
const tag = await Tag.findOne({tag: req.params.data}, function(err, tag) {
console.log(tag);
res.json(tag)
})
if(tag === null) {
await (await Card.findOne({card: req.params.data}).populate('comments')).execPopulate((error, card) => {
res.json(card)
})
} else {
await (await Post.findOne({post: req.params.data}).populate('comments')).execPopulate((error, post) => {
res.json(post)
})
}
} catch(e) {
res.status(500).json(e)
}
}