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