Commit 8f5824af authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

fix post creen

parents 100f3021 b2fb2547
This diff is collapsed.
......@@ -247,10 +247,9 @@
<v-file-input
v-model="eImages"
label="File input"
accept="image/*"
small-chips
dense
multiple
:state="Boolean(eImages)"
/>
</v-col>
</v-row>
......@@ -270,7 +269,7 @@
color="blue darken-1"
text
type="submit"
@click="dialog = false;"
@click="dialog = false; updatePost()"
>
Save
</v-btn>
......@@ -382,7 +381,7 @@
<v-spacer />
</v-toolbar>
</template>
<template v-slot:[`item.actions`]="{ item }">
<template #[`item.actions`]="{ item }">
<v-icon :id="item.id" small @click="editPost(item)">
mdi-pencil
</v-icon>
......@@ -472,11 +471,11 @@ export default {
sImages: null,
eId: '',
eTitle: '',
eCategoryId: '',
eCategoryId: [],
eContent: '',
eUserId: '',
eStatus: '',
eImages: null,
eImages: [],
message: [],
editedIndex: -1,
editedItem: {
......@@ -593,19 +592,18 @@ export default {
},
createPost () {
const self = this
const fd = new FormData()
fd.append('title', this.title)
fd.append('category_id', this.category_id)
fd.append('content', this.content)
fd.append('images', this.images)
fd.append('status', this.status)
this.$axios
.post('/posts/',
{
title: this.title,
category_id: this.category_id,
content: this.content,
images: this.images,
user_id: this.user_id,
status: this.status
},
fd,
{
headers: {
'Content-Type': 'application/json; multipart/form-data; boundary=---------------------------974767299852498929531610575 ',
'Content-Type': 'multipart/form-data; application/json',
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
}
}
......@@ -619,8 +617,6 @@ export default {
this.posts.push(this.editedItem)
})
.catch((errors) => {
console.log(errors.response.data.message)
this.message = errors.response.data.message
self.$toast.error('something went wrong while trying create!', {
duration: 3000
})
......@@ -665,7 +661,6 @@ export default {
this.sTitle = resp.data.data.title
this.sContent = resp.data.data.content
this.sCategoryId = resp.data.data.category_id
this.sUserId = resp.data.data.user_id
this.sStatus = resp.data.data.status
this.sImages = resp.data.data.images
} catch (error) {
......@@ -679,27 +674,29 @@ export default {
this.eCategoryId = item.category_id
this.eContent = item.content
this.eStatus = item.status
this.eUserId = item.user_id
this.editedIndex = this.posts.indexOf(item)
console.log(this.editedIndex)
this.dialog = true
},
updatePost () {
const self = this
const fd = new FormData()
fd.append('title', this.eTitle)
fd.append('category_id', this.eCategoryId)
fd.append('content', this.eContent)
fd.append('images', this.eImages)
fd.append('status', this.eStatus)
const currentPostIndex = this.editedIndex
this.$axios
.post(
`/posts/update/${this?.eId}`,
{
title: this.eTitle,
category_id: this.eCategoryId,
content: this.eContent,
images: this.eImages,
user_id: this.eUserId,
status: this.eStatus
},
fd,
{
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`,
Accept: 'application/json, text/plain, */*'
}
}
)
......@@ -707,10 +704,8 @@ export default {
self.$toast.success('Post updated successfully!', {
duration: 3000
})
console.log(response)
this.editedItem = response.data.data
this.$bvModal.hide('modal-edit')
Object.assign(this.posts[this.editedIndex], this.editedItem)
Object.assign(this.posts[currentPostIndex], this.editedItem)
})
.catch((error) => {
console.log(error)
......
......@@ -72,7 +72,6 @@
small-chips
dense
multiple
:state="Boolean(images)"
/>
</v-col>
<v-col cols="12">
......@@ -148,7 +147,7 @@
<v-btn
color="blue darken-1"
text
@click="dialog1 = false"
@click="dialog1 = false; seeVariant()"
>
Close
</v-btn>
......@@ -718,7 +717,7 @@
<v-spacer />
</v-toolbar>
</template>
<template v-slot:[`item.actions`]="{ item }">
<template #[`item.actions`]="{ item }">
<v-icon :id="item.id" small @click="editProduct(item)">
mdi-pencil
</v-icon>
......@@ -948,17 +947,20 @@ export default {
const self = this
// const set = new Set([this.images])
// const images = Array.from(set)
const fd = new FormData()
fd.append('name', this.name)
fd.append('price', this.price)
fd.append('category_id', this.category_id)
fd.append('description', this.description)
fd.append('image', this.images)
fd.append('variants', this.variants)
this.$axios
.post('/products/', {
name: this.name,
price: this.price,
category_id: this.category_id,
description: this.description,
images: this.images,
variants: this.variants
}, {
.post('/products/',
fd
,
{
headers: {
'Content-Type': 'application/json; multipart/form-data; boundary=---------------------------974767299852498929531610575 ',
'Content-Type': 'application/json; multipart/form-data ',
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`,
Accept: 'application/json; multipart/form-data'
}
......@@ -1085,6 +1087,9 @@ export default {
},
removeVariant (index) {
this.eVariants.splice(index, 1)
},
seeVariant () {
console.log(this.variants)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment