Commit 02906955 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

fix formdata

parent 8f5824af
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
color="blue darken-1" color="blue darken-1"
text text
type="submit" type="submit"
@click="dialog2 = false; createPost();" @click="dialog2 = false;"
> >
Save Save
</v-btn> </v-btn>
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
label="File input" label="File input"
small-chips small-chips
dense dense
accept="image/*"
multiple multiple
/> />
</v-col> </v-col>
...@@ -276,7 +277,7 @@ ...@@ -276,7 +277,7 @@
> >
<v-card> <v-card>
<v-card-title> <v-card-title>
<span class="text-h5">CREAT PRODUCT</span> <span class="text-h5">EDIT PRODUCT</span>
</v-card-title> </v-card-title>
<v-card-text> <v-card-text>
<v-container> <v-container>
...@@ -323,7 +324,6 @@ ...@@ -323,7 +324,6 @@
small-chips small-chips
dense dense
multiple multiple
:state="Boolean(images)"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -407,7 +407,7 @@ ...@@ -407,7 +407,7 @@
color="blue darken-1" color="blue darken-1"
text text
type="submit" type="submit"
@click="dialog3 = false; editProduct();" @click="dialog3 = false; updateProduct();"
> >
Save Save
</v-btn> </v-btn>
...@@ -758,6 +758,9 @@ export default { ...@@ -758,6 +758,9 @@ export default {
quantity: '' quantity: ''
} }
], ],
color: '',
size: '',
quantity: '',
dialog1: false, dialog1: false,
dialog2: false, dialog2: false,
dialog3: false, dialog3: false,
...@@ -790,6 +793,7 @@ export default { ...@@ -790,6 +793,7 @@ export default {
href: '/products' href: '/products'
} }
], ],
i: '',
products: [], products: [],
product: [], product: [],
categories: [], categories: [],
...@@ -945,15 +949,19 @@ export default { ...@@ -945,15 +949,19 @@ export default {
}, },
createProduct () { createProduct () {
const self = this const self = this
// const set = new Set([this.images])
// const images = Array.from(set)
const fd = new FormData() const fd = new FormData()
fd.append('name', this.name) fd.append('name', this.name)
fd.append('price', this.price) fd.append('price', this.price)
fd.append('category_id', this.category_id) fd.append('category_id', this.category_id)
fd.append('description', this.description) fd.append('description', this.description)
fd.append('image', this.images) for (let i = 0; i < this.variants.length; i++) {
fd.append('variants', this.variants) fd.append(`variants[${i}][color]`, this.variants[i].color)
fd.append(`variants[${i}][quantity]`, this.variants[i].quantity)
fd.append(`variants[${i}][size]`, this.variants[i].size)
}
for (let j = 0; j < this.images.length; j++) {
fd.append(`images[${j}]`, this.images[j])
}
this.$axios this.$axios
.post('/products/', .post('/products/',
fd fd
...@@ -1039,16 +1047,23 @@ export default { ...@@ -1039,16 +1047,23 @@ export default {
}, },
updateProduct (ID) { updateProduct (ID) {
const self = this const self = this
const fd = new FormData()
fd.append('name', this.eName)
fd.append('price', this.ePrice)
fd.append('category_id', this.eCategoryId)
fd.append('description', this.eDescription)
for (let i = 0; i < this.eVariants.length; i++) {
fd.append(`variants[${i}][color]`, this.eVariants[i].color)
fd.append(`variants[${i}][quantity]`, this.eVariants[i].quantity)
fd.append(`variants[${i}][size]`, this.eVariants[i].size)
}
for (let j = 0; j < this.eImages.length; j++) {
fd.append(`images[${j}]`, this.eImages[j])
}
try { try {
this.$axios this.$axios
.post(`/products/update/${this?.eId}`, { .post(`/products/update/${this?.eId}`,
name: this.eName, fd, {
price: this.ePrice,
category_id: this.eCategoryId,
description: this.eDescription,
images: this.eImages,
variants: this.eVariants
}, {
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')}`
......
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