Commit 529568ba authored by vietanh-0511's avatar vietanh-0511

update product management

parent 2c2ff775
<!-- eslint-disable vue/require-v-for-key -->
<!-- eslint-disable vue/valid-v-slot -->
<template> <template>
<div> <div>
<div> <div>
...@@ -43,18 +41,16 @@ ...@@ -43,18 +41,16 @@
required required
/> />
</v-col> </v-col>
<v-col <v-col cols="12">
cols="12" <v-select
>
<v-treeview
v-model="category_id" v-model="category_id"
:items="categories" :items="categories"
:selection-type="independent" item-text="name"
:multiple-active="false"
shaped
hoverable
activatable
item-value="id" item-value="id"
menu-props="auto"
label="Select category"
hide-details
single-line
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -301,14 +297,15 @@ ...@@ -301,14 +297,15 @@
<v-col <v-col
cols="12" cols="12"
> >
<v-treeview <v-select
v-model="eCategoryId" v-model="eCategoryId"
:items="categories" :items="categories"
:selection-type="independent" item-text="name"
:multiple-active="false" item-value="id"
shaped menu-props="auto"
hoverable label="Select category"
activatable hide-details
single-line
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -389,7 +386,7 @@ ...@@ -389,7 +386,7 @@
dark dark
x-small x-small
color="red" color="red"
@click="removeVariant(index)" @click="removeVariant(index, variant.id)"
> >
<v-icon dark> <v-icon dark>
mdi-minus mdi-minus
...@@ -425,7 +422,7 @@ ...@@ -425,7 +422,7 @@
<v-data-table <v-data-table
:headers="headers" :headers="headers"
:items="products" :items="products"
sort-by="calories" sort-by="created_at"
class="elevation-1" class="elevation-1"
> >
<template #top> <template #top>
...@@ -435,6 +432,9 @@ ...@@ -435,6 +432,9 @@
<v-spacer /> <v-spacer />
</v-toolbar> </v-toolbar>
</template> </template>
<template #[`item.index`]="{ index }">
{{ index + 1 }}
</template>
<template #[`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
...@@ -464,7 +464,7 @@ export default { ...@@ -464,7 +464,7 @@ export default {
return { return {
name: '', name: '',
id: '', id: '',
category_id: [], category_id: '',
price: '', price: '',
stock: '', stock: '',
description: '', description: '',
...@@ -486,13 +486,13 @@ export default { ...@@ -486,13 +486,13 @@ export default {
options: [], options: [],
headers: [ headers: [
{ {
text: 'Name', text: '#',
align: 'start', align: 'start',
sortable: false, sortable: false,
value: 'name' value: 'index'
}, },
{ text: 'id', value: 'id' }, { text: 'name', value: 'name' },
{ text: 'category ID', value: 'category_id' }, { text: 'category', value: 'category.name' },
{ text: 'price', value: 'price', sortable: false }, { text: 'price', value: 'price', sortable: false },
{ text: 'description', value: 'description' }, { text: 'description', value: 'description' },
{ text: 'stock', value: 'stock' }, { text: 'stock', value: 'stock' },
...@@ -530,7 +530,7 @@ export default { ...@@ -530,7 +530,7 @@ export default {
], ],
eId: '', eId: '',
eName: '', eName: '',
eCategoryId: [], eCategoryId: '',
ePrice: '', ePrice: '',
eDescription: '', eDescription: '',
eStock: '', eStock: '',
...@@ -587,7 +587,7 @@ export default { ...@@ -587,7 +587,7 @@ export default {
this.images = [] this.images = []
this.products = [] this.products = []
this.product = [] this.product = []
this.categories = [] this.categories = ''
this.sName = '' this.sName = ''
this.sCategoryId = '' this.sCategoryId = ''
this.sPrice = '' this.sPrice = ''
...@@ -599,7 +599,6 @@ export default { ...@@ -599,7 +599,6 @@ export default {
color: '', color: '',
size: '', size: '',
quantity: '' quantity: ''
} }
] ]
}, },
...@@ -686,7 +685,7 @@ export default { ...@@ -686,7 +685,7 @@ export default {
, ,
{ {
headers: { headers: {
'Content-Type': 'application/json; 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; multipart/form-data' Accept: 'application/json; multipart/form-data'
} }
...@@ -706,6 +705,7 @@ export default { ...@@ -706,6 +705,7 @@ export default {
duration: 3000 duration: 3000
}) })
}) })
this.getProducts()
}, },
deleteProduct (ID, index) { deleteProduct (ID, index) {
const self = this const self = this
...@@ -803,6 +803,7 @@ export default { ...@@ -803,6 +803,7 @@ export default {
this.editedItem = response.data.data this.editedItem = response.data.data
Object.assign(this.products[currentPostIndex], this.editedItem) Object.assign(this.products[currentPostIndex], this.editedItem)
}) })
this.getProducts()
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
...@@ -824,18 +825,32 @@ export default { ...@@ -824,18 +825,32 @@ export default {
remove (index) { remove (index) {
this.variants.splice(index, 1) this.variants.splice(index, 1)
}, },
removeVariant (index) { removeVariant (index, id = null) {
if (confirm('Do you really want to delete?')) {
const self = this
if (id !== null) {
try {
this.$axios.post(`/products/delete-variant/${id}`,
{
headers: {
Authorization: `Bearer ${this.$auth.$storage.getUniversal('token')}`
}
}
).then((response) => {
self.$toast.success('Remove variant successfully!', {
duration: 3000
})
})
this.getProducts()
} catch (error) {
console.log(error)
}
}
this.eVariants.splice(index, 1) this.eVariants.splice(index, 1)
}
}, },
seeVariant () { seeVariant () {
console.log(this.variants) console.log(this.variants)
},
fetchCategories (item) {
return this.$axios
.get('/categories/')
.then(res => res.json())
.then(json => (item.children.push(...json)))
.catch(err => console.warn(err))
} }
} }
} }
......
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