Commit 3ac4c11d authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

Merge branch 'feature/update-product-UI' into 'feature/UI-vuetify'

Feature/update product ui

See merge request !16
parents 51ae5777 8a8a1a66
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
<script> <script>
export default { export default {
name: 'IndexPage' name: 'IndexPage',
middleware: ['web']
} }
</script> </script>
...@@ -126,8 +126,8 @@ export default { ...@@ -126,8 +126,8 @@ export default {
return response.json() return response.json()
}) })
console.log(resp.status) console.log(resp.status)
localStorage.setItem('token', resp.data.bearer_token) localStorage.setItem('token', 'Bearer ' + resp.data.bearer_token)
this.$auth.$storage.setUniversal('token', resp.data.bearer_token) this.$auth.$storage.setUniversal('token', 'Bearer ' + resp.data.bearer_token)
this.$auth.$storage.setUniversal('userName', resp.data.name) this.$auth.$storage.setUniversal('userName', resp.data.name)
this.$auth.$storage.setUniversal('loggedIn', 'true') this.$auth.$storage.setUniversal('loggedIn', 'true')
if (resp.status == 'success') { if (resp.status == 'success') {
......
<!-- eslint-disable vue/require-v-for-key -->
<!-- eslint-disable vue/valid-v-slot -->
<template> <template>
<div> <div>
<div> <div>
...@@ -43,15 +41,16 @@ ...@@ -43,15 +41,16 @@
required required
/> />
</v-col> </v-col>
<v-col <v-col cols="12">
cols="12"
>
<v-select <v-select
v-model="category_id" v-model="category_id"
:items="categories" :items="categories"
item-text="name" item-text="name"
item-value="id" item-value="id"
label="Category" menu-props="auto"
label="Select category"
hide-details
single-line
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -302,7 +301,10 @@ ...@@ -302,7 +301,10 @@
:items="categories" :items="categories"
item-text="name" item-text="name"
item-value="id" item-value="id"
label="Category" menu-props="auto"
label="Select category"
hide-details
single-line
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
...@@ -384,7 +386,7 @@ ...@@ -384,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
...@@ -416,12 +418,11 @@ ...@@ -416,12 +418,11 @@
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-dialog> </v-dialog>
<!-- table -->
<div> <div>
<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>
...@@ -431,6 +432,9 @@ ...@@ -431,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
...@@ -460,7 +464,7 @@ export default { ...@@ -460,7 +464,7 @@ export default {
return { return {
name: '', name: '',
id: '', id: '',
category_id: null, category_id: '',
price: '', price: '',
stock: '', stock: '',
description: '', description: '',
...@@ -483,13 +487,13 @@ export default { ...@@ -483,13 +487,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' },
...@@ -584,7 +588,7 @@ export default { ...@@ -584,7 +588,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 = ''
...@@ -596,7 +600,6 @@ export default { ...@@ -596,7 +600,6 @@ export default {
color: '', color: '',
size: '', size: '',
quantity: '' quantity: ''
} }
] ]
}, },
...@@ -703,6 +706,7 @@ export default { ...@@ -703,6 +706,7 @@ export default {
duration: 3000 duration: 3000
}) })
}) })
this.getProducts()
}, },
deleteProduct (ID, index) { deleteProduct (ID, index) {
const self = this const self = this
...@@ -768,16 +772,18 @@ export default { ...@@ -768,16 +772,18 @@ export default {
fd.append('price', this.ePrice) fd.append('price', this.ePrice)
fd.append('category_id', this.eCategoryId) fd.append('category_id', this.eCategoryId)
fd.append('description', this.eDescription) fd.append('description', this.eDescription)
if (this.eVariants) { for (let i = 0; i < this.eVariants.length; i++) {
for (let i = 0; i < this.eVariants.length; i++) { if (typeof this.eVariants[i].id !== 'undefined') {
fd.append(`variants[${i}][id]`, this.eVariants[i].id) fd.append(`variants[${i}][id]`, this.eVariants[i].id)
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)
} }
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++) { if (this.eImages) {
fd.append(`images[${j}]`, this.eImages[j]) for (let j = 0; j < this.eImages.length; j++) {
fd.append(`images[${j}]`, this.eImages[j])
}
} }
const currentPostIndex = this.editedIndex const currentPostIndex = this.editedIndex
try { try {
...@@ -798,6 +804,7 @@ export default { ...@@ -798,6 +804,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)
} }
...@@ -819,8 +826,29 @@ export default { ...@@ -819,8 +826,29 @@ export default {
remove (index) { remove (index) {
this.variants.splice(index, 1) this.variants.splice(index, 1)
}, },
removeVariant (index) { removeVariant (index, id = null) {
this.eVariants.splice(index, 1) 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)
}
}, },
seeVariant () { seeVariant () {
console.log(this.variants) console.log(this.variants)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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