|
@@ -10,7 +10,7 @@
|
|
|
<!-- Category DropDown -->
|
|
|
<div class="a-spacing-top-medium">
|
|
|
<label for="">Category</label>
|
|
|
- <select class="a-select-option">
|
|
|
+ <select v-model="categoryID" class="a-select-option">
|
|
|
<option v-for="category in categories" :key="category._id" :value="category._id">{{ category.type }}</option>
|
|
|
</select>
|
|
|
</div>
|
|
@@ -18,7 +18,7 @@
|
|
|
<!-- Owner DropDown -->
|
|
|
<div class="a-spacing-top-medium">
|
|
|
<label for="">Owner</label>
|
|
|
- <select class="a-select-option">
|
|
|
+ <select v-model="ownerID" class="a-select-option" >
|
|
|
<option v-for="owner in owners" :key="owner._id" :value="owner._id">{{ owner.name }}</option>
|
|
|
</select>
|
|
|
</div>
|
|
@@ -26,19 +26,26 @@
|
|
|
<!-- Title input-->
|
|
|
<div class="a-spacing-top-medium">
|
|
|
<label for="" style="margin-bottom: 0px;">Title</label>
|
|
|
- <input type="text" class="a-input-text" style="width: 100%"/>
|
|
|
+ <input v-model="title" type="text" class="a-input-text" style="width: 100%"/>
|
|
|
</div>
|
|
|
|
|
|
+ <!-- stockQuantity input-->
|
|
|
+ <div class="a-spacing-top-medium">
|
|
|
+ <label for="" style="margin-bottom: 0px;">stockQuantity</label>
|
|
|
+ <input v-model="stockQuantity" type="number" class="a-input-text" style="width: 100%"/>
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
<!-- Price input-->
|
|
|
<div class="a-spacing-top-medium">
|
|
|
<label for="" style="margin-bottom: 0px;">Price</label>
|
|
|
- <input type="number" class="a-input-text" style="width: 100%"/>
|
|
|
+ <input v-model="price" type="number" class="a-input-text" style="width: 100%"/>
|
|
|
</div>
|
|
|
|
|
|
<!-- Description input-->
|
|
|
<div class="a-spacing-top-medium">
|
|
|
<label for="" style="margin-bottom: 0px;">Description</label>
|
|
|
- <textarea placeholder="Provide details product description" style="width: 100%"></textarea>
|
|
|
+ <textarea v-model="description" placeholder="Provide details product description" style="width: 100%"></textarea>
|
|
|
</div>
|
|
|
|
|
|
<!-- Photo input-->
|
|
@@ -47,8 +54,8 @@
|
|
|
<div class="a-row a-spacing-top-medium">
|
|
|
<label class="choosefile-button">
|
|
|
<i class="fa fa-plus"></i>
|
|
|
- <input type="file" />
|
|
|
- <p style="margin-top: -70px">name of the</p>
|
|
|
+ <input @change="onFileSelected" type="file" />
|
|
|
+ <p style="margin-top: -70px">{{ fileName }}</p>
|
|
|
</label>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -85,6 +92,42 @@ export default {
|
|
|
} catch (err) {
|
|
|
console.log(err)
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ categoryID: null,
|
|
|
+ ownerID: null,
|
|
|
+ title: '',
|
|
|
+ price: 0,
|
|
|
+ description: '',
|
|
|
+ selectedFile: null,
|
|
|
+ fileName: '',
|
|
|
+ stockQuantity: 1
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+ onFileSelected (event) {
|
|
|
+ this.selectedFile = event.target.files[0]
|
|
|
+ console.log(this.selectedFile)
|
|
|
+ this.fileName = event.target.files[0].name
|
|
|
+ },
|
|
|
+
|
|
|
+ async onAddProduct () {
|
|
|
+ let data = new FormData()
|
|
|
+ data.append('title', this.title)
|
|
|
+ data.append('price', this.price)
|
|
|
+ data.append('stockQuantity', this.stockQuantity)
|
|
|
+ data.append('description', this.description)
|
|
|
+ data.append('ownerID', this.ownerID)
|
|
|
+ data.append('categoryID', this.categoryID)
|
|
|
+ data.append('photo', this.selectedFile, this.selectedFile.name)
|
|
|
+
|
|
|
+ let result = await this.$axios.$post('http://localhost:3000/api/products', data)
|
|
|
+
|
|
|
+ this.$router.push('/')
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|