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

index products

parent 0a773156
<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.variantName"
placeholder="enter you variant name"
v-model="variant.variantColor"
placeholder="Color"
class="w-full py-2 border border-indigo-500 rounded"
/>
<input
v-model="variant.variantIndex"
placeholder="enter you variantIndex"
v-model="variant.variantSize"
placeholder="Size"
class="w-full py-2 border border-indigo-500 rounded"
/>
<input
v-model="variant.variantPrice"
placeholder="enter you variantPrice"
v-model="variant.variantQuantity"
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: [
{
variantName: "",
variantIndex: "",
variantPrice: "",
variantColor: "",
variantSize: "",
variantQuantity: "",
},
],
......@@ -93,16 +121,20 @@ export default {
methods: {
addMore() {
this.variants.push({
variantName: "",
variantIndex: "",
variantPrice: "",
variantColor: "",
variantSize: "",
variantQuantity: "",
});
},
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)
}
},
};
......
<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>
......
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