Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
K
kiaisoft_tuananh_nuxt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TTS Tran Viet Anh
kiaisoft_tuananh_nuxt
Commits
c83e5638
Commit
c83e5638
authored
Jan 16, 2023
by
TTS Kieu Tuan Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
index products
parent
0a773156
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
318 additions
and
31 deletions
+318
-31
CreateProductModal.vue
components/CreateProductModal.vue
+59
-27
products.vue
pages/home/products.vue
+259
-4
No files found.
components/
DynamicInput
.vue
→
components/
CreateProductModal
.vue
View file @
c83e5638
<
template
>
<div
class=
"hello"
>
<h1>
{{
msg
}}
</h1>
<div>
<b-button
v-b-modal
.
modal-edit
>
New Category
</b-button>
<b-modal
id=
"modal-edit"
title=
"Edit Category"
class=
"modal fade"
>
<div
class=
"w-full mt-4 p-10"
>
<form
@
submit.prevent=
"getInfo"
>
<label>
Name :
</label>
...
...
@@ -11,6 +12,7 @@
v-model=
"name"
max=
"255"
min=
"1"
size=
"sm"
required
/>
<label>
Category ID :
</label>
...
...
@@ -19,6 +21,7 @@
class=
"form-control mb-2"
placeholder=
"Parent ID"
v-model=
"category_id"
size=
"sm"
/>
<label>
Price :
</label>
...
...
@@ -26,36 +29,62 @@
type=
"text"
class=
"form-control mb-2"
placeholder=
"Ordering"
v-model=
"ordering"
v-model=
"price"
size=
"sm"
required
/>
<label>
Description :
</label>
<input
type=
"text"
class=
"form-control mb-2"
placeholder=
"Description"
v-model=
"description"
size=
"sm"
required
/>
<label>
Stock :
</label>
<input
type=
"text"
class=
"form-control mb-2"
placeholder=
"Stock"
v-model=
"stock"
size=
"sm"
required
/>
<label>
Image :
</label>
<b-form-file
v-model=
"image"
:state=
"Boolean(image)"
placeholder=
"Choose a image or drop it here..."
drop-placeholder=
"Drop file here..."
></b-form-file>
<button
type=
"button"
class=
"flex justify-start ml-2 rounded-md border px-3 py-2 bg-pink-600
text-white
"
class=
"flex justify-start ml-2 rounded-md border px-3 py-2 bg-pink-600 "
@
click=
"addMore()"
>
Add More
Variant (+)
</button>
<div
v-for=
"(variant, index) in variants"
:key=
"index"
>
<div
class=
"flex justify-start ml-2 mt-4"
>
<input
v-model=
"variant.variant
Name
"
placeholder=
"
enter you variant name
"
v-model=
"variant.variant
Color
"
placeholder=
"
Color
"
class=
"w-full py-2 border border-indigo-500 rounded"
/>
<input
v-model=
"variant.variant
Index
"
placeholder=
"
enter you variantIndex
"
v-model=
"variant.variant
Size
"
placeholder=
"
Size
"
class=
"w-full py-2 border border-indigo-500 rounded"
/>
<input
v-model=
"variant.variant
Price
"
placeholder=
"
enter you variantPrice
"
v-model=
"variant.variant
Quantity
"
placeholder=
"
Quantity
"
class=
"w-full py-2 border border-indigo-500 rounded"
/>
<button
type=
"button"
class=
"ml-2 rounded-md border px-3 py-2 bg-red-600
text-white
"
class=
"ml-2 rounded-md border px-3 py-2 bg-red-600"
@
click=
"remove(index)"
v-show=
"index != 0"
>
...
...
@@ -63,28 +92,27 @@
</button>
</div>
</div>
<b-button
type=
"submit"
variant=
"primary"
>
Submit
</b-button>
</form>
</div>
</div>
</b-modal>
</div>
</
template
>
<
script
>
export
default
{
name
:
"
HelloWorld
"
,
props
:
{
msg
:
String
,
},
data
()
{
return
{
name
:
''
,
parent_id
:
''
,
ordering
:
''
,
category_id
:
''
,
price
:
''
,
stock
:
''
,
description
:
''
,
image
:
null
,
variants
:
[
{
variant
Name
:
""
,
variant
Index
:
""
,
variant
Price
:
""
,
variant
Color
:
""
,
variant
Size
:
""
,
variant
Quantity
:
""
,
},
],
...
...
@@ -93,16 +121,20 @@ export default {
methods
:
{
addMore
()
{
this
.
variants
.
push
({
variant
Name
:
""
,
variant
Index
:
""
,
variant
Price
:
""
,
variant
Color
:
""
,
variant
Size
:
""
,
variant
Quantity
:
""
,
});
},
remove
(
index
)
{
this
.
variants
.
splice
(
index
,
1
);
},
getInfo
()
{
console
.
log
()
console
.
log
(
this
.
name
)
console
.
log
(
this
.
price
)
console
.
log
(
this
.
category_id
)
console
.
log
(
this
.
stock
)
console
.
log
(
this
.
variants
)
}
},
};
...
...
pages/home/products.vue
View file @
c83e5638
<
template
>
<div
id=
"app"
>
<DynamicInput
msg=
"Example of Dynamic Input"
/>
<div>
<b-breadcrumb>
<b-breadcrumb-item
href=
"/home"
>
<b-icon
icon=
"house-fill"
scale=
"1.25"
shift-v=
"1.25"
aria-hidden=
"true"
></b-icon>
Home
</b-breadcrumb-item>
<b-breadcrumb-item
href=
"/home/products"
>
Product
</b-breadcrumb-item>
</b-breadcrumb>
<div
style=
"float: right"
>
<CreateProductModal
/>
</div>
<!-- table -->
<div>
<v-data-table
:headers=
"headers"
:items=
"products"
sort-by=
"calories"
class=
"elevation-1"
>
<template
v-slot:top
>
<v-toolbar
flat
>
<v-toolbar-title>
Category Manage
</v-toolbar-title>
<v-divider
class=
"mx-4"
inset
vertical
></v-divider>
<v-spacer></v-spacer>
</v-toolbar>
</
template
>
<
template
v-slot:item.actions=
"{ item }"
>
<v-icon
small
class=
"mr-2"
@
click=
" editCategory(item.id)"
:id =
"item.id"
>
mdi-pencil
</v-icon>
<v-icon
small
@
click=
"deleteCategory(item.id,item)"
:id =
"item.id"
>
mdi-delete
</v-icon>
</
template
>
<
template
v-slot:no-data
>
<v-btn
color=
"primary"
@
click=
"initialize"
>
Reset
</v-btn>
</
template
>
</v-data-table>
</div>
</div>
</template>
<
script
>
import
DynamicInput
from
"
@/components/DynamicInput
"
;
import
CreateProductModal
from
"
../../components/CreateProductModal
"
;
import
nav
from
"
@/components/Nav
"
;
import
Navigation
from
"
@/components/Navigation
"
;
import
axios
from
"
axios
"
;
import
notification
from
"
@/components/Notification
"
;
export
default
{
layout
:
'
admin
'
,
name
:
"
App
"
,
components
:
{
DynamicInput
,
CreateProductModal
,
Nav
,
Navigation
,
},
middleware
:
[
"
web
"
],
data
:
()
=>
{
return
{
id
:
''
,
name
:
''
,
category_id
:
''
,
image
:
[],
price
:
''
,
description
:
''
,
stock
:
''
,
dialog
:
false
,
dialogDelete
:
false
,
options
:
[],
headers
:
[
{
text
:
"
Name
"
,
align
:
"
start
"
,
sortable
:
false
,
value
:
"
name
"
,
},
{
text
:
"
id
"
,
value
:
"
id
"
},
{
text
:
"
category ID
"
,
value
:
"
category_id
"
},
{
text
:
"
price
"
,
value
:
"
price
"
,
sortable
:
false
},
{
text
:
"
description
"
,
value
:
"
description
"
},
{
text
:
"
stock
"
,
value
:
"
stock
"
},
{
text
:
'
Actions
'
,
value
:
'
actions
'
,
sortable
:
false
},
],
products
:
[],
eID
:
''
,
eName
:
''
,
eOrdering
:
''
,
eParent_id
:
''
,
eImage
:
null
,
message
:
[],
editedIndex
:
-
1
,
editedItem
:
{
name
:
""
,
id
:
""
,
ordering
:
""
,
status
:
""
,
created_at
:
""
,
updated_at
:
""
,
},
defaultItem
:
{
name
:
""
,
id
:
""
,
ordering
:
""
,
status
:
""
,
created_at
:
""
,
updated_at
:
""
,
},
}
},
computed
:
{
formTitle
()
{
return
this
.
editedIndex
===
-
1
?
"
New Item
"
:
"
Edit Item
"
;
},
},
watch
:
{
dialog
(
val
)
{
val
||
this
.
close
();
},
dialogDelete
(
val
)
{
val
||
this
.
closeDelete
();
},
},
created
()
{
this
.
initialize
();
this
.
getProducts
();
},
methods
:
{
initialize
()
{
this
.
products
=
[];
},
editItem
(
item
)
{
this
.
editedIndex
=
this
.
products
.
indexOf
(
item
);
this
.
editedItem
=
Object
.
assign
({},
item
);
this
.
dialog
=
true
;
},
deleteItem
(
item
)
{
this
.
editedIndex
=
this
.
products
.
indexOf
(
item
);
this
.
editedItem
=
Object
.
assign
({},
item
);
this
.
dialogDelete
=
true
;
},
deleteItemConfirm
()
{
this
.
products
.
splice
(
this
.
editedIndex
,
1
);
this
.
closeDelete
();
},
close
()
{
this
.
dialog
=
false
;
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
);
this
.
editedIndex
=
-
1
;
});
},
closeDelete
()
{
this
.
dialogDelete
=
false
;
this
.
$nextTick
(()
=>
{
this
.
editedItem
=
Object
.
assign
({},
this
.
defaultItem
);
this
.
editedIndex
=
-
1
;
});
},
save
()
{
if
(
this
.
editedIndex
>
-
1
)
{
Object
.
assign
(
this
.
products
[
this
.
editedIndex
],
this
.
editedItem
);
}
else
{
this
.
products
.
push
(
this
.
editedItem
);
}
this
.
close
();
},
getProducts
()
{
axios
.
get
(
"
http://127.0.0.1:8000/api/products/
"
)
.
then
((
response
)
=>
(
this
.
products
=
response
.
data
.
data
))
.
catch
(
function
(
error
)
{
console
.
log
(
error
);
});
},
// createCategory() {
// const self = this
// axios
// .post('http://127.0.0.1:8000/api/products/',{
// name: this.name,
// ordering: this.ordering,
// parent_id: this.parent_id,
// image: this.image,
// }, {
// headers: {
// "Content-Type": "multipart/form-data",
// "Authorization": this.$auth.$storage.getUniversal("token")
// }
// })
// .then(response => {
// this.$bvModal.hide('modal-create')
// self.$toast.success('Category created successfully!', {
// duration: 3000
// })
// })
// .catch(errors => {
// this.$bvModal.hide('modal-create')
// console.log(errors.response.data.message);
// this.message = errors.response.data.message;
// self.$toast.error('something went wrong while trying create!',{
// duration: 3000
// });
// });
// },
// fileSelected(event){
// console.log(event)
// const file = event.target.files[0];
// this.url = URL.createObjectURL(file);
// this.image = file;
// console.log(file)
// console.log(this.image)
// },
// deleteCategory(ID,index) {
// this.editedIndex = this.products.indexOf(index);
// if(confirm("Do you really want to delete?")){
// try{
// axios
// .delete(`http://127.0.0.1:8000/api/products/${ID}`)
// .then(response => {
// this.products.splice(this.editedIndex, 1);
// self.$toast.success('Category deleted successfully!',{
// duration: 3000
// });
// })
// } catch(error){
// console.log(error)
// }
// }
// },
// getID(item) {
// console.log(this.products.indexOf(item))
// },
// editCategory(userID) {
// this.$bvModal.show('modal-edit');
// this.eID = userID;
// console.log(this?.eID);
// console.log(this.eName);
// },
// updateCategory(userID) {
// const self = this
// console.log(this.eName);
// console.log(this.eOrdering);
// console.log(this?.eID);
// try{
// axios
// .post(`http://127.0.0.1:8000/api/products/update/${this?.eID}`,{
// name: this.eName,
// ordering: this.eOrdering,
// parent_id: this.eParent_id,
// image: this.eImage }, {
// headers: {
// "Content-Type": "multipart/form-data",
// "Authorization": this.$auth.$storage.getUniversal("token")
// }
// } )
// .then(response => {
// self.$toast.success('User updated successfully!',{
// duration: 3000
// });
// console.log(response);
// })
// } catch(error){
// console.log(error)
// }
// }
},
};
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment